public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31618]  New: backspace intrinsic is not working on an unformatted file
@ 2007-04-18 10:27 Patrick dot Begou at hmg dot inpg dot fr
  2007-04-18 14:01 ` [Bug fortran/31618] " jvdelisle at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Patrick dot Begou at hmg dot inpg dot fr @ 2007-04-18 10:27 UTC (permalink / raw)
  To: gcc-bugs

Using backspace when reading an unformatted file after a read error does not
work except if it is on the first record.

The code below show the problem. This code write 3 couples of integer values in
an unformatted file called 'foo' and close it.
File is reopen for read.
Then it reads the first couple of values. It's OK.
Then it try to read 3 values and detects the error (only 2 values in the
record).
The code use backspace to go back at the begining of this record and try to
read again this record, but with only 2 values.
The values obtained are wrong.

Trying to read 3 values at the begining of the file, using backspace and
reading again only 2 values works. 

Code:

      PROGRAM gfort
      IMPLICIT NONE

      INTEGER :: x, z, count
      INTEGER :: nx, nz,LocalTimeStep 


      OPEN (21,FILE='foo',form='UNFORMATTED',err=101)
      REWIND(21)
      x=140
      z=170
      WRITE(21) x,z
      WRITE(6,*)'writing x (',x,') and z(',z,') in foo'
      x=14
      z=17
      WRITE(21) x,z
      WRITE(6,*)'writing x (',x,') and z(',z,') in foo'
      x=1400
      z=1700
      WRITE(21) x,z
      WRITE(6,*)'writing x (',x,') and z(',z,') in foo'
      CLOSE(21)


      OPEN (21,FILE='foo',form='UNFORMATTED',status='OLD',err=101)
      REWIND(21)
      WRITE(6,*)'reading first x, z in foo'
      x=-1
      z=-1
      READ(21,err=103,end=103) x,z
      WRITE(6,*)'x (',x,') and z(',z,')'

      WRITE(6,*)'reading x, z and LocalTimeStep in foo'
      nx=-1
      nz=-1
      READ(21,iostat=count) nx,nz,LocalTimeStep
      WRITE(6,*)'x (',nx,') and z(',nz,') and LocalTimeStep(',
     + LocalTimeStep,')'
         IF (count.NE.0) THEN
            WRITE(6,*)'reading again x and z in foo'
            BACKSPACE(21)
            nx=-1
            nz=-1
            READ(21,err=103,end=103) nx,nz
            LocalTimeStep=0.0
      WRITE(6,*)'x (',nx,') and z(',nz,') and LocalTimeStep(',
     + LocalTimeStep,')'
         ENDIF
      CLOSE(21)
      STOP 'OK'

101   WRITE(6,*) 'foo n''a pas ete trouve.'
      STOP 'FAILED'
103   WRITE(6,*) 'Erreur de lecture'
      CLOSE(21)
      STOP 'FAILED'
      END PROGRAM gfort



NORMAL RESULT:
 ./a.out
 writing x (         140 ) and z(         170 ) in foo
 writing x (          14 ) and z(          17 ) in foo
 writing x (        1400 ) and z(        1700 ) in foo
 reading first x, z in foo
 x (         140 ) and z(         170 )
 reading x, z and LocalTimeStep in foo
 x (          14 ) and z(          17 ) and LocalTimeStep(           0 )
 reading again x and z in foo
 x (          14 ) and z(          17 ) and LocalTimeStep(           0 )
OK

Gfortran RESULT (WRONG) :
./a.out
 writing x (         140 ) and z(         170 ) in foo
 writing x (          14 ) and z(          17 ) in foo
 writing x (        1400 ) and z(        1700 ) in foo
 reading first x, z in foo
 x (         140 ) and z(         170 )
 reading x, z and LocalTimeStep in foo
 x (          14 ) and z(          17 ) and LocalTimeStep(          17 )
 reading again x and z in foo
 x (          17 ) and z(           8 ) and LocalTimeStep(           0 )
STOP OK


-- 
           Summary: backspace intrinsic is not working on an unformatted
                    file
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Patrick dot Begou at hmg dot inpg dot fr
 GCC build triplet: gcc version 4.3.0 20070418 (experimental)
GCC target triplet: i386-pc-linux-gnu


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


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

* [Bug fortran/31618] backspace intrinsic is not working on an unformatted file
  2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
@ 2007-04-18 14:01 ` jvdelisle at gcc dot gnu dot org
  2007-04-19  2:47 ` jvdelisle at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2007-04-18 14:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from jvdelisle at gcc dot gnu dot org  2007-04-18 15:01 -------
hmm, I will investigate.


-- 


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


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

* [Bug fortran/31618] backspace intrinsic is not working on an unformatted file
  2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
  2007-04-18 14:01 ` [Bug fortran/31618] " jvdelisle at gcc dot gnu dot org
@ 2007-04-19  2:47 ` jvdelisle at gcc dot gnu dot org
  2007-04-19 20:35 ` tkoenig at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2007-04-19  2:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jvdelisle at gcc dot gnu dot org  2007-04-19 03:47 -------
Confirming.  g77 does not do it right either.  :)


-- 

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         |2007-04-19 03:47:49
               date|                            |


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


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

* [Bug fortran/31618] backspace intrinsic is not working on an unformatted file
  2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
  2007-04-18 14:01 ` [Bug fortran/31618] " jvdelisle at gcc dot gnu dot org
  2007-04-19  2:47 ` jvdelisle at gcc dot gnu dot org
@ 2007-04-19 20:35 ` tkoenig at gcc dot gnu dot org
  2007-04-20 21:29 ` tkoenig at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-04-19 20:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from tkoenig at gcc dot gnu dot org  2007-04-19 21:35 -------
(In reply to comment #2)
> Confirming.  g77 does not do it right either.  :)

gfortran 4.1 doesn't get this right either, so at least
this isn't a regression.  Uff :-)


-- 

tkoenig at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tkoenig at gcc dot gnu dot
                   |                            |org
           Keywords|                            |wrong-code


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


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

* [Bug fortran/31618] backspace intrinsic is not working on an unformatted file
  2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
                   ` (2 preceding siblings ...)
  2007-04-19 20:35 ` tkoenig at gcc dot gnu dot org
@ 2007-04-20 21:29 ` tkoenig at gcc dot gnu dot org
  2007-04-21 22:12 ` tkoenig at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-04-20 21:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from tkoenig at gcc dot gnu dot org  2007-04-20 22:29 -------
Strictly speaking, this is not a violation of the
Fortran standard, as there are no guarantees of what happens
after an error.

Nonetheless, we should fix it.

I'm investigating.


-- 


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


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

* [Bug fortran/31618] backspace intrinsic is not working on an unformatted file
  2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
                   ` (3 preceding siblings ...)
  2007-04-20 21:29 ` tkoenig at gcc dot gnu dot org
@ 2007-04-21 22:12 ` tkoenig at gcc dot gnu dot org
  2007-04-21 22:47 ` jvdelisle at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-04-21 22:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from tkoenig at gcc dot gnu dot org  2007-04-21 23:12 -------
Created an attachment (id=13402)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13402&action=view)
proposed patch

This could work.  Let's see if this passes regression.


-- 

tkoenig at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |tkoenig at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED


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


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

* [Bug fortran/31618] backspace intrinsic is not working on an unformatted file
  2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
                   ` (4 preceding siblings ...)
  2007-04-21 22:12 ` tkoenig at gcc dot gnu dot org
@ 2007-04-21 22:47 ` jvdelisle at gcc dot gnu dot org
  2007-04-22 21:10 ` patchapp at dberlin dot org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2007-04-21 22:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jvdelisle at gcc dot gnu dot org  2007-04-21 23:47 -------
Thats an interesting approach.  I am curious for the results.  I also like the
adjustments to errors you have made.


-- 


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


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

* [Bug fortran/31618] backspace intrinsic is not working on an unformatted file
  2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
                   ` (5 preceding siblings ...)
  2007-04-21 22:47 ` jvdelisle at gcc dot gnu dot org
@ 2007-04-22 21:10 ` patchapp at dberlin dot org
  2007-04-23 19:44 ` tkoenig at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: patchapp at dberlin dot org @ 2007-04-22 21:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from patchapp at dberlin dot org  2007-04-22 22:10 -------
Subject: Bug number PR 31618

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/2007-04/msg01432.html


-- 


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


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

* [Bug fortran/31618] backspace intrinsic is not working on an unformatted file
  2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
                   ` (6 preceding siblings ...)
  2007-04-22 21:10 ` patchapp at dberlin dot org
@ 2007-04-23 19:44 ` tkoenig at gcc dot gnu dot org
  2007-04-23 19:47 ` [Bug fortran/31618] [4.2, 4.1 only] " tkoenig at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-04-23 19:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from tkoenig at gcc dot gnu dot org  2007-04-23 20:44 -------
Subject: Bug 31618

Author: tkoenig
Date: Mon Apr 23 20:43:54 2007
New Revision: 124079

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124079
Log:
2007-04-23  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/31618
        * io/transfer.c (read_block_direct):  Instead of calling us_read,
        set dtp->u.p.current_unit->current_record = 0 so that pre_position
        will read the record marker.
        (data_transfer_init):  For different error conditions, call
        generate_error, then return.

2007-04-23  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/31618
        * gfortran.dg/backspace_8.f:  New test case.


Added:
    trunk/gcc/testsuite/gfortran.dg/backspace_8.f
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/transfer.c


-- 


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


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

* [Bug fortran/31618] [4.2, 4.1 only] backspace intrinsic is not working on an unformatted file
  2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
                   ` (7 preceding siblings ...)
  2007-04-23 19:44 ` tkoenig at gcc dot gnu dot org
@ 2007-04-23 19:47 ` tkoenig at gcc dot gnu dot org
  2007-05-20 21:09 ` tkoenig at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-04-23 19:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from tkoenig at gcc dot gnu dot org  2007-04-23 20:46 -------
Fixed on trunk.

Maybe we should backport this once 4.2.1 is open.


-- 

tkoenig at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |4.2.0 4.1.2
      Known to work|                            |4.3.0
            Summary|backspace intrinsic is not  |[4.2, 4.1 only] backspace
                   |working on an unformatted   |intrinsic is not working on
                   |file                        |an unformatted file


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


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

* [Bug fortran/31618] [4.2, 4.1 only] backspace intrinsic is not working on an unformatted file
  2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
                   ` (8 preceding siblings ...)
  2007-04-23 19:47 ` [Bug fortran/31618] [4.2, 4.1 only] " tkoenig at gcc dot gnu dot org
@ 2007-05-20 21:09 ` tkoenig at gcc dot gnu dot org
  2007-05-20 21:12 ` tkoenig at gcc dot gnu dot org
  2007-05-26  3:14 ` pinskia at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-05-20 21:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from tkoenig at gcc dot gnu dot org  2007-05-20 22:09 -------
Subject: Bug 31618

Author: tkoenig
Date: Sun May 20 21:07:14 2007
New Revision: 124878

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124878
Log:
2007-05-20  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/31618
        Backport from trunk.
        * io/transfer.c (read_block_direct):  Instead of calling us_read,
        set dtp->u.p.current_unit->current_record = 0 so that pre_position
        will read the record marker.
        (data_transfer_init):  For different error conditions, call
        generate_error, then return.

2007-05-20  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/31618
        Backport from trunk.
        * gfortran.dg/backspace_8.f:  New test case.


Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/backspace_8.f
Modified:
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_2-branch/libgfortran/ChangeLog
    branches/gcc-4_2-branch/libgfortran/io/transfer.c


-- 


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


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

* [Bug fortran/31618] [4.2, 4.1 only] backspace intrinsic is not working on an unformatted file
  2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
                   ` (9 preceding siblings ...)
  2007-05-20 21:09 ` tkoenig at gcc dot gnu dot org
@ 2007-05-20 21:12 ` tkoenig at gcc dot gnu dot org
  2007-05-26  3:14 ` pinskia at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-05-20 21:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from tkoenig at gcc dot gnu dot org  2007-05-20 22:11 -------
Now also fixed on 4.2.1 (revision 124878).  Won't backport to 4.1.

Closing.


-- 

tkoenig at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to work|4.3.0                       |4.3.0 4.2.1
         Resolution|                            |FIXED


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


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

* [Bug fortran/31618] [4.2, 4.1 only] backspace intrinsic is not working on an unformatted file
  2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
                   ` (10 preceding siblings ...)
  2007-05-20 21:12 ` tkoenig at gcc dot gnu dot org
@ 2007-05-26  3:14 ` pinskia at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-05-26  3:14 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.2.1


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


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

end of thread, other threads:[~2007-05-26  3:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
2007-04-18 14:01 ` [Bug fortran/31618] " jvdelisle at gcc dot gnu dot org
2007-04-19  2:47 ` jvdelisle at gcc dot gnu dot org
2007-04-19 20:35 ` tkoenig at gcc dot gnu dot org
2007-04-20 21:29 ` tkoenig at gcc dot gnu dot org
2007-04-21 22:12 ` tkoenig at gcc dot gnu dot org
2007-04-21 22:47 ` jvdelisle at gcc dot gnu dot org
2007-04-22 21:10 ` patchapp at dberlin dot org
2007-04-23 19:44 ` tkoenig at gcc dot gnu dot org
2007-04-23 19:47 ` [Bug fortran/31618] [4.2, 4.1 only] " tkoenig at gcc dot gnu dot org
2007-05-20 21:09 ` tkoenig at gcc dot gnu dot org
2007-05-20 21:12 ` tkoenig at gcc dot gnu dot org
2007-05-26  3:14 ` pinskia 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).