[C/C++ PATCH] Don't convert RHS of a shift-expression to int (PR c/63862)

Jakub Jelinek jakub@redhat.com
Wed Nov 26 18:12:00 GMT 2014


On Wed, Nov 26, 2014 at 06:39:44PM +0100, Marek Polacek wrote:
> Both C11 and C++14 standards specify that integral promotions are
> performed on both operands of a shift-expression.  This we do just
> fine.  But then we convert the right operand to integer_type_node.
> Not only is this unnecessary, it can also be harfmul, because for
> e.g. 
> void
> foo (unsigned int x)
> {
>   if (-1 >> x != -1)
>     bar ();
> }
> with (int) x we lose info that x is nonnegative, which means that
> tree_expr_nonnegative_p cannot fold this expr.  Another problem
> with the conversion is that we weren't able to detect e.g. shift
> by 0x100000000ULL, since after the conversion this is 0.

Have you checked what the expander does with it?  Say trying to
shift something by __int128 count or similar might upset it.
Wonder about if we don't make similar assumptions in the middle-end.
It might make a difference (sometimes positive, sometimes negative)
for vectorization too.

> 2014-11-26  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c/63862
> c-family/
> 	* c-ubsan.c (ubsan_instrument_shift): Change the type of a MINUS_EXPR
> 	to op1_utype.

This part is ok regardless of the rest.

	Jakub



More information about the Gcc-patches mailing list