[COMMITTED] stdlib: Adapt tst-stdbit-builtins.c _BitInt tests on clang

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Mon Aug 24 19:10:20 GMT 2026



On 23/08/26 08:54, Gabriel Ravier wrote:
> On 8/12/26 8:21 PM, Adhemerval Zanella wrote:
>> Two issues with clang-23:
>>
>> 1. -std=gnu11 triggers warnings with the 'uwb' suffix due to
>>     -Wc23-extensions being enabled by default.
>>
>> 2. an ICE with __builtin_stdc_bit_ceil with a non-constant
>>     unsigned _BitInt(1) argument [1]
>>
>> This patch disables the warning for 1. and disables the affected
>> stdc_bit_ceil tests for clang.
>>
>> [1] https://github.com/llvm/llvm-project/issues/214478
>> ---
>>   stdlib/tst-stdbit-builtins.c | 10 ++++++++++
>>   1 file changed, 10 insertions(+)
>>
>> diff --git a/stdlib/tst-stdbit-builtins.c b/stdlib/tst-stdbit-builtins.c
>> index a0c83c6dc22..9236b8c1114 100644
>> --- a/stdlib/tst-stdbit-builtins.c
>> +++ b/stdlib/tst-stdbit-builtins.c
>> @@ -19,6 +19,7 @@
>>   #include <stdbit.h>
>>   #include <limits.h>
>>   #include <support/check.h>
>> +#include <libc-diag.h>
>>     #if __glibc_has_builtin (__builtin_stdc_leading_zeros) \
>>       && __glibc_has_builtin (__builtin_stdc_leading_ones) \
>> @@ -512,6 +513,10 @@ do_test (void)
>>     TEST_COMPARE (b, 14);
>>   # ifdef BITINT_MAXWIDTH
>>   #  if BITINT_MAXWIDTH >= 64
>> +  /* clang with -std=gnu11 warns that '_BitInt' suffix for literals is a C23
>> +     extension.  */
>> +  DIAG_PUSH_NEEDS_COMMENT_CLANG;
>> +  DIAG_IGNORE_NEEDS_COMMENT_CLANG (23, "-Wc23-extensions");
>>     TEST_COMPARE (stdc_leading_zeros (0uwb), 1);
>>     TEST_COMPARE (expr_has_type (stdc_leading_zeros (0uwb), ui), 1);
>>     TEST_COMPARE (stdc_leading_zeros (1uwb), 0);
>> @@ -568,6 +573,10 @@ do_test (void)
>>     TEST_COMPARE (expr_has_type (stdc_bit_ceil (0uwb), unsigned _BitInt(1)), 1);
>>     TEST_COMPARE (stdc_bit_ceil (1uwb), 1);
>>     TEST_COMPARE (expr_has_type (stdc_bit_ceil (1uwb), unsigned _BitInt(1)), 1);
>> +  DIAG_POP_NEEDS_COMMENT_CLANG;
>> +  /* clang-23 triggers an ICE with __builtin_stdc_bit_ceil with a non-constant
>> +     unsigned _BitInt(1).  */
>> +#   ifdef __clang__
>>     unsigned _BitInt(1) c = 0;
>>     TEST_COMPARE (stdc_bit_floor (c++), 0);
>>     TEST_COMPARE (c, 1);
>> @@ -577,6 +586,7 @@ do_test (void)
>>     TEST_COMPARE (c, 1);
>>     TEST_COMPARE (stdc_bit_ceil (c++), 1);
>>     TEST_COMPARE (c, 0);
>> +#   endif
>>   #  endif
>>   #  if BITINT_MAXWIDTH >= 512
>>     TEST_COMPARE (stdc_leading_zeros ((unsigned _BitInt(512)) 0), 512);
> 
> 
> I am puzzled as to how exactly the ifdef works to prevent the ICE on Clang - shouldn't that ifdef __clang__ be ifndef __clang__ ?
> 

I think I messed the ifdefs indeed, I will fix.

> 
> (also, perhaps mildly unrelated but I noticed it while looking at the same file: is `TEST_COMPARE (stdc_bit_floor (((unsigned _BitInt(373)) 512) << 242) != (((unsigned _BitInt(512)) 512) << 242), 0);` supposed to have the two sides be different widths ?)

Hum it makes sense, I am ccing Jakub since he was the one that added this test.


More information about the Libc-alpha mailing list