]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/40579 (gcc -O2 optimization causes infinite loop and wrong...
authorRichard Guenther <rguenther@suse.de>
Mon, 29 Jun 2009 14:52:20 +0000 (14:52 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 29 Jun 2009 14:52:20 +0000 (14:52 +0000)
2009-06-29  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/40579
* tree-vrp.c (vrp_evaluate_conditional_warnv): Bail out early if
the IL to simplify has constants that overflowed.

* gcc.c-torture/execute/pr40579.c: New testcase.

From-SVN: r149052

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr40579.c [new file with mode: 0644]
gcc/tree-vrp.c

index a1763870e0df39c500f875086ea19b0d2572b6a2..63ca404ef9ce2e26d32b4710b8872dfc05cfc744 100644 (file)
@@ -1,3 +1,9 @@
+2009-06-29  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/40579
+       * tree-vrp.c (vrp_evaluate_conditional_warnv): Bail out early if
+       the IL to simplify has constants that overflowed.
+
 2009-06-28  Uros Bizjak  <ubizjak@gmail.com>
 
        PR tree-optimization/40550
index c5d17fef3798e9e7eb870ec57e0be6e683f34f16..d3ec476880583a08ecaede07b53bfffe3d6e69dc 100644 (file)
@@ -1,3 +1,8 @@
+2009-06-29  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/40579
+       * gcc.c-torture/execute/pr40579.c: New testcase.
+
 2009-06-28  Uros Bizjak  <ubizjak@gmail.com>
 
        PR tree-optimization/40550
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr40579.c b/gcc/testsuite/gcc.c-torture/execute/pr40579.c
new file mode 100644 (file)
index 0000000..7f44af3
--- /dev/null
@@ -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;
+}
+
index 4a20c74738ec0e23a18d9aadba116b256edbef3c..53f910d97d6563d66489b5d95c8ac3835f7acc2d 100644 (file)
@@ -4989,6 +4989,14 @@ vrp_evaluate_conditional_warnv (tree cond, bool use_equiv_p,
       tree op0 = TREE_OPERAND (cond, 0);
       tree op1 = TREE_OPERAND (cond, 1);
 
+      /* 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;
+
       /* We only deal with integral and pointer types.  */
       if (!INTEGRAL_TYPE_P (TREE_TYPE (op0))
          && !POINTER_TYPE_P (TREE_TYPE (op0)))