]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/45262 (Optimization results in wrong result on expression x>>31...
authorJakub Jelinek <jakub@redhat.com>
Thu, 12 Aug 2010 15:28:40 +0000 (17:28 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 12 Aug 2010 15:28:40 +0000 (17:28 +0200)
PR middle-end/45262
* fold-const.c (make_range) <case NEGATE_EXPR>: Punt if
-a overflows.  Normalize the range.

* gcc.c-torture/execute/pr45262.c: New test.

From-SVN: r163195

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr45262.c [new file with mode: 0644]

index a60b69822e7bfff068a62b8986b6af16a4655847..e33f5e6f8a0bd8bf5ec70f26fd1f06c4b60b58ed 100644 (file)
@@ -1,3 +1,9 @@
+2010-08-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/45262
+       * fold-const.c (make_range) <case NEGATE_EXPR>: Punt if
+       -a overflows.  Normalize the range.
+
 2010-08-10  Steve Ellcey  <sje@cup.hp.com>
            Jakub Jelinek <jakub@redhat.com>
 
index 192665924f0e16adc6fa967c6cd3228444d827d4..4d5e70d4b2689e0e34171b625298af9e73866bd2 100644 (file)
@@ -4479,9 +4479,9 @@ make_range (tree exp, int *pin_p, tree *plow, tree *phigh,
          n_high = range_binop (MINUS_EXPR, exp_type,
                                build_int_cst (exp_type, 0),
                                0, low, 0);
-         low = n_low, high = n_high;
-         exp = arg0;
-         continue;
+         if (n_high != 0 && TREE_OVERFLOW (n_high))
+           break;
+         goto normalize;
 
        case BIT_NOT_EXPR:
          /* ~ X -> -X - 1  */
@@ -4514,6 +4514,7 @@ make_range (tree exp, int *pin_p, tree *plow, tree *phigh,
          if (TYPE_OVERFLOW_UNDEFINED (arg0_type))
            *strict_overflow_p = true;
 
+       normalize:
          /* Check for an unsigned range which has wrapped around the maximum
             value thus making n_high < n_low, and normalize it.  */
          if (n_low && n_high && tree_int_cst_lt (n_high, n_low))
index cf80f396688e77303ae26b654f25160ccb9f7e1c..47d8759cbc9a5022d6c5b0eb54be9d2c8e3702ec 100644 (file)
@@ -1,3 +1,8 @@
+2010-08-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/45262
+       * gcc.c-torture/execute/pr45262.c: New test.
+
 2010-08-10  Steve Ellcey  <sje@cup.hp.com>
 
        Backport from mainline:
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr45262.c b/gcc/testsuite/gcc.c-torture/execute/pr45262.c
new file mode 100644 (file)
index 0000000..72e186b
--- /dev/null
@@ -0,0 +1,33 @@
+/* PR middle-end/45262 */
+
+extern void abort (void);
+
+int
+foo (unsigned int x)
+{
+  return ((int) x < 0) || ((int) (-x) < 0);
+}
+
+int
+bar (unsigned int x)
+{
+  return x >> 31 || (-x) >> 31;
+}
+
+int
+main (void)
+{
+  if (foo (1) != 1)
+    abort ();
+  if (foo (0) != 0)
+    abort ();
+  if (foo (-1) != 1)
+    abort ();
+  if (bar (1) != 1)
+    abort ();
+  if (bar (0) != 0)
+    abort ();
+  if (bar (-1) != 1)
+    abort ();
+  return 0;
+}