[multiple changes]
authorPaul Thomas <pault@gcc.gnu.org>
Wed, 13 Jul 2005 18:43:14 +0000 (18:43 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Wed, 13 Jul 2005 18:43:14 +0000 (18:43 +0000)
2005-07-13 Paul Thomas  <pault@gcc.gnu.org>

* io/read.c (read_complex): Prevent X formatting during reads
from going beyond EOR to fix NIST fm908.FOR failure.
* io/list_read.c (read_complex): Allow complex data in list-
directed reads to have eols either side of the comma to
fix NIST FM906.FOR failure.

2005-07-13  Paul Thomas  <pault@gcc.gnu.org>

* gfortran.dg/past_eor.f90: New.
* gfortran.dg/complex_read.f90: New.

From-SVN: r101984

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/complex_read.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/past_eor.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/io/list_read.c
libgfortran/io/read.c

index 3f187ae65b23f4fd25f0fba9734c5b1f9a52f103..9b30550462891693d6874b5823137ba553eba36c 100644 (file)
@@ -1,9 +1,7 @@
-2005-07-13  Jeff Law  <law@redhat.com>
+2005-07-13  Paul Thomas  <pault@gcc.gnu.org>
 
-       * gcc.dg/tree-ssa/pr22051-2.c: Tweak expected output to allow
-       additional casts.
-
-       * gcc.dg/tree-ssa/pr22321.c: New test
+       * gfortran.dg/past_eor.f90: New.
+       * gfortran.dg/complex_read.f90: New.
 
 2005-07-13  Paolo Bonzini  <bonzini@gnu.org>
 
diff --git a/gcc/testsuite/gfortran.dg/complex_read.f90 b/gcc/testsuite/gfortran.dg/complex_read.f90
new file mode 100644 (file)
index 0000000..c12b66c
--- /dev/null
@@ -0,0 +1,58 @@
+! { dg-do run }
+! Test of the fix to the bug in NIST fm906.for.
+! Contributed by Paul Thomas  <pault@gcc.gnu.org>
+!
+program complex_read
+  complex            ::  a
+  open (10, status="scratch")
+
+! Test that we have not broken the one line form.
+
+  write (10, *) " ( 0.99  ,  9.9  )"
+  rewind (10)
+  read (10,*) a
+  if (a.ne.(0.99, 9.90)) call abort ()
+
+! Test a new record after the.comma (the original bug).
+
+  rewind (10)
+  write (10, *) " ( 99.0   ,"
+  write (10, *) "   999.0  )"
+  rewind (10)
+  read (10,*) a
+  if (a.ne.(99.0, 999.0)) call abort ()
+
+! Test a new record before the.comma 
+
+  rewind (10)
+  write (10, *) " ( 0.99  "
+  write (10, *) " , 9.9  )"
+  rewind (10)
+  read (10,*) a
+  if (a.ne.(0.99, 9.90)) call abort ()
+
+! Test a new records before and after the.comma 
+
+  rewind (10)
+  write (10, *) " ( 99.0   "
+  write (10, *) ",         "
+  write (10, *) "  999.0  )"
+  rewind (10)
+  read (10,*) a
+  if (a.ne.(99.0, 999.0)) call abort ()
+
+! Test a new records and blank records before and after the.comma 
+
+  rewind (10)
+  write (10, *) " ( 0.99   "
+  write (10, *) "          "
+  write (10, *) ",         "
+  write (10, *) "          "
+  write (10, *) "  9.9    )"
+  rewind (10)
+  read (10,*) a
+  if (a.ne.(0.99, 9.9)) call abort ()
+
+  close (10)
+end program complex_read
+
diff --git a/gcc/testsuite/gfortran.dg/past_eor.f90 b/gcc/testsuite/gfortran.dg/past_eor.f90
new file mode 100644 (file)
index 0000000..e89ed22
--- /dev/null
@@ -0,0 +1,22 @@
+! { dg-do run }
+! Test of the fix to the bug triggered by NIST fm908.for.
+! Contributed by Paul Thomas  <pault@gcc.gnu.org>
+!
+program past_eor
+  character(len=82)         ::  buffer
+  real                      ::  a(2), b(2), c(2), d(2), e(2)
+
+  e = (/2.34,2.456/)
+
+! tests 28-31 from fm908.for
+
+  buffer = '  2.34 ,  2.456     2.34 ,  2.456     0.234E01,  2.456E00&
+ &   0.234E+001, 2.456E-000'
+
+  READ (UNIT=buffer,FMT=10) a, b, c, d
+10 FORMAT (2(2(G7.5,1X),2X),2(G10.4E2,1X),1X,2(G11.7E4,1X))
+
+  if (any (a.ne.e).or.any (b.ne.e).or.any (c.ne.e).or.any (d.ne.e)) call abort ()
+
+end program past_eor
+
index 093043d7108a0714d16f43e91b3fec6e6a9323bd..25f55c7398a13c4f68d57979ebd99b0dfd56be7a 100644 (file)
@@ -1,3 +1,11 @@
+2005-07-13 Paul Thomas  <pault@gcc.gnu.org>
+
+       * io/read.c (read_complex): Prevent X formatting during reads
+       from going beyond EOR to fix NIST fm908.FOR failure.
+       * io/list_read.c (read_complex): Allow complex data in list-
+       directed reads to have eols either side of the comma to
+       fix NIST FM906.FOR failure.
+
 2005-07-12  Thomas Koenig  <Thomas.Koenig@online.de>
 
        PR libfortran/21593
index 3d62d8c845ec90d3cf746c1adcf396758deba777..df99e7858a7581abedfe206c5f1955e804ced2a3 100644 (file)
@@ -984,11 +984,25 @@ read_complex (int length)
   if (parse_real (value, length))
     return;
 
+eol_1:
   eat_spaces ();
+  c = next_char ();
+  if (c == '\n' || c== '\r')
+    goto eol_1;
+  else
+    unget_char (c);
+
   if (next_char () != ',')
     goto bad_complex;
 
+eol_2:
   eat_spaces ();
+  c = next_char ();
+  if (c == '\n' || c== '\r')
+    goto eol_2;
+  else
+    unget_char (c);
+
   if (parse_real (value + length, length))
     return;
 
index 101652ca8dcdfce0bcd48697dbc89be3766d699f..4cfad8d7785ef2db1f703ba76745b774297bee6f 100644 (file)
@@ -784,8 +784,12 @@ read_f (fnode * f, char *dest, int length)
 void
 read_x (fnode * f)
 {
-  int n;
+  int n, m;
 
   n = f->u.n;
-  read_block (&n);
+  m = (int)current_unit->bytes_left;
+  if (f->format == FMT_X)
+    n = (n > m) ? m : n;
+  if (n)
+    read_block (&n);
 }