From e1e42f46d41317fec807e29194dd1570699fbe5c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 9 Apr 2024 14:17:38 +0200 Subject: [PATCH] totalorder, totalorderf: Avoid miscompilation by clang on OpenBSD/i386. * lib/totalorder.c (totalorder): Insert a compiler optimization barrier. * lib/totalorderf.c (totalorderf): Likewise. --- ChangeLog | 6 ++++++ lib/totalorder.c | 5 +++++ lib/totalorderf.c | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index b05ef3fe84..c258cdfb3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-04-09 Bruno Haible + + 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 totalorder, totalorderf: Fix handling of SNaN on i386 and x86_64 CPUs. diff --git a/lib/totalorder.c b/lib/totalorder.c index 635e3cb276..eaef9a582d 100644 --- a/lib/totalorder.c +++ b/lib/totalorder.c @@ -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 diff --git a/lib/totalorderf.c b/lib/totalorderf.c index 75024b6839..f5f1b40112 100644 --- a/lib/totalorderf.c +++ b/lib/totalorderf.c @@ -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 -- 2.39.5