]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/34318 (Modules: Infinity/NaN parameters read as 0.0)
authorTobias Burnus <burnus@net-b.de>
Tue, 4 Dec 2007 10:32:04 +0000 (11:32 +0100)
committerTobias Burnus <burnus@gcc.gnu.org>
Tue, 4 Dec 2007 10:32:04 +0000 (11:32 +0100)
2007-12-04  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34318
        * module.c (mio_gmp_real): Properly write NaN and Infinity.

2007-12-04  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34318
        * gfortran.dg/module_nan.f90: New.

From-SVN: r130600

gcc/fortran/ChangeLog
gcc/fortran/module.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/module_nan.f90 [new file with mode: 0644]

index 05a5a6d395b162db65c50c85aea66b6bc3af2b47..a457fa273bc6eb9be0d427e832983086f18d7939 100644 (file)
@@ -1,3 +1,8 @@
+2007-12-04  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/34318
+       * module.c (mio_gmp_real): Properly write NaN and Infinity.
+
 2007-12-02  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/34186
index a81067cf51d219e34d1e44d3ec673ce168ad44ff..af81c3aee7cfd7ad38366b33a4f727e5793f5341 100644 (file)
@@ -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);
index 8ec5307f8e5f5d3b06a216dffc6af223f49b13fb..6f7e2d929b6b9e1cadc489ecddf5ef9e76f7a0e2 100644 (file)
@@ -1,3 +1,8 @@
+2007-12-04  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/34318
+       * gfortran.dg/module_nan.f90: New.
+
 2007-12-04  Richard Sandiford  <rsandifo@nildram.co.uk>
 
        * 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 (file)
index 0000000..055880e
--- /dev/null
@@ -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" } }