Re: git: 28cecfe27964 - main - libc: Restrict ATOMIC_VAR_INIT for C23 conformance
- In reply to: Warner Losh : "git: 28cecfe27964 - main - libc: Restrict ATOMIC_VAR_INIT for C23 conformance"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 21 Jun 2026 18:11:19 UTC
On 6/19/26 17:24, Warner Losh wrote:
> The branch main has been updated by imp:
>
> URL: https://cgit.FreeBSD.org/src/commit/?id=28cecfe27964fdb67497800f5dcd5d3e1033727f
>
> commit 28cecfe27964fdb67497800f5dcd5d3e1033727f
> Author: Faraz Vahedi <kfv@kfv.io>
> AuthorDate: 2026-05-01 14:34:44 +0000
> Commit: Warner Losh <imp@FreeBSD.org>
> CommitDate: 2026-06-20 00:23:28 +0000
>
> libc: Restrict ATOMIC_VAR_INIT for C23 conformance
>
> Omit `ATOMIC_VAR_INIT` when targeting C23, where it has been removed.
> Retain it for earlier C standards and for C++ (as it still remains in
> C++23, albeit marked as deprecated since C17 and C++20.)
>
> Also separate `atomic_init` definitions from `ATOMIC_VAR_INIT` to
> avoid coupling with a deprecated initialisation mechanism.
>
> No functional change intended for `atomic_init`; this is purely a
> conformance and cleanup adjustment.
>
> 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 | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/sys/sys/stdatomic.h b/sys/sys/stdatomic.h
> index c3f9b217519c..2d565ce991be 100644
> --- a/sys/sys/stdatomic.h
> +++ b/sys/sys/stdatomic.h
> @@ -86,11 +86,17 @@
> * 7.17.2 Initialization.
> */
>
> +#if __ISO_C_VISIBLE < 2023 || defined(__cplusplus)
> #if defined(__CLANG_ATOMICS)
> #define ATOMIC_VAR_INIT(value) (value)
> -#define atomic_init(obj, value) __c11_atomic_init(obj, value)
> #else
> #define ATOMIC_VAR_INIT(value) { .__val = (value) }
> +#endif
> +#endif
> +
> +#if defined(__CLANG_ATOMICS)
> +#define atomic_init(obj, value) __c11_atomic_init(obj, value)
> +#else
> #define atomic_init(obj, value) ((void)((obj)->__val = (value)))
> #endif
>
>
>
I expect that the problem reports for port package build failures are
tied to src/sys/sys/_visible.h :
. . .
#elif defined(_C23_SOURCE) /* Localism to specify strict C23 env. */
#define __POSIX_VISIBLE 0
#define __XSI_VISIBLE 0
#define __BSD_VISIBLE 0
#define __ISO_C_VISIBLE 2023
#define __EXT1_VISIBLE 0
#else /* Default environment: show everything. */
#define __POSIX_VISIBLE 202405
#define __XSI_VISIBLE 800
#define __BSD_VISIBLE 1
#define __ISO_C_VISIBLE 2023
#define __EXT1_VISIBLE 1
#endif
#endif /* _POSIX_C_SOURCE */
The "show everything" note is wrong now, as C23 removes at least
ATOMIC_VAR_INIT . A real "show everything" would require more logic,
such as still keeping ATOMIC_VAR_INIT for __BSD_VISIBLE also being 1 or
some such (may be inventing a new configuration macro for, say,
__ISO_C_BUT_WITHOUT_SOME_REMOVALS).
--
===
Mark Millard
marklmi at yahoo.com