Re: [PATCH] newlib/libc/stdbit: Fix static assertions for 16-bit int

Joel Sherrill <[email protected]> Mon, 20 Apr 2026 14:47:31 -0500
Newsgroups gmane.comp.lib.newlib
Message-ID <CAF9ehCVpCR6-704Jmtt-So0EWogkwuc_vcZU-t55ErEsxpN-Sg@mail.gmail.com>
Is there a conditional defined when building newlib to know you are inside
newlib? I'd like to guard changes from the original FreeBSD code if that's
possible. We do that inside RTEMS and it makes updates easier.

--joel

On Mon, Apr 20, 2026, 2:32 PM Corinna Vinschen <[email protected]> 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...
>
>
> Thanks,
> Corinna
>