Re: [PATCH v2 03/34] compiler-capability-analysis: Add test stub
From: Marco Elver
Date: Tue Mar 04 2025 - 19:04:43 EST
On Wed, 5 Mar 2025 at 00:52, Bart Van Assche <bvanassche@xxxxxxx> wrote:
>
> On 3/4/25 1:21 AM, Marco Elver wrote:
> > +#include <linux/build_bug.h>
> > +
> > +/*
> > + * Test that helper macros work as expected.
> > + */
> > +static void __used test_common_helpers(void)
> > +{
> > + BUILD_BUG_ON(capability_unsafe(3) != 3); /* plain expression */
> > + BUILD_BUG_ON(capability_unsafe((void)2; 3;) != 3); /* does not swallow semi-colon */
> > + BUILD_BUG_ON(capability_unsafe((void)2, 3) != 3); /* does not swallow commas */
> > + capability_unsafe(do { } while (0)); /* works with void statements */
> > +}
>
> Is it guaranteed that <linux/build_bug.h> includes the header file that
> defines capability_unsafe() or should that header file perhaps be
> included explicitly?
It doesn't come in via build_bug.h, but via:
scripts/Makefile.lib -> "-include
$(srctree)/include/linux/compiler_types.h" (all TUs) ->
compiler-capability-analysis.h.
The things pulled in via compiler_types.h are treated a bit like
builtins available everywhere implicitly.