git: af116659c071 - stable/15 - libc: Fix atomic_init for GCC atomic objects
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 31 Oct 2026 10:06:34 UTC
The branch stable/15 has been updated by kfv:
URL: https://cgit.FreeBSD.org/src/commit/?id=af116659c071a284b036d4e8e232b107a7c3ecaa
commit af116659c071a284b036d4e8e232b107a7c3ecaa
Author: Faraz Vahedi <kfv@FreeBSD.org>
AuthorDate: 2026-05-07 23:00:47 +0000
Commit: Faraz Vahedi <kfv@FreeBSD.org>
CommitDate: 2026-10-31 10:03:31 +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
(cherry picked from commit 54ac231419cf09557d2f5826b1539e83db552410)
---
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