[PATCH] fix pr39867, wrong folding to MAX_EXPR

Jakub Jelinek jakub@redhat.com
Fri Apr 24 08:05:00 GMT 2009


On Fri, Apr 24, 2009 at 02:40:41AM -0400, Paolo Bonzini wrote:
> This is a fix for PR39867, a MAX operation created from a COND_EXPR
> with the wrong signedness.  The MAX operation must always be created
> with the operand type of the comparison, and then possibly casted
> to the result type of the COND_EXPR.
> 
> Bootstrapped/regtested i686-pc-linux-gnu, ok for trunk and 4.4?
> 
> Paolo
> 
> 2009-04-24  Paolo Bonzini  <bonzini@gnu.org>
> 

	PR middle-end/39867
should be mentioned here.
> 	* fold-const.c (fold_cond_expr_with_comparison): When folding
> 	> and >= to MAX, make sure the MAX uses the same type as the
> 	comparison's operands.

> /* { dg-do link } */
> /* { dg-options "-O2" } */
> 
> int main (void)
> {
>   int exp = -1;
>   /* Wrong folding of the LHS to an unsigned MAX leads to 4294967295 > 2.  */
>   if (("%u\n", exp < 2 ? 2U : (unsigned int) exp) > 2)

Why the "%u\n", ?  Doesn't make any difference, IMHO should be left out.
Also, why not test != 2, to verify that the result of the expression isn't
say signed -1?

	Jakub



More information about the Gcc-patches mailing list