Since the quiet NaN and signalling NaN representation on mips depends on the
CPU model, it can be expected that a compiler guesses it wrong. This means:

  - The compiler's constant-folding of 0.0f/0.0f, 0.0/0.0, 0.0L/0.0L
    produces a signalling NaN instead of quiet NaN. (This is the case on
    OpenBSD 7.4/mips64.)

  - The compiler's __builtin_nan{f,l} functions may produce a wrong result as
    well (like they do now on sh4:
    <https://gcc.gnu.org/bugzilla//show_bug.cgi?id=111814>).


2023-11-06  Bruno Haible  <br...@clisp.org>

        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.

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 ()
 {




Reply via email to