aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg
diff options
context:
space:
mode:
authorliuhongt <hongtao.liu@intel.com>2024-05-21 16:57:17 +0800
committerliuhongt <hongtao.liu@intel.com>2024-06-05 12:08:35 +0800
commitb05288d1f1e4b632eddf8830b4369d4659f6c2ff (patch)
treeb8f475d6293176e73e9d1894bb3dcf08e4ffee20 /gcc/testsuite/gcc.dg
parent4638e508aa814d4aa2e204c3ab041c6a56aad2bd (diff)
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/testsuite/gcc.dg')
-rw-r--r--gcc/testsuite/gcc.dg/Wconversion-complex-c99.c2
-rw-r--r--gcc/testsuite/gcc.dg/Wconversion-real-integer.c2
-rw-r--r--gcc/testsuite/gcc.dg/c90-const-expr-11.c2
-rw-r--r--gcc/testsuite/gcc.dg/overflow-warn-8.c1
-rw-r--r--gcc/testsuite/gcc.dg/pr100927.c31
5 files changed, 35 insertions, 3 deletions
diff --git a/gcc/testsuite/gcc.dg/Wconversion-complex-c99.c b/gcc/testsuite/gcc.dg/Wconversion-complex-c99.c
index e8bc9db237d..69281c7d71e 100644
--- a/gcc/testsuite/gcc.dg/Wconversion-complex-c99.c
+++ b/gcc/testsuite/gcc.dg/Wconversion-complex-c99.c
@@ -6,7 +6,7 @@
/* { dg-do compile } */
/* { dg-skip-if "doubles are floats,ints are 16bits" { "avr-*-*" } } */
-/* { dg-options " -std=c99 -pedantic -Wconversion " } */
+/* { dg-options " -std=c99 -pedantic -Wconversion -fno-trapping-math" } */
/* { dg-require-effective-target int32plus } */
/* { dg-require-effective-target double64plus } */
diff --git a/gcc/testsuite/gcc.dg/Wconversion-real-integer.c b/gcc/testsuite/gcc.dg/Wconversion-real-integer.c
index 92e6987d9ec..ca6007f4fe8 100644
--- a/gcc/testsuite/gcc.dg/Wconversion-real-integer.c
+++ b/gcc/testsuite/gcc.dg/Wconversion-real-integer.c
@@ -3,7 +3,7 @@
/* { dg-do compile } */
/* { dg-skip-if "doubles are floats,ints are 16bits" { "avr-*-*" } } */
-/* { dg-options "-std=c99 -Wconversion" } */
+/* { dg-options "-std=c99 -Wconversion -fno-trapping-math" } */
/* { dg-require-effective-target int32plus } */
/* { dg-require-effective-target double64plus } */
#include <limits.h>
diff --git a/gcc/testsuite/gcc.dg/c90-const-expr-11.c b/gcc/testsuite/gcc.dg/c90-const-expr-11.c
index a2720c47bf4..65aab10a129 100644
--- a/gcc/testsuite/gcc.dg/c90-const-expr-11.c
+++ b/gcc/testsuite/gcc.dg/c90-const-expr-11.c
@@ -2,7 +2,7 @@
constant expressions. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
-/* { dg-options "-std=iso9899:1990 -pedantic-errors -O2" } */
+/* { dg-options "-std=iso9899:1990 -pedantic-errors -O2 -fno-trapping-math" } */
#include <float.h>
#include <limits.h>
diff --git a/gcc/testsuite/gcc.dg/overflow-warn-8.c b/gcc/testsuite/gcc.dg/overflow-warn-8.c
index e76bcac5e07..75bfa74f3dc 100644
--- a/gcc/testsuite/gcc.dg/overflow-warn-8.c
+++ b/gcc/testsuite/gcc.dg/overflow-warn-8.c
@@ -1,5 +1,6 @@
#include <limits.h>
+/* { dg-options " -fno-trapping-math" } */
void foo (int j)
{
int i1 = (int)(double)1.0 + INT_MAX; /* { dg-warning "integer overflow" } */
diff --git a/gcc/testsuite/gcc.dg/pr100927.c b/gcc/testsuite/gcc.dg/pr100927.c
new file mode 100644
index 00000000000..ea0e627befa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr100927.c
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftrapping-math -fdump-tree-optimized -fdump-rtl-final" } */
+/* { dg-final { scan-tree-dump-times {(?n)= \(int\)} 3 "optimized" } } */
+/* { dg-final { scan-rtl-dump-times {(?n)\(fix:SI} 3 "final" } } */
+
+int
+foo_ofr ()
+{
+ union {float a;
+ int b;}c;
+ c.b = 0x4f000000;
+ return (int)c.a;
+}
+
+int
+foo_inf ()
+{
+ union {float a;
+ int b;}c;
+ c.b = 0xff800000;
+ return (int)c.a;
+}
+
+int
+foo_nan ()
+{
+ union {float a;
+ int b;}c;
+ c.b = 0xff800001;
+ return (int)c.a;
+}