Hi Collin,

> I found that the fenv-env tests do not compile on sh4. This is the
> error:
> 
>     test-fenv-env-2.c: In function 'main':
>     test-fenv-env-2.c:49:15: error: 'FE_UPWARD' undeclared (first use in this 
> function)
>        49 |   fesetround (FE_UPWARD);
>           |               ^~~~~~~~~
>     test-fenv-env-2.c:49:15: note: each undeclared identifier is reported 
> only once for each function it appears in
>     test-fenv-env-2.c:76:15: error: 'FE_DOWNWARD' undeclared (first use in 
> this function)
>        76 |   fesetround (FE_DOWNWARD);
>           |               ^~~~~~~~~~~
>     make[4]: *** [Makefile:28483: test-fenv-env-2.o] Error 1

Indeed.

> If I understand correctly, these macros should not be defined on this
> platform. Since ISO C23 § 7.6 states:
> 
>    Each of the macros [List of FE_* macros] is defined if and only if
>    the implementation supports getting and setting the represented
>    round-ing direction by means of the fegetround and fesetround
>    functions.

Yes.

> Based on the SH-4 CPU Core Architecture document § 6.3 [1], this
> architecture only supports Round to Nearest (FE_TONEAREST) and Round to
> Zero (FE_TOWARDZERO).

Yes. Unless a floating-point emulation in software is used, FE_UPWARD
and FE_DOWNLOAD are not available on this architecture.

Fixed through this patch:


2025-06-15  Bruno Haible  <br...@clisp.org>

        fenv-environment tests: Fix compilation errors on Linux/sh4.
        Reported by Collin Funk in
        <https://lists.gnu.org/archive/html/bug-gnulib/2025-06/msg00124.html>.
        * tests/test-fenv-env-2.c (FE_UPWARD, FE_DOWNWARD): Define as aliases.
        * tests/test-fenv-env-3.c: Likewise.
        * tests/test-fenv-env-4.c: Likewise.
        * tests/test-fenv-env-5.c: Likewise.

diff --git a/tests/test-fenv-env-2.c b/tests/test-fenv-env-2.c
index d283e61fdc..5f85bb2418 100644
--- a/tests/test-fenv-env-2.c
+++ b/tests/test-fenv-env-2.c
@@ -25,6 +25,14 @@
 
 /* Test the combination of fegetenv() with fesetenv().  */
 
+/* Some CPUs don't support FE_UPWARD and FE_DOWNWARD in hardware.  */
+#if defined __sh__
+# ifndef FE_UPWARD
+#  define FE_UPWARD   FE_TOWARDZERO
+#  define FE_DOWNWARD FE_TONEAREST
+# endif
+#endif
+
 /* On *BSD/powerpc systems, raising FE_INVALID also sets FE_VXSOFT.  */
 #ifndef FE_VXSOFT
 # define FE_VXSOFT 0
diff --git a/tests/test-fenv-env-3.c b/tests/test-fenv-env-3.c
index 0d86c8a519..a3eb33ed5c 100644
--- a/tests/test-fenv-env-3.c
+++ b/tests/test-fenv-env-3.c
@@ -25,6 +25,14 @@
 
 /* Test the combination of fegetenv() with feupdateenv().  */
 
+/* Some CPUs don't support FE_UPWARD and FE_DOWNWARD in hardware.  */
+#if defined __sh__
+# ifndef FE_UPWARD
+#  define FE_UPWARD   FE_TOWARDZERO
+#  define FE_DOWNWARD FE_TONEAREST
+# endif
+#endif
+
 /* On *BSD/powerpc systems, raising FE_INVALID also sets FE_VXSOFT.  */
 #ifndef FE_VXSOFT
 # define FE_VXSOFT 0
diff --git a/tests/test-fenv-env-4.c b/tests/test-fenv-env-4.c
index 6f1cea1034..084fb14bc5 100644
--- a/tests/test-fenv-env-4.c
+++ b/tests/test-fenv-env-4.c
@@ -25,6 +25,14 @@
 
 /* Test the combination of feholdexcept() with fesetenv().  */
 
+/* Some CPUs don't support FE_UPWARD and FE_DOWNWARD in hardware.  */
+#if defined __sh__
+# ifndef FE_UPWARD
+#  define FE_UPWARD   FE_TOWARDZERO
+#  define FE_DOWNWARD FE_TONEAREST
+# endif
+#endif
+
 /* On *BSD/powerpc systems, raising FE_INVALID also sets FE_VXSOFT.  */
 #ifndef FE_VXSOFT
 # define FE_VXSOFT 0
diff --git a/tests/test-fenv-env-5.c b/tests/test-fenv-env-5.c
index 6a06dfe97a..6e77614e72 100644
--- a/tests/test-fenv-env-5.c
+++ b/tests/test-fenv-env-5.c
@@ -25,6 +25,14 @@
 
 /* Test the combination of feholdexcept() with feupdateenv().  */
 
+/* Some CPUs don't support FE_UPWARD and FE_DOWNWARD in hardware.  */
+#if defined __sh__
+# ifndef FE_UPWARD
+#  define FE_UPWARD   FE_TOWARDZERO
+#  define FE_DOWNWARD FE_TONEAREST
+# endif
+#endif
+
 /* On *BSD/powerpc systems, raising FE_INVALID also sets FE_VXSOFT.  */
 #ifndef FE_VXSOFT
 # define FE_VXSOFT 0




Reply via email to