https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88387

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-12-06
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  We do not derive a range from n >> 2222 while it could be [-1,0].
But by default we warn

t.c: In function ‘test’:
t.c:6:9: warning: right shift count >= width of type [-Wshift-count-overflow]
    6 |   if (n >> 2222)
      |         ^~

Note that we fold
if (n >> 31) into if (n < 0).  GCC probably allows targets to interpret
2222 as if masked by 0x1f which means not all out-of-bound shifts would
yield the result you want.

The C standard says that a right-shift of a negative value is
implementation-defined and if the shift amount is greater or rqual to the width
of the
promoted left operand the behavior is undefined (but we do not make
use of that either here).

Thus - gcc could fold the above to n < 0 but we usually leave undefined
stuff in place when simply folding.

But you shouldn't use this kind of code anyways.

That said,

 n >> [31, +INF]

could be folded to n < 0 given we can disregard the possible values that
would invoke undefined behavior.

Reply via email to