Some tests check for fenv and then proceed to use fesetround() directly,
but some platforms (at least RISC-V soft-float) have fenv but don't
support rounding modes. This adds a DG check that fesetround() actually
functions, which is then used by all the tests that call fesetround()
explicitly.
gcc/testsuite/ChangeLog
* lib/target-supports.exp
(check_effective_target_fenv_setround): New function.
* gcc.dg/torture/fp-double-convert-float-1.c: Check
fenv_fesetround.
* gcc.dg/torture/fp-int-convert-float128-timode-3.c: Likewise.
* gcc.dg/torture/fp-int-convert-timode-2.c: Likewise.
* gcc.dg/torture/fp-int-convert-timode-3.c: Likewise.
* gcc.dg/torture/fp-int-convert-timode-4.c: Likewise.
* gcc.dg/torture/fp-uint64-convert-double-1.c: Likewise.
* gcc.dg/torture/fp-uint64-convert-double-2.c: Likewise.
gcc/ChangeLog
* doc/sourcebuild.texi: Document fenv_setround.
---
This was approved with the doc change in the v2
<[email protected]>, but I'll hold off a
bit on committing it just in case anyone else has feedback.
---
gcc/doc/sourcebuild.texi | 4 +++
.../torture/fp-double-convert-float-1.c | 2 +-
.../fp-int-convert-float128-timode-3.c | 2 +-
.../gcc.dg/torture/fp-int-convert-timode-2.c | 2 +-
.../gcc.dg/torture/fp-int-convert-timode-3.c | 2 +-
.../gcc.dg/torture/fp-int-convert-timode-4.c | 2 +-
.../torture/fp-uint64-convert-double-1.c | 2 +-
.../torture/fp-uint64-convert-double-2.c | 2 +-
gcc/testsuite/lib/target-supports.exp | 35 +++++++++++++++++++
9 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 613ac29967b..793e2f353e8 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2560,6 +2560,10 @@ Target supports @file{fenv.h} with all the standard IEEE
exceptions
and floating-point exceptions are raised by arithmetic operations for
decimal floating point.
+@item fenv_setround
+Target supports @file{fenv.h} and any standard IEEE rounding mode that is
+defined is implemented in the environment under test.
+
@item fileio
Target offers such file I/O library functions as @code{fopen},
@code{fclose}, @code{tmpnam}, and @code{remove}. This is a link-time
diff --git a/gcc/testsuite/gcc.dg/torture/fp-double-convert-float-1.c
b/gcc/testsuite/gcc.dg/torture/fp-double-convert-float-1.c
index ec23274ea98..656e5c345e7 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-double-convert-float-1.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-double-convert-float-1.c
@@ -1,6 +1,6 @@
/* PR57245 */
/* { dg-do run } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
/* { dg-additional-options "-frounding-math" } */
#include <fenv.h>
diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert-float128-timode-3.c
b/gcc/testsuite/gcc.dg/torture/fp-int-convert-float128-timode-3.c
index c445d10522e..499e8c0cabf 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-int-convert-float128-timode-3.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert-float128-timode-3.c
@@ -4,7 +4,7 @@
/* { dg-require-effective-target __float128 } */
/* { dg-require-effective-target base_quadfloat_support } */
/* { dg-require-effective-target int128 } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
/* { dg-options "-frounding-math" } */
/* { dg-add-options __float128 } */
diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-2.c
b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-2.c
index a82f03d079c..3f91f8f3833 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-2.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-2.c
@@ -2,7 +2,7 @@
float. */
/* { dg-do run } */
/* { dg-require-effective-target int128 } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
/* { dg-options "-frounding-math" } */
#include <fenv.h>
diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-3.c
b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-3.c
index 707d539335f..816fcb1120e 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-3.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-3.c
@@ -2,7 +2,7 @@
float. */
/* { dg-do run } */
/* { dg-require-effective-target int128 } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
/* { dg-options "-frounding-math" } */
#include <fenv.h>
diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-4.c
b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-4.c
index 09600f90903..6337a6d3f1e 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-4.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-4.c
@@ -2,7 +2,7 @@
float. */
/* { dg-do run } */
/* { dg-require-effective-target int128 } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
/* { dg-options "-frounding-math" } */
#include <fenv.h>
diff --git a/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-1.c
b/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-1.c
index fadad8c3198..43aeb81a602 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-1.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-1.c
@@ -1,6 +1,6 @@
/* PR84407 */
/* { dg-do run } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
/* { dg-additional-options "-frounding-math -fexcess-precision=standard" } */
#include <fenv.h>
diff --git a/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-2.c
b/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-2.c
index 952f96b33c9..d380b4a80e8 100644
--- a/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-2.c
+++ b/gcc/testsuite/gcc.dg/torture/fp-uint64-convert-double-2.c
@@ -1,6 +1,6 @@
/* PR84407 */
/* { dg-do run } */
-/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target fenv_setround } */
/* { dg-additional-options "-frounding-math" } */
#include <fenv.h>
diff --git a/gcc/testsuite/lib/target-supports.exp
b/gcc/testsuite/lib/target-supports.exp
index 2d5d0539bb4..bd4dab0a9ad 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -10685,6 +10685,41 @@ proc check_effective_target_fenv_exceptions_dfp {} {
} [add_options_for_ieee "-std=gnu99"]]
}
+
+# Return 1 if <fenv.h> is availiable and supports fesetround.
+
+proc check_effective_target_fenv_setround {} {
+ return [check_runtime fenv_setround {
+ #include <fenv.h>
+ #include <stdlib.h>
+ int
+ main (void)
+ {
+ #ifdef FE_TONEAREST
+ if (fesetround (FE_TONEAREST) != 0)
+ abort ();
+ #endif
+
+ #ifdef FE_UPWARD
+ if (fesetround (FE_UPWARD) != 0)
+ abort ();
+ #endif
+
+ #ifdef FE_DOWNWARD
+ if (fesetround (FE_DOWNWARD) != 0)
+ abort ();
+ #endif
+
+ #ifdef FE_TOWARDZERO
+ if (fesetround (FE_TOWARDZERO) != 0)
+ abort ();
+ #endif
+
+ exit (0);
+ }
+ } [add_options_for_ieee "-std=gnu99"]]
+}
+
# Return 1 if -fexceptions is supported.
proc check_effective_target_exceptions {} {
--
2.34.1