]> Savannah Git Hosting - gnulib.git/commitdiff
fpe-trapping: Always clear the FE_INVALID exception flag first.
authorBruno Haible <bruno@clisp.org>
Sat, 28 Oct 2023 16:42:47 +0000 (18:42 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 28 Oct 2023 16:46:16 +0000 (18:46 +0200)
* lib/fpe-trapping.h: Include <fenv.h> on all platforms.
(sigfpe_on_invalid) [AIX, HP-UX, IRIX, Solaris] : Clear the FE_INVALID
exception flag first.
* modules/fpe-trapping (Depends-on): Add fenv-exceptions-tracking-c99.

ChangeLog
lib/fpe-trapping.h
modules/fpe-trapping

index 3af21529c2ff4147e1312281a91bc8a7c8b254af..a527f14ae8f88577e78e4456c839a7f66dbbaa04 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-10-28  Bruno Haible  <bruno@clisp.org>
+
+       fpe-trapping: Always clear the FE_INVALID exception flag first.
+       * lib/fpe-trapping.h: Include <fenv.h> on all platforms.
+       (sigfpe_on_invalid) [AIX, HP-UX, IRIX, Solaris] : Clear the FE_INVALID
+       exception flag first.
+       * modules/fpe-trapping (Depends-on): Add fenv-exceptions-tracking-c99.
+
 2023-10-28  Bruno Haible  <bruno@clisp.org>
 
        fenv-exceptions-tracking-c99: Add tests.
index 6a63327da9bdd86cda4cf1335f0b54c83a3778fe..9040a218ce60b7abf5e7c2dcb4d71155e43fcaad 100644 (file)
 
 #define HAVE_FPE_TRAPPING 1
 
+#include <fenv.h>
+
 #if HAVE_FEENABLEEXCEPT
 /* glibc, FreeBSD ≥ 6.0, NetBSD ≥ 7.0, OpenBSD ≥ 5.0, Cygwin ≥ 1.7.8, Android, Haiku.  */
 
-# include <fenv.h>
-
 static int
 sigfpe_on_invalid ()
 {
@@ -69,7 +69,7 @@ sigfpe_on_invalid ()
   #endif
 
   #if (defined __FreeBSD__ || defined __NetBSD__) && defined __arm__
-  /* Work around a bug with FreeBSD 12.2 on arm64 CPUs:
+  /* Work around a bug with FreeBSD 12.2 on arm CPUs:
      feenableexcept returns success even if the CPU does not support the
      request.  */
   /* Test whether fpscr was actually changed as desired.  */
@@ -102,8 +102,17 @@ sigfpe_on_invalid ()
 static int
 sigfpe_on_invalid ()
 {
+  /* Clear FE_INVALID exceptions from past operations.  */
+  feclearexcept (FE_INVALID);
+
   fpsetmask (fpgetmask () | FP_X_INV);
 
+  #if defined __arm__ || defined __aarch64__
+  /* Test whether the CPU supports the request.  */
+  if ((fpgetmask () & ~FP_X_INV) == 0)
+    return -1;
+  #endif
+
   return 0;
 }
 
@@ -115,6 +124,9 @@ sigfpe_on_invalid ()
 static int
 sigfpe_on_invalid ()
 {
+  /* Clear FE_INVALID exceptions from past operations.  */
+  feclearexcept (FE_INVALID);
+
   fesettrapenable (fegettrapenable () | FE_INVALID);
 
   return 0;
@@ -128,6 +140,9 @@ sigfpe_on_invalid ()
 static int
 sigfpe_on_invalid ()
 {
+  /* Clear FE_INVALID exceptions from past operations.  */
+  feclearexcept (FE_INVALID);
+
   /* Enable precise trapping mode.
      Documentation: <https://www.ibm.com/docs/en/aix/7.3?topic=f-fp-trap-subroutine>  */
   fp_trap (FP_TRAP_SYNC);
index d8acbe8a27240586720e353614dc416f4a842618..353e77bdefa9ae667a175069ad4c409b24a920b3 100644 (file)
@@ -10,6 +10,7 @@ m4/musl.m4
 
 Depends-on:
 extensions
+fenv-exceptions-tracking-c99
 
 configure.ac:
 gl_FPE_TRAPPING