]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/11771 (Segfault with simple double arithmetics)
authorRoger Sayle <roger@eyesopen.com>
Mon, 4 Aug 2003 23:46:34 +0000 (23:46 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Mon, 4 Aug 2003 23:46:34 +0000 (23:46 +0000)
PR middle-end/11771
* fold-const.c (negate_expr_p <MINUS_EXPR>): Change to match the
logic in negate_expr, i.e. we don't invert (A-B) for floating
point types unless flag_unsafe_math_optimizations.

* gcc.c-torture/compile/20030804-1.c: New test case.

From-SVN: r70159

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/20030804-1.c [new file with mode: 0644]

index daf0bec3424e173396bbcf0d962b31839bcc515e..60bfb0289e4329cd878af7485cb6d12b540d4c13 100644 (file)
@@ -1,3 +1,10 @@
+2003-08-04  Roger Sayle  <roger@eyesopen.com>
+
+       PR middle-end/11771
+       * fold-const.c (negate_expr_p <MINUS_EXPR>): Change to match the
+       logic in negate_expr, i.e. we don't invert (A-B) for floating
+       point types unless flag_unsafe_math_optimizations.
+
 2003-08-04  Roger Sayle  <roger@eyesopen.com>
 
        * fold-const.c (fold <PLUS_EXPR>): Transform x+x into x*2.0.
index 4dd606f68bf569248b39a711486dfa0faa8638fa..9333c5907477766856e1b33eaafd600e3734c25c 100644 (file)
@@ -841,9 +841,12 @@ negate_expr_p (tree t)
 
     case REAL_CST:
     case NEGATE_EXPR:
-    case MINUS_EXPR:
       return true;
 
+    case MINUS_EXPR:
+      /* We can't turn -(A-B) into B-A when we honor signed zeros.  */
+      return ! FLOAT_TYPE_P (type) || flag_unsafe_math_optimizations;
+
     default:
       break;
     }
index ba19bc89283a4f04ab185fe94c2fda447fbc6d78..86e12c522c411899a2593a0846c72a1a21d872c8 100644 (file)
@@ -1,3 +1,8 @@
+2003-08-04  Roger Sayle  <roger@eyesopen.com>
+
+       PR middle-end/11771
+       * gcc.c-torture/compile/20030804-1.c: New test case.
+
 2003-08-04  Roger Sayle  <roger@eyesopen.com>
 
        * gcc.dg/20030804-1.c: New test case.
diff --git a/gcc/testsuite/gcc.c-torture/compile/20030804-1.c b/gcc/testsuite/gcc.c-torture/compile/20030804-1.c
new file mode 100644 (file)
index 0000000..189fde3
--- /dev/null
@@ -0,0 +1,9 @@
+/* Extracted from PR middle-end/11771.  */
+/* The following testcase used to ICE without -ffast-math from unbounded
+   recursion in fold.  This was due to the logic in negate_expr_p not
+   matching that in negate_expr.  */
+
+double f(double x) {
+    return -(1 - x) + (x ? -(1 - x) : 0);
+}
+