Patch for libgfortran; broken isnan/isfinite/fpclassify

FX Coudert fxcoudert@gmail.com
Mon Sep 26 20:58:00 GMT 2005


> 2005-09-23  Steve Ellcey  <sje@cup.hp.com>
> 
> 	* acinclude.m4 (LIBGFOR_CHECK_FOR_BROKEN_ISFINITE): New.
> 	(LIBGFOR_CHECK_FOR_BROKEN_ISNAN): New.
> 	(LIBGFOR_CHECK_FOR_BROKEN_FPCLASSIFY): New.
> 	* configure.ac (LIBGFOR_CHECK_FOR_BROKEN_ISFINITE): Add use.
> 	(LIBGFOR_CHECK_FOR_BROKEN_ISNAN): Add use.
> 	(LIBGFOR_CHECK_FOR_BROKEN_FPCLASSIFY): Add use.
> 	* libgfortan.h (isfinite): undef if broken, set if needed.
> 	(isnan): undef if broken, set if needed.
>         (fpclassify): undef if broken, set if needed.
> 	* io/write.c: Remove TODO comment about working isfinite.
> 	* intrinsics/c99_functions.c (round): Use isfinite instead
> 	of fpclassify.
> 	* intrinsics/c99_functions.c (roundf): Ditto.

OK provided you take care of the remarks below. I do not have cygwin at 
hand, so I can't check whether we can remove the __CYGWIN__ check, though.


> + dnl Check whether isfinite works.
> + dnl The most common problem is that it does not work on long doubles.
> + AC_DEFUN([LIBGFOR_CHECK_FOR_BROKEN_ISFINITE], [
> +   AC_CACHE_CHECK([whether isfinite works],
> +                   have_broken_isfinite, [

The problem is that your tests return true/yes if the macro is broken, 
while the message "whether isfinite works" indicates the contrary. I was 
quite surprised, during testing, to see (on x86_64-linux):

checking whether isfinite works... no
checking whether isnan works... no
checking whether fpclassify works... no

So maybe you should change that to "whether isfinite is broken"  ;-)


> + AC_DEFUN([LIBGFOR_CHECK_FOR_BROKEN_ISFINITE], [
> +   AC_CACHE_CHECK([whether isfinite works],
> +                   have_broken_isfinite, [
> +   libgfor_check_for_broken_isfinite_save_LIBS=$LIBS
> +   LIBS="$LIBS -lm"
> +   AC_TRY_RUN([

When using AC_TRY_RUN, you need to provide sensible defaults for 
cross-compilers. These can be have_broken_isfinite=no, 
have_broken_isnan=no, or still better, target-based. You can have a look 
at LIBGFOR_CHECK_UNLINK_OPEN_FILE and LIBGFOR_CHECK_CRLF for example: in 
both cases, the test was introduced to fix bugs known to occur on 
i386-mingw32, hence the target-based test for cross-compilers.


> +     long double x;
> +     x = 0/0;
> +     if (!isnan(x) return 1;

This was already commented on by rth.


> ! #if (defined(isfinite) && (defined(HAVE_BROKEN_ISFINITE) || defined(__CYGWIN__)))
>   #undef isfinite
> ! #endif
> ! 
> ! #if (defined(isnan) && defined(HAVE_BROKEN_ISNAN))
> ! #undef isnan
> ! #endif
> ! 
> ! #if (defined(fpclassify) && defined(HAVE_BROKEN_FPCLASSIFY))
> ! #undef fpclassify
> ! #endif

No need to check for defined(fpclassify), as Andrew Pinski told me about 
a recent patch.


FX



More information about the Gcc-patches mailing list