From: Roger Sayle Date: Thu, 26 May 2005 05:44:01 +0000 (+0000) Subject: re PR middle-end/21709 (ICE on compile-time complex NaN) X-Git-Tag: releases/gcc-3.4.5~406 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f4e40b7cee5e2b95ee8bc92f5d44de3bd8d8555;p=thirdparty%2Fgcc.git re PR middle-end/21709 (ICE on compile-time complex NaN) 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d705a11fbb91..3dc4aef29106 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2005-05-25 Roger Sayle + + PR middle-end/21709 + * fold-const.c (const_binop): Check for division by zero during + complex division. + 2005-05-24 Kazuhiro Inaoka * config/m32r/m32r.c (m32r_expand_block_move): Return 0 if diff --git a/gcc/fold-const.c b/gcc/fold-const.c index b34422f15aaf..64b0b51e11c8 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 710ee0a1dc77..0e16116b0d7d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-05-25 Roger Sayle + + PR middle-end/21709 + * gcc.dg/pr21709-1.c: New test case. + 2005-05-23 Ulrich Weigand * 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 index 000000000000..0d6f20f3260b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr21709-1.c @@ -0,0 +1,6 @@ +/* PR middle-end/21709 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +double _Complex f(void) { return 1.0iF / 0.0; } +