[Bug c/55967] rightshift an unsigned value (X) by it's number of bits does not always yield 0, when X is an unsigned that's leftshifted by it's number of bits and offset
b1262178 at rmqkr dot net
gcc-bugzilla@gcc.gnu.org
Mon Jan 14 12:53:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55967
--- Comment #1 from JoeSoe <b1262178 at rmqkr dot net> 2013-01-14 12:53:24 UTC ---
Of course I get warnings...
go.c:146:3: warning: left shift count >= width of type [enabled by default]
go.c:146:3: warning: right shift count >= width of type [enabled by default]
And of course ((1U<<(32))) is also undefined behaviour, since the
www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf#page=578 states on undefined
behaviour:
An expression is shifted by a negative number or by an amount greater than or
equal to the width of the promoted expression (6.5.7).
Bit even if this is undefined behaviour, I would like gcc to handle this
gracefully, as is the case with
(((1U<<(32))) ) >> 32U
which "gracefully" yields 0.
So the following should also do the graceful thing and yield 0, right?
((1U<<(32))) + 0x80000000U) >> 32U
More information about the Gcc-bugs
mailing list