This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR34318 - Properly write NaN and INF to the .mod file


:ADDPATCH fortran:

gfortran did not properly write parameters with the value NaN or
Infinity to the module file *.mod and thus the used parameters were read
as "0.0" instead of as NaN or INF.

Build and regression tested on x86-64.
OK for the trunk?

Tobias
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.

Index: gcc/fortran/module.c
===================================================================
--- gcc/fortran/module.c	(Revision 130598)
+++ gcc/fortran/module.c	(Arbeitskopie)
@@ -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: gcc/testsuite/gfortran.dg/module_nan.f90
===================================================================
--- gcc/testsuite/gfortran.dg/module_nan.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/module_nan.f90	(Revision 0)
@@ -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 except
+  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" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]