]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/92131 (incorrect assumption that (ao >= 0) is always false)
authorEric Botcazou <ebotcazou@gcc.gnu.org>
Wed, 23 Oct 2019 13:17:34 +0000 (13:17 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Wed, 23 Oct 2019 13:17:34 +0000 (13:17 +0000)
PR tree-optimization/92131
* tree-vrp.c (extract_range_from_plus_minus_expr): If the resulting
range would be symbolic, drop to varying for any explicit overflow
in the constant part or if neither range is a singleton.

From-SVN: r277331

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

index 2300b57f48db1eaa8059c81048b3029c5f3782c7..fe43786a8e1268a9a8c33d09d02872cb54d915c3 100644 (file)
@@ -1,6 +1,14 @@
+2019-10-23  Eric Botcazou  <ebotcazou@adacore.com>
+
+       PR tree-optimization/92131
+       * tree-vrp.c (extract_range_from_plus_minus_expr): If the resulting
+       range would be symbolic, drop to varying for any explicit overflow
+       in the constant part or if neither range is a singleton.
+
 2019-10-18  Georg-Johann Lay  <avr@gjlay.de>
 
-       Backport from 2019-10-18 trunk r277143.
+       Backport from trunk
+       2019-10-18  Georg-Johann Lay  <avr@gjlay.de>
 
        PR target/86040
        * config/avr/avr.c (avr_out_lpm): Do not shortcut-return.
index fc2a754361aec8fee609ba31c8f4136c21796601..9dfad63b9ab3e535d19e22a54b967449a98b431c 100644 (file)
@@ -1,3 +1,7 @@
+2019-10-23  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc.c-torture/execute/20191023-1.c: New test.
+
 2019-10-18  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/69455
diff --git a/gcc/testsuite/gcc.c-torture/execute/20191023-1.c b/gcc/testsuite/gcc.c-torture/execute/20191023-1.c
new file mode 100644 (file)
index 0000000..3811ebc
--- /dev/null
@@ -0,0 +1,73 @@
+/* PR tree-optimization/92131 */
+/* Testcase by Armin Rigo <arigo@tunes.org> */
+
+long b, c, d, e, f, i;
+char g, h, j, k;
+int *aa;
+
+static void error (void) __attribute__((noipa));
+static void error (void) { __builtin_abort(); }
+
+static void see_me_here (void) __attribute__((noipa));
+static void see_me_here (void) {}
+
+static void aaa (void) __attribute__((noipa));
+static void aaa (void) {}
+
+static void a (void) __attribute__((noipa));
+static void a (void) {
+  long am, ao;
+  if (aa == 0) {
+    aaa();
+    if (j)
+      goto ay;
+  }
+  return;
+ay:
+  aaa();
+  if (k) {
+    aaa();
+    goto az;
+  }
+  return;
+az:
+  if (i)
+    if (g)
+      if (h)
+        if (e)
+          goto bd;
+  return;
+bd:
+  am = 0;
+  while (am < e) {
+    switch (c) {
+    case 8:
+      goto bh;
+    case 4:
+      return;
+    }
+  bh:
+    if (am >= 0)
+      b = -am;
+    ao = am + b;
+    f = ao & 7;
+    if (f == 0)
+      see_me_here();
+    if (ao >= 0)
+      am++;
+    else
+      error();
+  }
+}
+
+int main (void)
+{
+    j++;
+    k++;
+    i++;
+    g++;
+    h++;
+    e = 1;
+    a();
+    return 0;
+}
index b5424befc785a9810f17c61c82411b79aa4af806..f2ef37290de3bb08ae592d9a3df49fb34781b3c0 100644 (file)
@@ -2535,10 +2535,13 @@ extract_range_from_binary_expr_1 (value_range *vr,
                max_ovf = 1;
            }
 
-         /* If we have overflow for the constant part and the resulting
-            range will be symbolic, drop to VR_VARYING.  */
-         if ((min_ovf && sym_min_op0 != sym_min_op1)
-             || (max_ovf && sym_max_op0 != sym_max_op1))
+         /* If the resulting range will be symbolic, we need to eliminate any
+            explicit or implicit overflow introduced in the above computation
+            because compare_values could make an incorrect use of it.  That's
+            why we require one of the ranges to be a singleton.  */
+         if ((sym_min_op0 != sym_min_op1 || sym_max_op0 != sym_max_op1)
+             && (min_ovf || max_ovf
+                 || (min_op0 != max_op0 && min_op1 != max_op1)))
            {
              set_value_range_to_varying (vr);
              return;