Re: [PATCH] newlib/libc/stdbit: Fix static assertions for 16-bit int
Corinna Vinschen <[email protected]> Mon, 20 Apr 2026 21:32:01 +0200
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
[CC Joel Sherrill, please review] On Apr 20 16:24, Jonathan Wakely wrote: > All the USHRT_WIDTH < UINT_WIDTH assertions fail for 16-bit int targets, > such as msp430-elf. Remove those static assertions and instead fix the > stdc_xxx_us functions to work correctly when USHRT_WIDTH == UINT_WIDTH. > > Signed-off-by: Jonathan Wakely <[email protected]> > --- > > This is untested, except to check that it now compiles on msp430-elf and > still compiles on arm-eabi. > > newlib/libc/stdbit/stdc_bit_ceil.c | 9 +++++---- > newlib/libc/stdbit/stdc_leading_ones.c | 10 ++++++---- > newlib/libc/stdbit/stdc_leading_zeros.c | 10 ++++++---- > newlib/libc/stdbit/stdc_trailing_ones.c | 10 ++++++---- > newlib/libc/stdbit/stdc_trailing_zeros.c | 11 +++++++---- > 5 files changed, 30 insertions(+), 20 deletions(-) > [...] > unsigned int > stdc_leading_ones_us(unsigned short x) > { > +#if USHRT_WIDTH == UINT_WIDTH > + /* Avoid triggering undefined behavior if x == 0. */ > + if (x == ~0U) ~0 is not 0... Thanks, Corinna