OSDN Git Service

2007-12-04 Tobias Burnus <burnus@net-b.de>
authorburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 4 Dec 2007 10:32:04 +0000 (10:32 +0000)
committerburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 4 Dec 2007 10:32:04 +0000 (10:32 +0000)
        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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@130600 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 05a5a6d..a457fa2 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 a81067c..af81c3a 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 8ec5307..6f7e2d9 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" } }