[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: totalorder, totalorderf: Fix handling of SNaN on i386 and x86_64 CPU
From: |
Bruno Haible |
Subject: |
Re: totalorder, totalorderf: Fix handling of SNaN on i386 and x86_64 CPUs |
Date: |
Tue, 09 Apr 2024 17:49:10 +0200 |
I wrote:
> This patch does it and thus fixes the test failures on Linux and NetBSD.
Well, it fixes them only when not optimizing. With -O2, I see the
same miscompilation with gcc as with clang. This patch works around it.
2024-04-09 Bruno Haible <bruno@clisp.org>
totalorder, totalorderf: Avoid miscompilation by gcc on NetBSD/i386.
* lib/totalorder.c (totalorder): Use the a compiler optimization barrier
also for GCC.
* lib/totalorderf.c (totalorderf): Likewise.
diff --git a/lib/totalorder.c b/lib/totalorder.c
index eaef9a582d..445b8f84d6 100644
--- a/lib/totalorder.c
+++ b/lib/totalorder.c
@@ -57,9 +57,11 @@ totalorder (double const *x, double const *y)
xu.f = *x;
yu.f = *y;
#else
-# ifdef __clang__
- /* Prevent clang 16.0.6 on OpenBSD 7.5 from reusing the values of *x and *y
- (fetched above) in optimized inlined memcpy expansions. */
+# if defined __GNUC__ || defined __clang__
+ /* Prevent gcc and clang from reusing the values of *x and *y (fetched above)
+ in optimized inlined memcpy expansions.
+ Seen with gcc <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114659>
+ and with clang 16.0.6 on OpenBSD 7.5. */
__asm__ __volatile__ ("" : : : "memory");
# endif
/* On 32-bit x86 processors, as well as on x86_64 processors with
diff --git a/lib/totalorderf.c b/lib/totalorderf.c
index f5f1b40112..70bc02cd90 100644
--- a/lib/totalorderf.c
+++ b/lib/totalorderf.c
@@ -57,9 +57,11 @@ totalorderf (float const *x, float const *y)
xu.f = *x;
yu.f = *y;
#else
-# ifdef __clang__
- /* Prevent clang 16.0.6 on OpenBSD 7.5 from reusing the values of *x and *y
- (fetched above) in optimized inlined memcpy expansions. */
+# if defined __GNUC__ || defined __clang__
+ /* Prevent gcc and clang from reusing the values of *x and *y (fetched above)
+ in optimized inlined memcpy expansions.
+ Seen with gcc <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114659>
+ and with clang 16.0.6 on OpenBSD 7.5. */
__asm__ __volatile__ ("" : : : "memory");
# endif
/* On 32-bit x86 processors, as well as on x86_64 processors with