This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR40579, wrong-code simplifying ranges
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 29 Jun 2009 13:55:42 +0200 (CEST)
- Subject: [PATCH] Fix PR40579, wrong-code simplifying ranges
This fixes PR40579, a case where VRP conditional folding is confused
by constants with TREE_OVERFLOW set in the IL. Not the first time...
A safe conservative fix is to bail out early in this case.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
I'm testing backports right now.
Richard.
2009-06-29 Richard Guenther <rguenther@suse.de>
PR tree-optimization/40579
* tree-vrp.c (vrp_evaluate_conditional): Bail out early if
the IL to simplify has constants that overflowed.
* gcc.c-torture/execute/pr40579.c: New testcase.
Index: gcc/tree-vrp.c
===================================================================
*** gcc/tree-vrp.c (revision 149044)
--- gcc/tree-vrp.c (working copy)
*************** vrp_evaluate_conditional (enum tree_code
*** 5679,5684 ****
--- 5679,5692 ----
tree ret;
bool only_ranges;
+ /* Some passes and foldings leak constants with overflow flag set
+ into the IL. Avoid doing wrong things with these and bail out. */
+ if ((TREE_CODE (op0) == INTEGER_CST
+ && TREE_OVERFLOW (op0))
+ || (TREE_CODE (op1) == INTEGER_CST
+ && TREE_OVERFLOW (op1)))
+ return NULL_TREE;
+
sop = false;
ret = vrp_evaluate_conditional_warnv_with_ops (code, op0, op1, true, &sop,
&only_ranges);
Index: gcc/testsuite/gcc.c-torture/execute/pr40579.c
===================================================================
*** gcc/testsuite/gcc.c-torture/execute/pr40579.c (revision 0)
--- gcc/testsuite/gcc.c-torture/execute/pr40579.c (revision 0)
***************
*** 0 ****
--- 1,28 ----
+ extern void abort (void);
+ static char * __attribute__((noinline))
+ itos(int num)
+ {
+ return (char *)0;
+ }
+ static void __attribute__((noinline))
+ foo(int i, const char *x)
+ {
+ if (i >= 4)
+ abort ();
+ }
+ int main()
+ {
+ int x = -__INT_MAX__ + 3;
+ int i;
+
+ for (i = 0; i < 4; ++i)
+ {
+ char *p;
+ --x;
+ p = itos(x);
+ foo(i, p);
+ }
+
+ return 0;
+ }
+