diff options
author | Xi Ruoyao <xry111@mengyan1223.wang> | 2022-01-31 01:15:20 +0800 |
---|---|---|
committer | Xi Ruoyao <xry111@mengyan1223.wang> | 2022-02-01 18:20:57 +0800 |
commit | 34afa19d29c5bf0b0f504e4d0aca4e9a8bc82c5c (patch) | |
tree | 974df02b77f39a5ad90e502b19d94fcef6d406f6 /gcc/fold-const.cc | |
parent | d43fbc7d3f7621e1c8f153c1471d2a5cd20bfdc8 (diff) | |
download | gcc-34afa19d29c5bf0b0f504e4d0aca4e9a8bc82c5c.zip gcc-34afa19d29c5bf0b0f504e4d0aca4e9a8bc82c5c.tar.gz gcc-34afa19d29c5bf0b0f504e4d0aca4e9a8bc82c5c.tar.bz2 |
fold-const: do not fold NaN result from non-NaN operands [PR95115]
These operations should raise an invalid operation exception at runtime.
So they should not be folded during compilation unless -fno-trapping-math
is used.
gcc/
PR middle-end/95115
* fold-const.cc (const_binop): Do not fold NaN result from
non-NaN operands.
gcc/testsuite
* gcc.dg/pr95115.c: New test.
Diffstat (limited to 'gcc/fold-const.cc')
-rw-r--r-- | gcc/fold-const.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index b155611..8fc01cd 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -1306,6 +1306,17 @@ const_binop (enum tree_code code, tree arg1, tree arg2) real_convert (&result, mode, &value); /* Don't constant fold this floating point operation if + both operands are not NaN but the result is NaN, and + flag_trapping_math. Such operations should raise an + invalid operation exception. */ + if (flag_trapping_math + && MODE_HAS_NANS (mode) + && REAL_VALUE_ISNAN (result) + && !REAL_VALUE_ISNAN (d1) + && !REAL_VALUE_ISNAN (d2)) + return NULL_TREE; + + /* Don't constant fold this floating point operation if the result has overflowed and flag_trapping_math. */ if (flag_trapping_math && MODE_HAS_INFINITIES (mode) |