diff options
author | liuhongt <hongtao.liu@intel.com> | 2024-05-21 16:57:17 +0800 |
---|---|---|
committer | liuhongt <hongtao.liu@intel.com> | 2024-06-05 12:08:35 +0800 |
commit | b05288d1f1e4b632eddf8830b4369d4659f6c2ff (patch) | |
tree | b8f475d6293176e73e9d1894bb3dcf08e4ffee20 /gcc/fold-const.cc | |
parent | 4638e508aa814d4aa2e204c3ab041c6a56aad2bd (diff) | |
download | gcc-b05288d1f1e4b632eddf8830b4369d4659f6c2ff.zip gcc-b05288d1f1e4b632eddf8830b4369d4659f6c2ff.tar.gz gcc-b05288d1f1e4b632eddf8830b4369d4659f6c2ff.tar.bz2 |
Don't simplify NAN/INF or out-of-range constant for FIX/UNSIGNED_FIX.
According to IEEE standard, for conversions from floating point to
integer. When a NaN or infinite operand cannot be represented in the
destination format and this cannot otherwise be indicated, the invalid
operation exception shall be signaled. When a numeric operand would
convert to an integer outside the range of the destination format, the
invalid operation exception shall be signaled if this situation cannot
otherwise be indicated.
The patch prevent simplication of the conversion from floating point
to integer for NAN/INF/out-of-range constant when flag_trapping_math.
gcc/ChangeLog:
PR rtl-optimization/100927
PR rtl-optimization/115161
PR rtl-optimization/115115
* simplify-rtx.cc (simplify_const_unary_operation): Prevent
simplication of FIX/UNSIGNED_FIX for NAN/INF/out-of-range
constant when flag_trapping_math.
* fold-const.cc (fold_convert_const_int_from_real): Don't fold
for overflow value when_trapping_math.
gcc/testsuite/ChangeLog:
* gcc.dg/pr100927.c: New test.
* c-c++-common/Wconversion-1.c: Add -fno-trapping-math.
* c-c++-common/dfp/convert-int-saturate.c: Ditto.
* g++.dg/ubsan/pr63956.C: Ditto.
* g++.dg/warn/Wconversion-real-integer.C: Ditto.
* gcc.c-torture/execute/20031003-1.c: Ditto.
* gcc.dg/Wconversion-complex-c99.c: Ditto.
* gcc.dg/Wconversion-real-integer.c: Ditto.
* gcc.dg/c90-const-expr-11.c: Ditto.
* gcc.dg/overflow-warn-8.c: Ditto.
Diffstat (limited to 'gcc/fold-const.cc')
-rw-r--r-- | gcc/fold-const.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 92b048c..710d697 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -2246,7 +2246,18 @@ fold_convert_const_int_from_real (enum tree_code code, tree type, const_tree arg if (! overflow) val = real_to_integer (&r, &overflow, TYPE_PRECISION (type)); - t = force_fit_type (type, val, -1, overflow | TREE_OVERFLOW (arg1)); + /* According to IEEE standard, for conversions from floating point to + integer. When a NaN or infinite operand cannot be represented in the + destination format and this cannot otherwise be indicated, the invalid + operation exception shall be signaled. When a numeric operand would + convert to an integer outside the range of the destination format, the + invalid operation exception shall be signaled if this situation cannot + otherwise be indicated. */ + if (!flag_trapping_math || !overflow) + t = force_fit_type (type, val, -1, overflow | TREE_OVERFLOW (arg1)); + else + t = NULL_TREE; + return t; } |