re PR tree-optimization/63665 (wrong code with signed overflow even with -fwrapv)
authorRichard Biener <rguenther@suse.de>
Tue, 28 Oct 2014 11:42:43 +0000 (11:42 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 28 Oct 2014 11:42:43 +0000 (11:42 +0000)
2014-10-28  Richard Biener  <rguenther@suse.de>

PR middle-end/63665
* fold-const.c (fold_comparison): Properly guard simplifying
against INT_MAX/INT_MIN with !TYPE_OVERFLOW_WRAPS.

* gcc.dg/pr63665.c: New testcase.

From-SVN: r216781

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr63665.c [new file with mode: 0644]

index 536a0007dc03a03f9ca42a3a1e89cfc9c768683f..1f3a0fb007040d6636f924ccace58d72df3d66bd 100644 (file)
@@ -1,3 +1,9 @@
+2014-10-28  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/63665
+       * fold-const.c (fold_comparison): Properly guard simplifying
+       against INT_MAX/INT_MIN with !TYPE_OVERFLOW_WRAPS.
+
 2014-10-28  Alan Lawrence  <alan.lawrence@arm.com>
 
        * expr.c (expand_expr_real_2): Remove code handling VEC_LSHIFT_EXPR.
index 81660706b402e2a1fd34a331639519227e3ad804..218afa01ab4b9a834d074faa389b9b63963c84fc 100644 (file)
@@ -8749,7 +8749,8 @@ fold_comparison (location_t loc, enum tree_code code, tree type,
 
       /* If the constant operation overflowed this can be
         simplified as a comparison against INT_MAX/INT_MIN.  */
-      if (TREE_OVERFLOW (new_const))
+      if (TREE_OVERFLOW (new_const)
+         && !TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0)))
        {
          int const1_sgn = tree_int_cst_sgn (const1);
          enum tree_code code2 = code;
index e0759c3bd04b415c8e71736fa9caf6e1f2e75c37..d08d102fa0393f0e692dd616f552903c65b0b989 100644 (file)
@@ -1,3 +1,8 @@
+2014-10-28  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/63665
+       * gcc.dg/pr63665.c: New testcase.
+
 2014-10-28  Yury Gribov  <y.gribov@samsung.com>
 
        * c-c++-common/asan/kasan-recover-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pr63665.c b/gcc/testsuite/gcc.dg/pr63665.c
new file mode 100644 (file)
index 0000000..046ecae
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do run } */
+/* { dg-require-effective-target int32plus } */
+/* { dg-options "-O -fno-tree-ccp -fno-tree-fre -fno-tree-copy-prop -fwrapv" } */
+
+static inline int
+test5 (int x)
+{
+  int y = 0x80000000;
+  return x + y;
+}
+
+int
+main ()
+{
+  if (test5 (0x80000000) != 0)
+    __builtin_abort ();
+  return 0;
+}