Bug 34565 - internal write to string array fails
Summary: internal write to string array fails
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P4 normal
Target Milestone: ---
Assignee: Thomas Koenig
URL: http://gcc.gnu.org/ml/fortran/2008-01...
Keywords: patch, wrong-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-12-23 11:38 UTC by Tobias Burnus
Modified: 2008-01-03 19:53 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-12-27 15:07:39


Attachments
partial patch (733 bytes, patch)
2007-12-28 13:16 UTC, Thomas Koenig
Details | Diff
patch (1.83 KB, patch)
2007-12-31 11:50 UTC, Thomas Koenig
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-12-23 11:38:04 UTC
More bugs found via the test suite

Gfortran 4.1, 4.2 and 4.3 show the run-time error:
    Fortran runtime error: End of file

implicit none
integer :: i
character(len=6) :: c (5) = ""
write (c (5:1:-2), "(I2,I2,I2)") 5,3,1
if (any(c(1:4) /= "")) stop 'ERROR 1'
if (c(5) /= " 5 3 1") stop 'ERROR 2'
do i = 1, 5
  print '(i0,3a)', i, '"',c(i),'"'
end do
end
Comment 1 Jerry DeLisle 2007-12-23 17:03:44 UTC
I can confirm this one.  Its been a long time since I looked at this.  I seem to recall at one point we had not implemented negative strides for internal units.  Part of the discussion was that it was so obscure we probably did not need to bother with it.  So it was put on back burner.  I think we should lower the priority on this one.
Comment 2 Thomas Koenig 2007-12-27 15:07:39 UTC
With the new transfer_array functions, this
should be fairly easy to do.

I'll take a shot at this.
Comment 3 Thomas Koenig 2007-12-27 15:36:35 UTC
Reduce test case:

$ cat end-2.f90
program main
  implicit none
  character(len=6) :: c (2) = ""
  write (c (2:1:-1), "(I2)") 5
end program main
$ gfortran end-2.f90
$ ./a.out
At line 4 of file end-2.f90
Fortran runtime error: End of file
Comment 4 Jerry DeLisle 2007-12-28 01:00:44 UTC
The relevant code is in transfer.c (next_array_record).  You will see the TODO in the comment.  The array descriptor should be coming in fine to the library so this  function just needs to be updated some.

Enjoy!
Comment 5 Thomas Koenig 2007-12-28 13:16:39 UTC
Created attachment 14837 [details]
partial patch

The attached patch will let the test case from comment #3
succeed, but not the original test case.
Comment 6 Jerry DeLisle 2007-12-28 15:39:03 UTC
See in next_array_record where we do not handle negative step size other than -1
Comment 7 Thomas Koenig 2007-12-31 11:50:35 UTC
Created attachment 14847 [details]
patch

Well, here's something that at least passes
for the simple test cases.  As you can see from
the number on the diff, this took some trying...

Testing, more test cases etc. in the new year.
Comment 8 Thomas Koenig 2008-01-03 19:50:52 UTC
Subject: Bug 34565

Author: tkoenig
Date: Thu Jan  3 19:49:38 2008
New Revision: 131305

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131305
Log:
2008-01-03  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR libfortran/34565
	* io/io.h:  Adjust protoypes for open_internal(),
	next_array_record() and init_loop_spec().
	* io/list_read.c (next_char):  Use argument "finished"
	of next_array_record to check for end on internal file.
	* io/unit.c:  Calculate the offset for an array
	internal file and supply this informatin to open_internal().
	* io/unix.c (open_internal):  Set the offset for the internal
	file on open.
	* io/transfer.c (init_loop_spec):  Calculate the starting
	record in case of negative strides.  Return size of 0 for
	an empty array.
	(next_array_record):  Use an extra flag to signal that the
	array is finished.
	(next_record_r):  Use the new flag to next_array_record().
	(next_record_w):  Likewise.

2008-01-03  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR libfortran/34565
	* gfortran.dg/internal_readwrite_1.f90:  New test.
	* gfortran.dg/internal_readwrite_2.f90:  New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/internal_readwrite_1.f90
    trunk/gcc/testsuite/gfortran.dg/internal_readwrite_2.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/io.h
    trunk/libgfortran/io/list_read.c
    trunk/libgfortran/io/transfer.c
    trunk/libgfortran/io/unit.c
    trunk/libgfortran/io/unix.c

Comment 9 Thomas Koenig 2008-01-03 19:53:01 UTC
Fixed on trunk.

Closing.