From aa45ef321f53e30ef62eb1869b2a0a041f7addaa Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 7 Nov 2023 00:59:02 +0100 Subject: [PATCH] nan: Work around clang's incorrect constant-folding on mips64. * lib/nan.h (NaNf, NaNd, NaNl): On mips platforms, avoid the compiler's constant-folding for 0.0f/0.0f, 0.0/0.0, 0.0L/0.0L. --- ChangeLog | 6 ++++++ lib/nan.h | 22 ++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index d065d20be5..1103289bae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-11-06 Bruno Haible + + nan: Work around clang's incorrect constant-folding on mips64. + * lib/nan.h (NaNf, NaNd, NaNl): On mips platforms, avoid the compiler's + constant-folding for 0.0f/0.0f, 0.0/0.0, 0.0L/0.0L. + 2023-11-06 Bruno Haible snan: Add more info for mips-based platforms. diff --git a/lib/nan.h b/lib/nan.h index 4cb56350f8..219b25aeac 100644 --- a/lib/nan.h +++ b/lib/nan.h @@ -29,10 +29,11 @@ /* The Compaq (ex-DEC) C 6.4 compiler and the Microsoft MSVC 9 compiler choke on the expression 0.0 / 0.0. The IBM XL C compiler on z/OS complains. - PGI 16.10 complains. */ + PGI 16.10 complains. clang 13 on mips64 does incorrect constant-folding. */ #if (defined __DECC || defined _MSC_VER \ - || (defined __MVS__ && defined __IBMC__) \ - || defined __PGI) + || (defined __MVS__ && defined __IBMC__) \ + || defined __PGI \ + || defined __mips__) static float NaNf () { @@ -48,10 +49,11 @@ NaNf () /* The Compaq (ex-DEC) C 6.4 compiler and the Microsoft MSVC 9 compiler choke on the expression 0.0 / 0.0. The IBM XL C compiler on z/OS complains. - PGI 16.10 complains. */ + PGI 16.10 complains. clang 13 on mips64 does incorrect constant-folding. */ #if (defined __DECC || defined _MSC_VER \ - || (defined __MVS__ && defined __IBMC__) \ - || defined __PGI) + || (defined __MVS__ && defined __IBMC__) \ + || defined __PGI \ + || defined __mips__) static double NaNd () { @@ -69,14 +71,18 @@ NaNd () runtime type conversion. The Microsoft MSVC 9 compiler chokes on the expression 0.0L / 0.0L. The IBM XL C compiler on z/OS complains. - PGI 16.10 complains. */ + PGI 16.10 complains. + Avoid possible incorrect constant-folding on mips. */ #ifdef __sgi static long double NaNl () { double zero = 0.0; return zero / zero; } -#elif defined _MSC_VER || (defined __MVS__ && defined __IBMC__) || defined __PGI +#elif (defined _MSC_VER \ + || (defined __MVS__ && defined __IBMC__) \ + || defined __PGI \ + || defined __mips__) static long double NaNl () { -- 2.39.5