]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/21709 (ICE on compile-time complex NaN)
authorRoger Sayle <roger@eyesopen.com>
Thu, 26 May 2005 05:44:01 +0000 (05:44 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Thu, 26 May 2005 05:44:01 +0000 (05:44 +0000)
PR middle-end/21709
* fold-const.c (const_binop): Check for division by zero during
complex division.

* gcc.dg/pr21709-1.c: New test case.

From-SVN: r100186

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

index d705a11fbb917cdb613ffca01d5ac20e6a21eaf6..3dc4aef291061ff2c2dbcdd1208d54654feb9509 100644 (file)
@@ -1,3 +1,9 @@
+2005-05-25  Roger Sayle  <roger@eyesopen.com>
+
+       PR middle-end/21709
+       * fold-const.c (const_binop): Check for division by zero during
+       complex division.
+
 2005-05-24  Kazuhiro Inaoka <inaoka.kazuhiro@renesas.com>
 
        * config/m32r/m32r.c (m32r_expand_block_move):  Return 0 if
index b34422f15aaff7d7082c702adc8d74521b3c2144..64b0b51e11c80c280eb403ab6eacbdf6b27f4b53 100644 (file)
@@ -1467,33 +1467,36 @@ const_binop (enum tree_code code, tree arg1, tree arg2, int notrunc)
 
        case RDIV_EXPR:
          {
+           tree t1, t2, real, imag;
            tree magsquared
              = const_binop (PLUS_EXPR,
                             const_binop (MULT_EXPR, r2, r2, notrunc),
                             const_binop (MULT_EXPR, i2, i2, notrunc),
                             notrunc);
 
-           t = build_complex (type,
-                              const_binop
-                              (INTEGRAL_TYPE_P (TREE_TYPE (r1))
-                               ? TRUNC_DIV_EXPR : RDIV_EXPR,
-                               const_binop (PLUS_EXPR,
-                                            const_binop (MULT_EXPR, r1, r2,
-                                                         notrunc),
-                                            const_binop (MULT_EXPR, i1, i2,
-                                                         notrunc),
-                                            notrunc),
-                               magsquared, notrunc),
-                              const_binop
-                              (INTEGRAL_TYPE_P (TREE_TYPE (r1))
-                               ? TRUNC_DIV_EXPR : RDIV_EXPR,
-                               const_binop (MINUS_EXPR,
-                                            const_binop (MULT_EXPR, i1, r2,
-                                                         notrunc),
-                                            const_binop (MULT_EXPR, r1, i2,
-                                                         notrunc),
-                                            notrunc),
-                               magsquared, notrunc));
+           t1 = const_binop (PLUS_EXPR,
+                             const_binop (MULT_EXPR, r1, r2, notrunc),
+                             const_binop (MULT_EXPR, i1, i2, notrunc),
+                             notrunc);
+           t2 = const_binop (MINUS_EXPR,
+                             const_binop (MULT_EXPR, i1, r2, notrunc),
+                             const_binop (MULT_EXPR, r1, i2, notrunc),
+                             notrunc);
+
+           if (INTEGRAL_TYPE_P (TREE_TYPE (r1)))
+             {
+               real = const_binop (TRUNC_DIV_EXPR, t1, magsquared, notrunc);
+               imag = const_binop (TRUNC_DIV_EXPR, t2, magsquared, notrunc);
+             }
+           else
+             {
+               real = const_binop (RDIV_EXPR, t1, magsquared, notrunc);
+               imag = const_binop (RDIV_EXPR, t2, magsquared, notrunc);
+               if (!real || !imag)
+                 return NULL_TREE;
+             }
+
+           t = build_complex (type, real, imag);
          }
          break;
 
index 710ee0a1dc77ce23ef0a73915414c97377488765..0e16116b0d7d0a925b2b621f8dca10212ba3295e 100644 (file)
@@ -1,3 +1,8 @@
+2005-05-25  Roger Sayle  <roger@eyesopen.com>
+
+       PR middle-end/21709
+       * gcc.dg/pr21709-1.c: New test case.
+
 2005-05-23  Ulrich Weigand  <uweigand@de.ibm.com>
 
        * gcc.dg/20050510-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pr21709-1.c b/gcc/testsuite/gcc.dg/pr21709-1.c
new file mode 100644 (file)
index 0000000..0d6f20f
--- /dev/null
@@ -0,0 +1,6 @@
+/* PR middle-end/21709 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+double _Complex f(void) { return 1.0iF / 0.0; }
+