git: 54ac231419cf - main - libc: Fix atomic_init for GCC atomic objects
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 20 Jun 2026 00:24:57 UTC
The branch main has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=54ac231419cf09557d2f5826b1539e83db552410
commit 54ac231419cf09557d2f5826b1539e83db552410
Author: Faraz Vahedi <kfv@kfv.io>
AuthorDate: 2026-05-07 23:00:47 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2026-06-20 00:23:29 +0000
libc: Fix atomic_init for GCC atomic objects
Add a dedicated `__GNUC_ATOMICS` path that initialises via
`atomic_store_explicit(obj, value, memory_order_relaxed)`.
This ensures the required initialisation semantics without
assuming any particular object representation.
Previously, `atomic_init` on GCC fell through to the legacy
`__val` member path intended only for old struct-backed
atomic objects. For current atomic objects, this caused the
following compilation error:
> error: request for member '__val' in something not a
structure or union
As a result, valid code such as `atomic_init(&x, 1)` failed
to compile when using GCC.
This fix restores compatibility with standard-conforming
callers while other code paths remain unchanged.
Signed-off-by: Faraz Vahedi <kfv@kfv.io>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/2185
---
sys/sys/stdatomic.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sys/sys/stdatomic.h b/sys/sys/stdatomic.h
index 3e4bdd505418..c0cbb7f785b5 100644
--- a/sys/sys/stdatomic.h
+++ b/sys/sys/stdatomic.h
@@ -96,6 +96,9 @@
#if defined(__CLANG_ATOMICS)
#define atomic_init(obj, value) __c11_atomic_init(obj, value)
+#elif defined(__GNUC_ATOMICS)
+#define atomic_init(obj, value) atomic_store_explicit(obj, \
+ value, __ATOMIC_RELAXED)
#else
#define atomic_init(obj, value) ((void)((obj)->__val = (value)))
#endif