From: Bruno Haible Date: Tue, 9 Apr 2024 15:47:01 +0000 (+0200) Subject: totalorder, totalorderf: Avoid miscompilation by gcc on NetBSD/i386. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=3265f57283ae2909f275005b84ca14e802f52e51;p=gnulib.git 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/ChangeLog b/ChangeLog index f946a276f3..cbe1bad843 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-04-09 Bruno Haible + + 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. + 2024-04-09 Bruno Haible totalorder, totalorderf: Avoid miscompilation by clang on OpenBSD/i386. 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 + 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 + 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