On Mon, 20 Nov 2023, Jakub Jelinek wrote:

> On Mon, Nov 20, 2023 at 04:03:07PM +0100, Jakub Jelinek wrote:
> > > Note that stdc_bit_ceil now has defined behavior (return 0) on overflow: 
> > > CD2 comment FR-135 was accepted for the DIS at the June WG14 meeting.  
> > > This affects both the documentation and the implementation, as they need 
> > > to avoid an undefined shift by the width of the type.  That's why my 
> > > stdbit.h implementations have two shifts (not claiming that's necessarily 
> > > the optimal way of ensuring the correct result in the overflow case).
> > > 
> > >   return __x <= 1 ? 1 : ((uint64_t) 1) << (__bw64_inline (__x - 1) - 1) 
> > > << 1;
> > 
> > Given the feedback from Richi I've in the meantime reworked the patch to
> > add all 14 builtins (but because the enum rid is very close to 256 values
> > and with 14 new ones was already 7 too many, used one RID value for all 14
> > builtins (different spellings)).
> > 
> > Will need to rework it for CD2 FR-135 then...
> 
> Here it is updated to use that
> x <= 1 ? 1 : ((type) 2) << (prec - 1 - __builtin_clzg ((type) (x - 1)))
> I've mentioned.
> 
> 2023-11-20  Jakub Jelinek  <ja...@redhat.com>
> 
> gcc/
>       * doc/extend.texi (__builtin_stdc_bit_ceil, __builtin_stdc_bit_floor,
>       __builtin_stdc_bit_width, __builtin_stdc_count_ones,
>       __builtin_stdc_count_zeros, __builtin_stdc_first_leading_one,
>       __builtin_stdc_first_leading_zero, __builtin_stdc_first_trailing_one,
>       __builtin_stdc_first_trailing_zero, __builtin_stdc_has_single_bit,
>       __builtin_stdc_leading_ones, __builtin_stdc_leading_zeros,
>       __builtin_stdc_trailing_ones, __builtin_stdc_trailing_zeros): Document.
> gcc/c-family/
>       * c-common.h (enum rid): Add RID_BUILTIN_STDC: New.
>       * c-common.cc (c_common_reswords): Add __builtin_stdc_bit_ceil,
>       __builtin_stdc_bit_floor, __builtin_stdc_bit_width,
>       __builtin_stdc_count_ones, __builtin_stdc_count_zeros,
>       __builtin_stdc_first_leading_one, __builtin_stdc_first_leading_zero,
>       __builtin_stdc_first_trailing_one, __builtin_stdc_first_trailing_zero,
>       __builtin_stdc_has_single_bit, __builtin_stdc_leading_ones,
>       __builtin_stdc_leading_zeros, __builtin_stdc_trailing_ones and
>       __builtin_stdc_trailing_zeros.  Move __builtin_assoc_barrier
>       alphabetically earlier.
> gcc/c/
>       * c-parser.cc (c_parser_postfix_expression): Handle RID_BUILTIN_STDC.
>       * c-decl.cc (names_builtin_p): Likewise.
> gcc/testsuite/
>       * gcc.dg/builtin-stdc-bit-1.c: New test.
>       * gcc.dg/builtin-stdc-bit-2.c: New test.

OK with tests added for unsigned _BitInt(1).  Specifically, unsigned 
_BitInt(1) is a bit of a degenerate case for stdc_bit_ceil (always 
returning 1 after evaluating the argument's side effects); I think the 
code that builds of constant 2 of that type (a constant only used in dead 
code) should still work (and produce a constant 0), and that the 
documentation is also still correct in the case where converting 2 to the 
type produces 0, but given those degeneracies I think it's worth testing 
unsigned _BitInt(1) with these functions to make sure they do behave as 
expected.

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to