This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Avoid some left-shifts of negative constants


On Thu, 7 Feb 2019, Paul Eggert wrote:

> On 2/6/19 1:37 PM, Joseph Myers wrote:
> > One group of warnings seen with -Wextra is "left shift of negative
> > value [-Wshift-negative-value]".
> 
> This group of warnings is make-work, right? Glibc assumes GCC, and in GCC the
> left shift of a negative value is well-defined unless it overflows (which
> can't happen in this case). So I suggest that we add -Wno-shift-negative-value
> to CFLAGS instead of worrying about pacifying the compiler by munging the
> source code.

In this particular case (constructing a mask value), using an unsigned 
constant seems cleaner to me than using a signed one.

We may well end up with -Wno-shift-negative-value because of the 
hard-to-fix cases, although I think there may well be utility in being 
able to build much of glibc with UBSAN to find bugs, which might indicate 
more generally avoiding such shifts even when in fact harmless with GCC.

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]