Backport GCC changes to fix integer overflow detection and enable -fwrapv by default.
[openwrt/svn-archive/archive.git] / openwrt / toolchain / gcc / 3.4.4 / 900-integer_overflow.patch
1 --- gcc.old/gcc/simplify-rtx.c 2005-03-23 15:41:59.000000000 +0100
2 +++ gcc.dev/gcc/simplify-rtx.c 2007-01-30 11:42:38.407017680 +0100
3 @@ -2607,18 +2607,18 @@
4 a register or a CONST_INT, this can't help; testing for these cases will
5 prevent infinite recursion here and speed things up.
6
7 - If CODE is an unsigned comparison, then we can never do this optimization,
8 - because it gives an incorrect result if the subtraction wraps around zero.
9 - ANSI C defines unsigned operations such that they never overflow, and
10 - thus such cases can not be ignored. */
11 + We can only do this for EQ and NE comparisons as otherwise we may
12 + lose or introduce overflow which we cannot disregard as undefined as
13 + we do not know the signedness of the operation on either the left or
14 + the right hand side of the comparison. */
15
16 if (INTEGRAL_MODE_P (mode) && trueop1 != const0_rtx
17 + && (code == EQ || code == NE)
18 && ! ((GET_CODE (op0) == REG || GET_CODE (trueop0) == CONST_INT)
19 && (GET_CODE (op1) == REG || GET_CODE (trueop1) == CONST_INT))
20 && 0 != (tem = simplify_binary_operation (MINUS, mode, op0, op1))
21 - /* We cannot do this for == or != if tem is a nonzero address. */
22 - && ((code != EQ && code != NE) || ! nonzero_address_p (tem))
23 - && code != GTU && code != GEU && code != LTU && code != LEU)
24 + /* We cannot do this if tem is a nonzero address. */
25 + && ! nonzero_address_p (tem))
26 return simplify_relational_operation (signed_condition (code),
27 mode, tem, const0_rtx);
28