re PR libfortran/78123 (Short reads with T edit descriptor not padding correctly)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 30 Oct 2016 22:14:01 +0000 (22:14 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 30 Oct 2016 22:14:01 +0000 (22:14 +0000)
2016-10-30  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR fortran/78123
* io/transfer.c (formatted_transfer_scalar_read): Clear seen_eor
only if we have tabbed to left of current position.

* gfortran.dg/fmt_t_9.f: New test.

From-SVN: r241691

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/fmt_t_9.f [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/io/transfer.c

index d65ebb4a8cef3afa8018bdf69703f1d2218d3906..c8d3650c41ca94dbbbae8b48d75ac7d903da41c5 100644 (file)
@@ -1,3 +1,8 @@
+2016-10-30  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR fortran/78123
+       * gfortran.dg/fmt_t_9.f: New test.
+
 2016-10-30  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/67219
diff --git a/gcc/testsuite/gfortran.dg/fmt_t_9.f b/gcc/testsuite/gfortran.dg/fmt_t_9.f
new file mode 100644 (file)
index 0000000..bfe0361
--- /dev/null
@@ -0,0 +1,41 @@
+! { dg-options "-ffixed-line-length-none -std=gnu" }
+! { dg-do run }
+! PR78123 Short reads with T edit descriptor not padding correctly
+      PROGRAM tformat
+C
+      INTEGER  MXFLTL
+      PARAMETER (MXFLTL = 99999)
+      INTEGER   IFLGHT, NFLCYC, IFLTSQ(MXFLTL), IDXBLK, LMAX, LMIN, I
+C
+      OPEN(29, status='scratch')
+      WRITE(29, '(a)') "   1   1   1  TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT      72  122     4"
+      WRITE(29, '(a)') ""
+      WRITE(29, '(a)') "  451   402012011201120112011200120112011201120112011201120111971201120112011201120112011201"
+      WRITE(29, '(a)') "  451   4020 866 866 866 866 866 866 866 866 865 866 865 866 866 866 866 866 866 866 865 866"
+      REWIND(29)
+C     The error occurs in the following loop:
+ 10   CONTINUE
+         READ(29,1010   )  IDXBLK, LMAX, LMIN
+1010     FORMAT(8X,I4,T51,2I5) ! wrong if this format is used
+c         write(6,fmt='("IDXBLK,LMAX,LMIN=",3I5)')IDXBLK,LMAX,LMIN
+         IF (IDXBLK .EQ. 0)  GO TO 20
+      GO TO 10
+C
+ 20   CONTINUE
+      READ(29,1040,END=100)  IFLGHT, NFLCYC,
+     &              (IFLTSQ(I), I=1,NFLCYC)
+1040  FORMAT(I5,I5,2X,(T13,20I4))
+c      write(6,fmt='(2i6)') IFLGHT,NFLCYC
+c      write(6,fmt='(20I4)') (IFLTSQ(I), I=1,NFLCYC)
+c      write(6,*) "Program is correct"
+      close(29)
+      if (IFLGHT.ne.451) call abort
+      if (NFLCYC.ne.40) call abort
+      stop
+C
+ 100  CONTINUE
+C      write(6,*) "End of file encountered (wrong)"
+      close (29)
+      call abort
+      STOP
+      END
index 107372340ed13103530d0dc05cf6ea96e10c74d5..78d3949240b600a866a4591cf65a106b822515c7 100644 (file)
@@ -1,3 +1,9 @@
+2016-10-30  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR fortran/78123
+       * io/transfer.c (formatted_transfer_scalar_read): Clear seen_eor
+       only if we have tabbed to left of current position.
+
 2016-10-26  Fritz Reese  <fritzoreese@gmail.com>
 
        * libgfortran.h (IOPARM_OPEN_HAS_READONLY, IOPARM_OPEN_HAS_SHARE,
index b8eb5eda20f6c249014c627dac5b67769d04bd4f..583036292f98d12dd30139d5105e474359b76090 100644 (file)
@@ -1579,7 +1579,8 @@ formatted_transfer_scalar_read (st_parameter_dt *dtp, bt type, void *p, int kind
               dtp->u.p.current_unit->bytes_left -= dtp->u.p.sf_seen_eor;
               dtp->u.p.skips -= dtp->u.p.sf_seen_eor;
              bytes_used = pos;
-             dtp->u.p.sf_seen_eor = 0;
+             if (dtp->u.p.pending_spaces == 0)
+               dtp->u.p.sf_seen_eor = 0;
            }
          if (dtp->u.p.skips < 0)
            {