[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <57a98a13-4d88-4d83-b9f4-77a0a665be8a@t-8ch.de>
Date: Wed, 3 Dec 2025 20:19:13 +0100
From: Thomas Weißschuh <linux@...ssschuh.net>
To: Willy Tarreau <w@....eu>
Cc: Shuah Khan <shuah@...nel.org>, Arnd Bergmann <arnd@...db.de>,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org
Subject: Re: [PATCH v2 12/13] tools/nolibc: add __nolibc_static_assert()
On 2025-11-30 12:08:56+0100, Willy Tarreau wrote:
> On Sat, Nov 22, 2025 at 05:59:18PM +0100, Thomas Weißschuh wrote:
> > Add a wrapper for _Static_assert() to use within nolibc.
> > While _Static_assert() itself was only standardized in C11,
> > in GCC and clang dialects it is also available in older standards.
> >
> > If it turns out that _Static_assert can't be used in some contexts,
> > this wrapper can be adapted.
> >
> > Signed-off-by: Thomas Weißschuh <linux@...ssschuh.net>
> > ---
> > tools/include/nolibc/compiler.h | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h
> > index 87090bbc53e0..ef247e916552 100644
> > --- a/tools/include/nolibc/compiler.h
> > +++ b/tools/include/nolibc/compiler.h
> > @@ -47,4 +47,6 @@
> > # define __nolibc_fallthrough do { } while (0)
> > #endif /* __nolibc_has_attribute(fallthrough) */
> >
> > +#define __nolibc_static_assert(_t) _Static_assert(_t, "")
>
> I'm not super fan of raising the bar to adoption by introducing forced
> C11-isms, especially when they're only used to perform extra safety
> checks that likely remain fine after you've checked them once. What
> about instead:
>
> +#if __STDC_VERSION__ >= 201112L
> +# define __nolibc_static_assert(_t) _Static_assert(_t, "")
> +#endif
> +# define __nolibc_static_assert(_t) do { } while (0)
> +#else
>
> Note that this won't work out of code blocks but we very likely don't
> care. And if we'd care, we could always switch to __asm__("") which
> works everywhere.
>
> What do you think ?
That works. But it won't be evaluated when not building with C11.
Which would not make it trigger when building nolibc-test.
So I don't want to guard it behind __STDC_VERSION__. But so far I was
not able to find a better, more dynamic guard. I'll look again.
Non-standard _Static_assert() is supported since GCC 4.6 and clang 3.0.
Thomas
Powered by blists - more mailing lists