re PR middle-end/21709 (ICE on compile-time complex NaN)
authorRoger Sayle <roger@eyesopen.com>
Thu, 26 May 2005 05:51:22 +0000 (05:51 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Thu, 26 May 2005 05:51:22 +0000 (05:51 +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: r100188

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

index e179c5f429f348c12da96a15dfb3f0cc044f16c4..6d9e69f5c1923683f9906f827ce79227bed1f0b4 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-26  Ian Lance Taylor  <ian@airs.com>
 
        * reload1.c (verify_initial_elim_offsets): Add braces to avoid
index 050d45c6069c2ab6b4d7482d2b2d1d9186d7c191..0d5f4ebf2b17fc4628bdfd2bc24938e61980c996 100644 (file)
@@ -1600,33 +1600,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 0944c2943d982cd605ae4524dd66afd9acde92f7..9f2f537a924be53699304fb334fc71c4ee007ef8 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-25  Ziemowit Laski  <zlaski@apple.com>
            Mike Stump  <mrs@apple.com>
 
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; }
+