Fix math/test-misc.c for undefined fenv.h macros [committed]

Message ID alpine.DEB.2.20.1808012222350.32216@digraph.polyomino.org.uk
State Committed
Headers

Commit Message

Joseph Myers Aug. 1, 2018, 10:23 p.m. UTC
  math/test-misc.c contains some code that uses fenv.h macros
FE_UNDERFLOW, FE_OVERFLOW and FE_UPWARD without being conditional on
those macros being defined.

That would normally break the build for configurations (typically
soft-float) not defining those macros.  However, the code in question
is inside LDBL_MANT_DIG > DBL_MANT_DIG conditionals.  And, while we
have configurations lacking rounding mode and exception support where
LDBL_MANT_DIG > DBL_MANT_DIG (soft-float MIPS64 and RISC-V), those
configurations currently define the fenv.h macros in question even for
soft-float.

There may be some case for defining those macros in cases where a
soft-float compilation could use a hard-float libm (where both
soft-float and hard-float can use the same ABI, as on ARM and RISC-V,
for example).  But MIPS is not such a case - the hard-float and
soft-float ABIs are incompatible - and thus I am testing a patch to
stop defining those macros for soft-float MIPS (motivated by reducing
the extent to which architectures need their own definitions of
math-tests.h macros - if lack of rounding mode / exception support can
be determined by the lack of macros in fenv.h, that avoids the need
for math-tests.h to declare that lack as well).  Introducing a case of
LDBL_MANT_DIG > DBL_MANT_DIG without these macros defined shows up the
problem with math/test-misc.c.  This patch then fixes that problem by
adding appropriate conditionals.

Tested for MIPS64 in conjunction with changes to stop defining the
macros in question in bits/fenv.h for soft-float.  Committed.

2018-08-01  Joseph Myers  <joseph@codesourcery.com>

	* math/test-misc.c (do_test) [LDBL_MANT_DIG > DBL_MANT_DIG]: Make
	code using FE_UNDERFLOW conditional on [FE_UNDERFLOW], code using
	FE_OVERFLOW conditional on [FE_OVERFLOW] and code using FE_UPWARD
	conditional on [FE_UPWARD].
  

Patch

diff --git a/math/test-misc.c b/math/test-misc.c
index c5cfb34..963e1e7 100644
--- a/math/test-misc.c
+++ b/math/test-misc.c
@@ -976,11 +976,13 @@  do_test (void)
 	puts ("scalbl (LDBL_MIN, 2147483647) returns -Inf");
 	result = 1;
       }
+# ifdef FE_UNDERFLOW
     else if (fetestexcept (FE_UNDERFLOW))
       {
 	puts ("scalbl (LDBL_MIN, 2147483647) raises underflow exception");
 	result = 1;
       }
+# endif
 
     feclearexcept (FE_ALL_EXCEPT);
     r = scalbl (LDBL_MAX, -2147483647);
@@ -994,11 +996,13 @@  do_test (void)
 	puts ("scalbl (LDBL_MAX, -2147483647) returns -Inf");
 	result = 1;
       }
+# ifdef FE_OVERFLOW
     else if (fetestexcept (FE_OVERFLOW))
       {
 	puts ("scalbl (LDBL_MAX, -2147483647) raises overflow exception");
 	result = 1;
       }
+# endif
   }
 #endif
 
@@ -1178,6 +1182,7 @@  do_test (void)
 	}
     }
 
+#  ifdef FE_UPWARD
   volatile long double ld7 = nextafterl (0.0L, 1.0L);
   volatile double d7;
   (void) &ld7;
@@ -1195,6 +1200,7 @@  do_test (void)
       else
 	puts ("ignoring this failure");
     }
+#  endif
 # endif
 #endif