]> Savannah Git Hosting - gnulib.git/commitdiff
totalorder, totalorderf: Avoid miscompilation by clang on OpenBSD/i386.
authorBruno Haible <bruno@clisp.org>
Tue, 9 Apr 2024 12:17:38 +0000 (14:17 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 9 Apr 2024 12:17:38 +0000 (14:17 +0200)
* lib/totalorder.c (totalorder): Insert a compiler optimization barrier.
* lib/totalorderf.c (totalorderf): Likewise.

ChangeLog
lib/totalorder.c
lib/totalorderf.c

index b05ef3fe84e120d945eff33e3ce9a74c99cd78fd..c258cdfb3d9667b45b8fdf6b1640b34c7f53f956 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-04-09  Bruno Haible  <bruno@clisp.org>
+
+       totalorder, totalorderf: Avoid miscompilation by clang on OpenBSD/i386.
+       * lib/totalorder.c (totalorder): Insert a compiler optimization barrier.
+       * lib/totalorderf.c (totalorderf): Likewise.
+
 2024-04-09  Bruno Haible  <bruno@clisp.org>
 
        totalorder, totalorderf: Fix handling of SNaN on i386 and x86_64 CPUs.
index 635e3cb2761dbc2030d6a3f5720b3b6c238451c4..eaef9a582db255402318cf48d2c8d48cfff7ac0c 100644 (file)
@@ -57,6 +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.  */
+  __asm__ __volatile__ ("" : : : "memory");
+# endif
   /* On 32-bit x86 processors, as well as on x86_64 processors with
      CC="gcc -mfpmath=387", the evaluation of *x and *y above is done through
      an 'fldl' instruction, which converts a signalling NaN to a quiet NaN. See
index 75024b683966123dc90d523f6bf413cc66668e7b..f5f1b40112331627697ef6f3b32e23ba285711f8 100644 (file)
@@ -57,6 +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.  */
+  __asm__ __volatile__ ("" : : : "memory");
+# endif
   /* On 32-bit x86 processors, as well as on x86_64 processors with
      CC="gcc -mfpmath=387", the evaluation of *x and *y above is done through
      an 'flds' instruction, which converts a signalling NaN to a quiet NaN. See