public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, fortran] PR80741 [Regression 7/8] DTIO wrong code causes incorrect behaviour of namelist READ
@ 2017-05-17  5:35 Jerry DeLisle
  2017-05-17 18:44 ` Paul Richard Thomas
  0 siblings, 1 reply; 2+ messages in thread
From: Jerry DeLisle @ 2017-05-17  5:35 UTC (permalink / raw)
  To: fortran; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]

Hi all,

When I first looked at this I thought the minor front end bobble was the 
problem. That turns out to be unrelated but needed to be fixed in trans-io.c

The actual problem was that when I moved the last_char to the unit structure, 
needed for DTIO, the value saved there persists across I/O operations so in the 
case of the PR the REWIND was was working but the EOF character from the 
preceding read was passed on.

I conservatively have reset the last_char in several places out of concern for 
missing a code path on this.

Regression tested on x86_64.  New test case attached.

OK for trunk and then back port to 7 in about a week?

Regards,

Jerry

2017-05-16  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/80741
	* trans-io.c (transfer_namelist_element): Change check from
	NULL_TREE to null_pointer_node.

2017-05-16  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/80741
	* transfer.c (finalize_transfer): Reset last_char to 'empty'.
	* file_pos.c (formatted_backspace): Likewise.
	(st_endfile): Likewise.
	(st_rewind): Likewise.
	(st_flush): Likewise.

[-- Attachment #2: pr80741.diff --]
[-- Type: text/x-patch, Size: 2136 bytes --]

diff --git a/gcc/fortran/trans-io.c b/gcc/fortran/trans-io.c
index 1b70136f..c557c114 100644
--- a/gcc/fortran/trans-io.c
+++ b/gcc/fortran/trans-io.c
@@ -1756,7 +1756,7 @@ transfer_namelist_element (stmtblock_t * block, const char * var_name,
   else
     tmp = build_int_cst (gfc_charlen_type_node, 0);
 
-  if (dtio_proc == NULL_TREE)
+  if (dtio_proc == null_pointer_node)
     tmp = build_call_expr_loc (input_location,
 			   iocall[IOCALL_SET_NML_VAL], 6,
 			   dt_parm_addr, addr_expr, string,
diff --git a/libgfortran/io/file_pos.c b/libgfortran/io/file_pos.c
index 5af9619b..771d548e 100644
--- a/libgfortran/io/file_pos.c
+++ b/libgfortran/io/file_pos.c
@@ -82,7 +82,7 @@ formatted_backspace (st_parameter_filepos *fpp, gfc_unit *u)
     goto io_error;
   u->last_record--;
   u->endfile = NO_ENDFILE;
-
+  u->last_char = EOF - 1;
   return;
 
  io_error:
@@ -322,6 +322,7 @@ st_endfile (st_parameter_filepos *fpp)
 
       unit_truncate (u, stell (u->s), &fpp->common);
       u->endfile = AFTER_ENDFILE;
+      u->last_char = EOF - 1;
       if (0 == stell (u->s))
         u->flags.position = POSITION_REWIND;
     }
@@ -371,6 +372,7 @@ st_endfile (st_parameter_filepos *fpp)
 	  if (u == NULL)
 	    return;
 	  u->endfile = AFTER_ENDFILE;
+	  u->last_char = EOF - 1;
 	}
     }
 
@@ -430,6 +432,7 @@ st_rewind (st_parameter_filepos *fpp)
 	  u->current_record = 0;
 	  u->strm_pos = 1;
 	  u->read_bad = 0;
+	  u->last_char = EOF - 1;
 	}
       /* Update position for INQUIRE.  */
       u->flags.position = POSITION_REWIND;
@@ -458,6 +461,7 @@ st_flush (st_parameter_filepos *fpp)
         fbuf_flush (u, u->mode);
 
       sflush (u->s);
+      u->last_char = EOF - 1;
       unlock_unit (u);
     }
   else
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index 928a448f..298b29e8 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -3977,7 +3977,7 @@ finalize_transfer (st_parameter_dt *dtp)
       fbuf_seek (dtp->u.p.current_unit, 0, SEEK_END);
 
   dtp->u.p.current_unit->saved_pos = 0;
-
+  dtp->u.p.current_unit->last_char = EOF - 1;
   next_record (dtp, 1);
 
  done:

[-- Attachment #3: read_4.f90 --]
[-- Type: text/x-fortran, Size: 713 bytes --]

! { dg-do run }
! PR80741 wrong code causes incorrect behaviour of namelist READ
program p
  use, intrinsic :: iso_fortran_env, only: iostat_end
  implicit none
  integer :: x, y, ios, io
  character(10) :: line
  namelist /test/ x, y
  
  x = 10
  y = 10
  ios = 0
  io = 10
  open(unit=io, status='scratch')
  write(io, test)
  write(io, *) 'done'
  rewind(io)
  x = 0
  y = 0
  read(io, test)
  if (x.ne.10 .or. y.ne.10) call abort
  !
  read(io, *) line
  if (line.ne.'done') call abort
  !
  read(io, *, iostat=ios) line
  if (ios/=iostat_end) call abort
  rewind(io)
  x = 0
  y = 0
  read(io, test)
  if (x.ne.10 .or. y.ne.10) call abort
  read(io, *, iostat=ios) line
  if (line.ne.'done') call abort
end

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch, fortran] PR80741 [Regression 7/8] DTIO wrong code causes incorrect behaviour of namelist READ
  2017-05-17  5:35 [patch, fortran] PR80741 [Regression 7/8] DTIO wrong code causes incorrect behaviour of namelist READ Jerry DeLisle
@ 2017-05-17 18:44 ` Paul Richard Thomas
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Richard Thomas @ 2017-05-17 18:44 UTC (permalink / raw)
  To: Jerry DeLisle; +Cc: fortran, GCC Patches

Hi Jerry,

OK for trunk and for 7-branch after a delay.

Cheers and thanks

Paul

On 17 May 2017 at 06:34, Jerry DeLisle <jvdelisle@charter.net> wrote:
> Hi all,
>
> When I first looked at this I thought the minor front end bobble was the
> problem. That turns out to be unrelated but needed to be fixed in trans-io.c
>
> The actual problem was that when I moved the last_char to the unit
> structure, needed for DTIO, the value saved there persists across I/O
> operations so in the case of the PR the REWIND was was working but the EOF
> character from the preceding read was passed on.
>
> I conservatively have reset the last_char in several places out of concern
> for missing a code path on this.
>
> Regression tested on x86_64.  New test case attached.
>
> OK for trunk and then back port to 7 in about a week?
>
> Regards,
>
> Jerry
>
> 2017-05-16  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
>
>         PR fortran/80741
>         * trans-io.c (transfer_namelist_element): Change check from
>         NULL_TREE to null_pointer_node.
>
> 2017-05-16  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
>
>         PR libgfortran/80741
>         * transfer.c (finalize_transfer): Reset last_char to 'empty'.
>         * file_pos.c (formatted_backspace): Likewise.
>         (st_endfile): Likewise.
>         (st_rewind): Likewise.
>         (st_flush): Likewise.



-- 
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-17 18:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-17  5:35 [patch, fortran] PR80741 [Regression 7/8] DTIO wrong code causes incorrect behaviour of namelist READ Jerry DeLisle
2017-05-17 18:44 ` Paul Richard Thomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).