This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Avoid some left-shifts of negative constants
On 2/7/19 8:52 AM, Joseph Myers wrote:
In this particular case (constructing a mask value), using an unsigned
constant seems cleaner to me than using a signed one.
That's a minor style preference, and the other side of it is that
replacing -1 with -1U will break if the value being masked is later
widened to 'long' for whatever reason, which gives a slight
style/portability edge to leaving the code alone. (Plus, -1U is uglier
and we shouldn't let GCC push us around. :-)
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.
There would be even greater utility in having UBSAN catch only real bugs
instead of sending us off on wild-goose cases that result in code that's
more fragile. Surely it would be easy to fix UBSAN to not report an
error for a left shift of a negative value, for applications like glibc
that are willing to rely on GCC's semantics.