------- Comment #18 from tg at mirbsd dot org  2007-01-25 16:09 -------
Subject:  Integer Overflow detection code optimised away, -fwrapv
 broken

Dixi:

>Commit ID:     10045B8CAF141886704
>CVSROOT:       /cvs
>Module name:   gcc
>Changes by:    [EMAIL PROTECTED]       2007/01/25 15:21:11 UTC
>
>Modified files:
>       gcc            : simplify-rtx.c
>
>Log message:
>   ------- Comment [100]#17 From [101]Richard Guenther 2007-01-25 14:49 -------
>Backporting the fix for [102]PR28651 should fix it I guess.

Yes it does, thanks.

>To generate a diff of this changeset, execute the following commands:
>cvs -R rdiff -ur1.5 -r1.6 gcc/gcc/simplify-rtx.c

That is:

----- cutting here may damage your screen surface -----
Index: gcc/gcc/simplify-rtx.c
diff -u gcc/gcc/simplify-rtx.c:1.5 gcc/gcc/simplify-rtx.c:1.6
--- gcc/gcc/simplify-rtx.c:1.5  Thu Mar 30 19:50:29 2006
+++ gcc/gcc/simplify-rtx.c      Thu Jan 25 15:21:10 2007
@@ -2686,18 +2686,18 @@
      a register or a CONST_INT, this can't help; testing for these cases will
      prevent infinite recursion here and speed things up.

-     If CODE is an unsigned comparison, then we can never do this
optimization,
-     because it gives an incorrect result if the subtraction wraps around
zero.
-     ANSI C defines unsigned operations such that they never overflow, and
-     thus such cases can not be ignored.  */
+     We can only do this for EQ and NE comparisons as otherwise we may
+     lose or introduce overflow which we cannot disregard as undefined as
+     we do not know the signedness of the operation on either the left or
+     the right hand side of the comparison.  */

   if (INTEGRAL_MODE_P (mode) && trueop1 != const0_rtx
+      && (code == EQ || code == NE)
       && ! ((GET_CODE (op0) == REG || GET_CODE (trueop0) == CONST_INT)
            && (GET_CODE (op1) == REG || GET_CODE (trueop1) == CONST_INT))
       && 0 != (tem = simplify_binary_operation (MINUS, mode, op0, op1))
-      /* We cannot do this for == or != if tem is a nonzero address.  */
-      && ((code != EQ && code != NE) || ! nonzero_address_p (tem))
-      && code != GTU && code != GEU && code != LTU && code != LEU)
+      /* We cannot do this if tem is a nonzero address.  */
+      && ! nonzero_address_p (tem))
     return simplify_relational_operation (signed_condition (code),
                                          mode, tem, const0_rtx);

----- cutting here may damage your screen surface -----

This applies to gcc 3.4.6 - if you need other versions, YMMV.

bye,
//mirabile


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30477

Reply via email to