re PR tree-optimization/79666 (wrong code (SIGFPE) at -O2 on x86_64-linux-gnu (in...
authorRichard Biener <rguenther@suse.de>
Wed, 22 Feb 2017 12:11:27 +0000 (12:11 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 22 Feb 2017 12:11:27 +0000 (12:11 +0000)
2017-02-22  Richard Biener  <rguenther@suse.de>

PR tree-optimization/79666
* tree-vrp.c (extract_range_from_binary_expr_1): Make sure
to not symbolically negate if that may introduce undefined
overflow.

* gcc.dg/torture/pr79666.c: New testcase.

From-SVN: r245648

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

index 1911946edcd3bcf945c31dfdc2a04246247ef56d..aa7a1cfc7e32f4b3730201c0c2244eb8ea995874 100644 (file)
@@ -1,3 +1,10 @@
+2017-02-22  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/79666
+       * tree-vrp.c (extract_range_from_binary_expr_1): Make sure
+       to not symbolically negate if that may introduce undefined
+       overflow.
+
 2017-02-22  Martin Liska  <mliska@suse.cz>
 
        PR lto/79587
index 19ddc6efac8de5a2004ca87dc3f0744bff6ff161..af56482b5afbf924fb31b179004a136cb4437915 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-22  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/79666
+       * gcc.dg/torture/pr79666.c: New testcase.
+
 2017-02-22  Martin Liska  <mliska@suse.cz>
 
        PR lto/79587
diff --git a/gcc/testsuite/gcc.dg/torture/pr79666.c b/gcc/testsuite/gcc.dg/torture/pr79666.c
new file mode 100644 (file)
index 0000000..3d83229
--- /dev/null
@@ -0,0 +1,30 @@
+/* { dg-do run } */
+
+struct
+{
+  unsigned a:6;
+} b;
+
+int c, e, g = 7;
+signed char d, f = 6, h = -10;
+
+void fn1 ()
+{
+  for (; c < 9; c++)
+    {
+      if (f)
+       g = ~(~0 / (g ^ e));
+      b.a = ~0;
+      d = ~((h ^ b.a) & 132 & (~(f && g) | (d && 1)));
+      e = ~0;
+      if (d < 127 || f < 1)
+       continue;
+      g = 0;
+    }
+}
+
+int main ()
+{
+  fn1 ();
+  return 0; 
+}
index 95bf1cf86969f78bec11659fdb92b6b7e4fec368..6420041fd1381568df8713cbfe7770ee6e83e99d 100644 (file)
@@ -2631,8 +2631,17 @@ extract_range_from_binary_expr_1 (value_range *vr,
            min = build_symbolic_expr (expr_type, sym_min_op0,
                                       neg_min_op0, min);
          else if (sym_min_op1)
-           min = build_symbolic_expr (expr_type, sym_min_op1,
-                                      neg_min_op1 ^ minus_p, min);
+           {
+             /* We may not negate if that might introduce
+                undefined overflow.  */
+             if (! minus_p
+                 || neg_min_op1
+                 || TYPE_OVERFLOW_WRAPS (expr_type))
+               min = build_symbolic_expr (expr_type, sym_min_op1,
+                                          neg_min_op1 ^ minus_p, min);
+             else
+               min = NULL_TREE;
+           }
 
          /* Likewise for the upper bound.  */
          if (sym_max_op0 == sym_max_op1)
@@ -2641,8 +2650,17 @@ extract_range_from_binary_expr_1 (value_range *vr,
            max = build_symbolic_expr (expr_type, sym_max_op0,
                                       neg_max_op0, max);
          else if (sym_max_op1)
-           max = build_symbolic_expr (expr_type, sym_max_op1,
-                                      neg_max_op1 ^ minus_p, max);
+           {
+             /* We may not negate if that might introduce
+                undefined overflow.  */
+             if (! minus_p
+                 || neg_max_op1
+                 || TYPE_OVERFLOW_WRAPS (expr_type))
+               max = build_symbolic_expr (expr_type, sym_max_op1,
+                                          neg_max_op1 ^ minus_p, max);
+             else
+               max = NULL_TREE;
+           }
        }
       else
        {