From: Tobias Burnus Date: Tue, 4 Dec 2007 10:32:04 +0000 (+0100) Subject: re PR fortran/34318 (Modules: Infinity/NaN parameters read as 0.0) X-Git-Tag: releases/gcc-4.3.0~1216 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c031ab9dfe19a2158c020ec810e5690d2b3ab90;p=thirdparty%2Fgcc.git re PR fortran/34318 (Modules: Infinity/NaN parameters read as 0.0) 2007-12-04 Tobias Burnus PR fortran/34318 * module.c (mio_gmp_real): Properly write NaN and Infinity. 2007-12-04 Tobias Burnus PR fortran/34318 * gfortran.dg/module_nan.f90: New. From-SVN: r130600 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 05a5a6d395b1..a457fa273bc6 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2007-12-04 Tobias Burnus + + PR fortran/34318 + * module.c (mio_gmp_real): Properly write NaN and Infinity. + 2007-12-02 Tobias Burnus PR fortran/34186 diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index a81067cf51d2..af81c3aee7cf 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -2535,6 +2535,14 @@ mio_gmp_real (mpfr_t *real) else { p = mpfr_get_str (NULL, &exponent, 16, 0, *real, GFC_RND_MODE); + + if (mpfr_nan_p (*real) || mpfr_inf_p (*real)) + { + write_atom (ATOM_STRING, p); + gfc_free (p); + return; + } + atom_string = gfc_getmem (strlen (p) + 20); sprintf (atom_string, "0.%s@%ld", p, exponent); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8ec5307f8e5f..6f7e2d929b6b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-12-04 Tobias Burnus + + PR fortran/34318 + * gfortran.dg/module_nan.f90: New. + 2007-12-04 Richard Sandiford * lib/target-supports.exp (get_compiler_messages): Replace with... diff --git a/gcc/testsuite/gfortran.dg/module_nan.f90 b/gcc/testsuite/gfortran.dg/module_nan.f90 new file mode 100644 index 000000000000..055880e5d62a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/module_nan.f90 @@ -0,0 +1,28 @@ +! { dg-do run } +! { dg-options "-fno-range-check" } +! +! PR fortran/34318 +! +! Infinity and NaN were not properly written to the .mod file. +! +module nonordinal + implicit none + real, parameter :: inf = 1./0., nan = 0./0., minf = -1./0.0 +end module nonordinal + +program a + use nonordinal + implicit none + character(len=20) :: str + if (log(abs(inf)) < huge(inf)) call abort() + if (log(abs(minf)) < huge(inf)) call abort() + if (.not. isnan(nan)) call abort() + write(str,*) inf + if (adjustl(str) /= "+Infinity") call abort() + write(str,*) minf + if (adjustl(str) /= "-Infinity") call abort() + write(str,*) nan + if (adjustl(str) /= "NaN") call abort() +end program a + +! { dg-final { cleanup-modules "nonordinal" } }