Re: [PATCH] newlib/libc/stdbit: Fix static assertions for 16-bit int
Jonathan Wakely <[email protected]> Mon, 20 Apr 2026 21:29:20 +0100
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 20 Apr 2026 at 21:32 +0200, Corinna Vinschen wrote: > >[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... I know. I just moved the original comment, but as I said at https://inbox.sourceware.org/newlib/CAH6eHdRheB4uCJQCvQLQ3rC5xGgLgA+9H_V60meVR3xrMikzxQ@mail.gmail.com/T/#t it looks like the comments in that file (the one I moved, and the earlier one on line 13) are both wrong.