public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/29053]  New: Consecutive STREAM I/O file positions mixed up
@ 2006-09-13  2:33 jvdelisle at gcc dot gnu dot org
  2006-09-13  2:45 ` [Bug fortran/29053] " kargl at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2006-09-13  2:33 UTC (permalink / raw)
  To: gcc-bugs

With the following test case and no optimization, the dtp pointer is duplicated
resulting in the dtp-rec values getting mixed up during consecutive writes:

program avl
   implicit none
   real dt, t, a(10)
   integer i, place
   dt = 1.e-6
   a = real( (/ (i, i=1, 10) /) )
   open(unit=11, file='a.dat', access='stream')
   open(unit=12, file='b.dat', access='stream')
   do i = 1, 10
      t = i * dt
      write(11) t
      write(12) a
   end do
   close(11)
   close(12)
end program avl

Test case from Steve Kargl.  The end result should be a.dat file of length 40
and b.dat file of length 400.  The result is:

-rw-rw-r-- 1 jerry jerry  396 Sep 12 19:32 a.dat
-rw-rw-r-- 1 jerry jerry  436 Sep 12 19:32 b.dat

With -O1 this program works fine.

With gdb you can see the transfer calls given the same dtp pointer for both
files.


-- 
           Summary: Consecutive STREAM I/O file positions mixed up
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jvdelisle at gcc dot gnu dot org
  GCC host triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29053


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

* [Bug fortran/29053] Consecutive STREAM I/O file positions mixed up
  2006-09-13  2:33 [Bug fortran/29053] New: Consecutive STREAM I/O file positions mixed up jvdelisle at gcc dot gnu dot org
@ 2006-09-13  2:45 ` kargl at gcc dot gnu dot org
  2006-09-13  3:05 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu dot org @ 2006-09-13  2:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from kargl at gcc dot gnu dot org  2006-09-13 02:45 -------
It fails at all optimization levels on FreeBSD.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29053


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

* [Bug fortran/29053] Consecutive STREAM I/O file positions mixed up
  2006-09-13  2:33 [Bug fortran/29053] New: Consecutive STREAM I/O file positions mixed up jvdelisle at gcc dot gnu dot org
  2006-09-13  2:45 ` [Bug fortran/29053] " kargl at gcc dot gnu dot org
@ 2006-09-13  3:05 ` pinskia at gcc dot gnu dot org
  2006-09-14  1:21 ` jvdelisle at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-09-13  3:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-09-13 03:05 -------
(In reply to comment #1)
> It fails at all optimization levels on FreeBSD.
If a.dat and b.dat are still there, nothing changes in file size.  Make sure
you removed them before running the program.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29053


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

* [Bug fortran/29053] Consecutive STREAM I/O file positions mixed up
  2006-09-13  2:33 [Bug fortran/29053] New: Consecutive STREAM I/O file positions mixed up jvdelisle at gcc dot gnu dot org
  2006-09-13  2:45 ` [Bug fortran/29053] " kargl at gcc dot gnu dot org
  2006-09-13  3:05 ` pinskia at gcc dot gnu dot org
@ 2006-09-14  1:21 ` jvdelisle at gcc dot gnu dot org
  2006-09-15  3:00 ` patchapp at dberlin dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2006-09-14  1:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jvdelisle at gcc dot gnu dot org  2006-09-14 01:21 -------
Assembly output which does not work because it is using the same block of
memory for the st_parameter_dt structure for both WRITEs, the file position
pointer is in this structure, but not set before the calls because it is
suppose to be wherever it was left at.

        movl    $.LC1, -368(%ebp)
        movl    $13, -364(%ebp)
        movl    $11, -372(%ebp)
        movl    $0, -376(%ebp)
        leal    -376(%ebp), %eax
        movl    %eax, (%esp)
        call    _gfortran_st_write
snip

        movl    $.LC1, -368(%ebp)
        movl    $16, -364(%ebp)
        movl    $12, -372(%ebp)
        movl    $0, -376(%ebp)
        leal    -376(%ebp), %eax
        movl    %eax, (%esp)
        call    _gfortran_st_write

Assembly output with -O1 shows that in this case, two separate blocks of memory
are being used for the two separate st_parameter_dt structures.  In this case
the two writes are kept independent as they should be.

        movl    $.LC0, -324(%ebp)
        movl    $13, -320(%ebp)
        movl    $11, -328(%ebp)
        movl    $0, -332(%ebp)
        movl    %esi, -624(%ebp)
        movl    %esi, (%esp)
        call    _gfortran_st_write

snip

        movl    $.LC0, -600(%ebp)
        movl    $16, -596(%ebp)
        movl    $12, -604(%ebp)
        movl    $0, -608(%ebp)
        leal    -608(%ebp), %ebx
        movl    %ebx, (%esp)
        call    _gfortran_st_write

The STREAM I/O assumes that the dtp structure is global, static, and unique to
each unit.  Evidently this is not the case.  To fix this, we can allocate the
POS pointer for STREAM within the gfc_unit structure which is allocated at run
time when OPENed and will remain static and unique.

I will proceed with a patch to do this.


-- 

jvdelisle at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-09-14 01:21:46
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29053


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

* [Bug fortran/29053] Consecutive STREAM I/O file positions mixed up
  2006-09-13  2:33 [Bug fortran/29053] New: Consecutive STREAM I/O file positions mixed up jvdelisle at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2006-09-14  1:21 ` jvdelisle at gcc dot gnu dot org
@ 2006-09-15  3:00 ` patchapp at dberlin dot org
  2006-09-15 13:16 ` jvdelisle at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: patchapp at dberlin dot org @ 2006-09-15  3:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from patchapp at dberlin dot org  2006-09-15 03:00 -------
Subject: Bug number PR29053

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
http://gcc.gnu.org/ml/gcc-patches/2006-09/msg00571.html


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29053


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

* [Bug fortran/29053] Consecutive STREAM I/O file positions mixed up
  2006-09-13  2:33 [Bug fortran/29053] New: Consecutive STREAM I/O file positions mixed up jvdelisle at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2006-09-15  3:00 ` patchapp at dberlin dot org
@ 2006-09-15 13:16 ` jvdelisle at gcc dot gnu dot org
  2006-09-15 13:32 ` jvdelisle at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2006-09-15 13:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jvdelisle at gcc dot gnu dot org  2006-09-15 13:16 -------
Subject: Bug 29053

Author: jvdelisle
Date: Fri Sep 15 13:16:15 2006
New Revision: 116970

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116970
Log:
2006-09-14  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

        PR libgfortran/29053
        * io.h (gfc_unit): Add variable, strm_pos, to track
        STREAM I/O file position.
        * file_pos.c (st_rewind): Set strm_pos to beginning.
        * open.c (new_unit): Initialize strm_pos.
        * read.c (read_x): Bump strm_pos.
        * inquire.c (inquire_via_unit): Return strm_pos value.
        * transfer.c (read_block),(read_block_direct),(write_block)
        (write_buf): Seek to strm_pos - 1.  Update strm_pos when done.
        (pre_position): Initialize strm_pos.
        (data_transfer_init): Set strm_pos if DT_HAS_REC.
        (finalize_transfer): Flush file, no need to update strm_pos.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/file_pos.c
    trunk/libgfortran/io/inquire.c
    trunk/libgfortran/io/io.h
    trunk/libgfortran/io/open.c
    trunk/libgfortran/io/read.c
    trunk/libgfortran/io/transfer.c


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29053


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

* [Bug fortran/29053] Consecutive STREAM I/O file positions mixed up
  2006-09-13  2:33 [Bug fortran/29053] New: Consecutive STREAM I/O file positions mixed up jvdelisle at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2006-09-15 13:16 ` jvdelisle at gcc dot gnu dot org
@ 2006-09-15 13:32 ` jvdelisle at gcc dot gnu dot org
  2006-09-15 13:33 ` jvdelisle at gcc dot gnu dot org
  2006-09-15 13:35 ` jvdelisle at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2006-09-15 13:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jvdelisle at gcc dot gnu dot org  2006-09-15 13:32 -------
Subject: Bug 29053

Author: jvdelisle
Date: Fri Sep 15 13:32:12 2006
New Revision: 116971

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116971
Log:
2006-09-15  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

        PR libgfortran/29053
        * gfortran.dg/streamio_9.f90: New test.
        * gfortran.dg/streamio_10.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/streamio_10.f90
    trunk/gcc/testsuite/gfortran.dg/streamio_9.f90
Modified:
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29053


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

* [Bug fortran/29053] Consecutive STREAM I/O file positions mixed up
  2006-09-13  2:33 [Bug fortran/29053] New: Consecutive STREAM I/O file positions mixed up jvdelisle at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2006-09-15 13:32 ` jvdelisle at gcc dot gnu dot org
@ 2006-09-15 13:33 ` jvdelisle at gcc dot gnu dot org
  2006-09-15 13:35 ` jvdelisle at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2006-09-15 13:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jvdelisle at gcc dot gnu dot org  2006-09-15 13:33 -------
Fixed on 4.2, will not go to 4.1.


-- 

jvdelisle at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29053


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

* [Bug fortran/29053] Consecutive STREAM I/O file positions mixed up
  2006-09-13  2:33 [Bug fortran/29053] New: Consecutive STREAM I/O file positions mixed up jvdelisle at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2006-09-15 13:33 ` jvdelisle at gcc dot gnu dot org
@ 2006-09-15 13:35 ` jvdelisle at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2006-09-15 13:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jvdelisle at gcc dot gnu dot org  2006-09-15 13:35 -------
*** Bug 28747 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29053


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

end of thread, other threads:[~2006-09-15 13:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-13  2:33 [Bug fortran/29053] New: Consecutive STREAM I/O file positions mixed up jvdelisle at gcc dot gnu dot org
2006-09-13  2:45 ` [Bug fortran/29053] " kargl at gcc dot gnu dot org
2006-09-13  3:05 ` pinskia at gcc dot gnu dot org
2006-09-14  1:21 ` jvdelisle at gcc dot gnu dot org
2006-09-15  3:00 ` patchapp at dberlin dot org
2006-09-15 13:16 ` jvdelisle at gcc dot gnu dot org
2006-09-15 13:32 ` jvdelisle at gcc dot gnu dot org
2006-09-15 13:33 ` jvdelisle at gcc dot gnu dot org
2006-09-15 13:35 ` jvdelisle at gcc dot gnu dot org

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