aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2005-05-26 05:51:22 +0000
committerRoger Sayle <sayle@gcc.gnu.org>2005-05-26 05:51:22 +0000
commitc10166c437ce15a119b663ac153a6bbcddb1ce84 (patch)
treef1a62da9b426bbca532d566171554a727730161b /gcc/fold-const.c
parent67730e237530f73a8ac3ff9ea35d7a6438407cd2 (diff)
downloadgcc-c10166c437ce15a119b663ac153a6bbcddb1ce84.zip
gcc-c10166c437ce15a119b663ac153a6bbcddb1ce84.tar.gz
gcc-c10166c437ce15a119b663ac153a6bbcddb1ce84.tar.bz2
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: r100188
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 050d45c..0d5f4eb 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -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;