]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR tree-optimization/68911
authoramker <amker@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 12 Jan 2016 17:49:51 +0000 (17:49 +0000)
committeramker <amker@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 12 Jan 2016 17:49:51 +0000 (17:49 +0000)
* tree-vrp.c (adjust_range_with_scev): Check overflow in range
information computed for expression "init + nit * step".

gcc/testsuite/ChangeLog
PR tree-optimization/68911
* gcc.c-torture/execute/pr68911.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@232286 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 6fcf9b2ed9bd7bcfe415984d78e1255b7b151bbf..ca02f822b232cf793210ccf6332b2a2d56643de4 100644 (file)
@@ -1,3 +1,9 @@
+2016-01-12  Bin Cheng  <bin.cheng@arm.com>
+
+       PR tree-optimization/68911
+       * tree-vrp.c (adjust_range_with_scev): Check overflow in range
+       information computed for expression "init + nit * step".
+
 2016-01-12  Sandra Loosemore <sandra@codesourcery.com>
 
        * doc/invoke.texi (Invoking GCC): Copy-edit.  Incorporate information
index ec887e975056672d3ee7deb5ffe1546af39e990d..435ffde8e1bef065ca9f93f166e927d209aef799 100644 (file)
@@ -1,3 +1,8 @@
+2016-01-12  Bin Cheng  <bin.cheng@arm.com>
+
+       PR tree-optimization/68911
+       * gcc.c-torture/execute/pr68911.c: New test.
+
 2016-01-12  Marek Polacek  <polacek@redhat.com>
 
        PR c++/68979
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr68911.c b/gcc/testsuite/gcc.c-torture/execute/pr68911.c
new file mode 100644 (file)
index 0000000..b8cbdb5
--- /dev/null
@@ -0,0 +1,27 @@
+extern void abort (void);
+
+char a;
+int b, c;
+short d;
+
+int main ()
+{
+  unsigned e = 2;
+  unsigned timeout = 0;
+
+  for (; c < 2; c++)
+    {
+      int f = ~e / 7;
+      if (f)
+       a = e = ~(b && d);
+      while (e < 94)
+       {
+         e++;
+         if (++timeout > 100)
+           goto die;
+       }
+    }
+  return 0;
+die:
+  abort ();
+}
index 920a9b1818dabc0521d62b2c74a10c2973e3c1a0..8f35eb73277edbc50549ba593cc7156f07c652e0 100644 (file)
@@ -4259,6 +4259,27 @@ adjust_range_with_scev (value_range *vr, struct loop *loop,
              /* Likewise if the addition did.  */
              if (maxvr.type == VR_RANGE)
                {
+                 value_range initvr = VR_INITIALIZER;
+
+                 if (TREE_CODE (init) == SSA_NAME)
+                   initvr = *(get_value_range (init));
+                 else if (is_gimple_min_invariant (init))
+                   set_value_range_to_value (&initvr, init, NULL);
+                 else
+                   return;
+
+                 /* Check if init + nit * step overflows.  Though we checked
+                    scev {init, step}_loop doesn't wrap, it is not enough
+                    because the loop may exit immediately.  Overflow could
+                    happen in the plus expression in this case.  */
+                 if ((dir == EV_DIR_DECREASES
+                      && (is_negative_overflow_infinity (maxvr.min)
+                          || compare_values (maxvr.min, initvr.min) != -1))
+                     || (dir == EV_DIR_GROWS
+                         && (is_positive_overflow_infinity (maxvr.max)
+                             || compare_values (maxvr.max, initvr.max) != 1)))
+                   return;
+
                  tmin = maxvr.min;
                  tmax = maxvr.max;
                }