Backport GCC changes to fix integer overflow detection and enable -fwrapv by default.
authorFelix Fietkau <nbd@openwrt.org>
Tue, 30 Jan 2007 16:14:46 +0000 (16:14 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 30 Jan 2007 16:14:46 +0000 (16:14 +0000)
See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30477 for more information on this...

SVN-Revision: 6230

openwrt/toolchain/gcc/3.4.4/900-integer_overflow.patch [new file with mode: 0644]
openwrt/toolchain/gcc/3.4.4/910-enable_wrapv.patch [new file with mode: 0644]

diff --git a/openwrt/toolchain/gcc/3.4.4/900-integer_overflow.patch b/openwrt/toolchain/gcc/3.4.4/900-integer_overflow.patch
new file mode 100644 (file)
index 0000000..5871e30
--- /dev/null
@@ -0,0 +1,28 @@
+--- gcc.old/gcc/simplify-rtx.c 2005-03-23 15:41:59.000000000 +0100
++++ gcc.dev/gcc/simplify-rtx.c 2007-01-30 11:42:38.407017680 +0100
+@@ -2607,18 +2607,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);
diff --git a/openwrt/toolchain/gcc/3.4.4/910-enable_wrapv.patch b/openwrt/toolchain/gcc/3.4.4/910-enable_wrapv.patch
new file mode 100644 (file)
index 0000000..6d81fd4
--- /dev/null
@@ -0,0 +1,11 @@
+--- gcc.old/gcc/toplev.c       2005-03-09 01:50:25.000000000 +0100
++++ gcc.dev/gcc/toplev.c       2007-01-30 12:25:29.644130224 +0100
+@@ -991,7 +991,7 @@
+ int flag_trapv = 0;
+ /* Nonzero if signed arithmetic overflow should wrap around.  */
+-int flag_wrapv = 0;
++int flag_wrapv = 1;
+ /* Nonzero if subexpressions must be evaluated from left-to-right.  */
+ int flag_evaluation_order = 0;