public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/52387] New: I/O wrong output with nonadvancing output
@ 2012-02-26 10:02 burnus at gcc dot gnu.org
  2012-02-26 10:13 ` [Bug fortran/52387] " burnus at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-02-26 10:02 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52387
           Summary: I/O wrong output with nonadvancing output
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org
                CC: jvdelisle@gcc.gnu.org


[Vaguely related: PR 52251]

Bob Corbett asked at c.l.f what the program below produces with the different
compilers. He thinks that the proper output should be:

ABCDMNOPIJKL

while gfortran produces

ABCDMNOP

(or actually, it [and NAG f95] produce [cf. modified program]:
>ABCDMNOP    <

with trailing spaces.)

Reasoning:

---------------- <cut> ---------------- 
According to interpretation 000024 of the Fortran 95 standard

Page 136. At the end of the last paragraph of subclause 9.2.1.3.1
[136:33] add
   If a nonadvancing output statement leaves a file positioned within
   the current record and no further output statement is executed
   for the file before it is closed or a BACKSPACE, ENDFILE, or REWIND
   statement is executed for it, the file is positioned after the
   current record before the specified action is performed.

The corresponding statement in the Fortran 2008 standard is
paragraph 2 of Clause 9.3.4.2.  Based on that statement and
on paragraph 4 of non-normative Clause C.6.2 of the
Fortran 2008 standard, my reading is that the output should
be

ABCDMNOPIJKL
---------------- </cut> ----------------

See complete thread at
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/694050b1806da367


Results of the various compilers:


Bob's expected result, Pathscale 4.0, Openf95 5.0, OpenUH/Open64
ABCDMNOPIJKL

gfortran (4.1 to 4.7), NAG 5.1, 
ABCDMNOP

g95, Silverfrost ftn95, ifort 11.1/12.1
ABCDEFGHIJKL 

sunf95 10/latest Oracle f95, IBM xlf, Microsoft V 3.31 (1985)
MNOP

Lahey:
ABCDMNOP


      PROGRAM MAIN
        CHARACTER*12 STR
        OPEN (10, FILE='XXX', POSITION='REWIND')
        WRITE (10, '(A)') 'ABCDEFGHIJKL'
        REWIND 10
        READ (10, '(TR4)', ADVANCE='NO')
        WRITE (10, '(TL2, A)', ADVANCE='NO') 'MNOP'
        REWIND 10
        READ (10, '(A)') STR
        PRINT '(3A)', STR
!        PRINT '(3A)', '>',STR,'<'
        CLOSE (10, STATUS='DELETE')
      END


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

* [Bug fortran/52387] I/O wrong output with nonadvancing output
  2012-02-26 10:02 [Bug fortran/52387] New: I/O wrong output with nonadvancing output burnus at gcc dot gnu.org
@ 2012-02-26 10:13 ` burnus at gcc dot gnu.org
  2012-02-26 11:12 ` burnus at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-02-26 10:13 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-26 10:02:03 UTC ---
(In reply to comment #0)
>         WRITE (10, '(A)') 'ABCDEFGHIJKL'

At this point, the file contains: "ABCDEFGHIJKL" + <new line>.

>         REWIND 10
>         READ (10, '(TR4)', ADVANCE='NO')
>         WRITE (10, '(TL2, A)', ADVANCE='NO') 'MNOP'

And at that point, the file is trimmed to contain "ABCDMNOP" without <new
line>.


With other compilers (file "XXX"):

NAG has at the end: "ABCDMNOP" plus line break.
g95 has at the end: "ABCDEFGHIJKL" + <line break> + "MNOP" + no linebreak.
pathscale: "ABCDMNOPIJKL" + linebreak.


 * * *

Fortran 2008's C.6.2, paragraph 4 (nonnormative):

"If the next I/O operation on a file after a nonadvancing write is a rewind,
backspace, end file or close operation, the file is positioned implicitly after
the current record before an ENDFILE record is written to the file, that is, a
REWIND, BACKSPACE, or ENDFILE statement following a nonadvancing WRITE
statement causes the file to be positioned at the end of the current output
record before the endfile record is written to the file."


And the paragraph 2 of Clause 9.3.4.2 is the following:

"A nonadvancing input/output statement may position a record file at a
character position within the current record, or a subsequent record (10.8.2).
Using nonadvancing input/output, it is possible to read or write a record of
the \fle by a sequence of input/output statements, each accessing a portion of
the record. It is also possible to read variable-length records and be noti\fed
of their lengths. If a nonadvancing output statement leaves a file positioned
within a current record and no further output statement is executed for the
file before it is closed or a BACKSPACE, ENDFILE, or REWIND statement is
executed for it, the effect is as if the output statement were the
corresponding advancing output statement."

 * * *

At least looking at the normative text (9.3.4.2), I think NAG's result is
correct: Namely, after writing "ABCDMNOP" the record is ended with a record
marker (new line) and then it is trimmed (end file marker is written).

Looking at the nonormative text, I get the conclusion Bob had: Namely that the
result should be "ABCDMNOPIJKL" followed by a new line and the endfile marker.


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

* [Bug fortran/52387] I/O wrong output with nonadvancing output
  2012-02-26 10:02 [Bug fortran/52387] New: I/O wrong output with nonadvancing output burnus at gcc dot gnu.org
  2012-02-26 10:13 ` [Bug fortran/52387] " burnus at gcc dot gnu.org
@ 2012-02-26 11:12 ` burnus at gcc dot gnu.org
  2012-02-26 12:29 ` burnus at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-02-26 11:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-26 10:36:55 UTC ---
(In reply to comment #1)
>         WRITE (10, '(TL2, A)', ADVANCE='NO') 'MNOP'
>
> And at that point, the file is trimmed to contain "ABCDMNOP" without <new
> line>.
> 
> With other compilers (file "XXX"):
> 
> NAG has at the end: "ABCDMNOP" plus line break.


That's actually misleading. gfortran has "ABCDMNOP" without new line before the
REWIND. But it correctly adds the new line after rewinding. Thus, the end
result is the same as with NAG.

Hence, I believe that gfortran's result matches the Fortran 2008 standard.


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

* [Bug fortran/52387] I/O wrong output with nonadvancing output
  2012-02-26 10:02 [Bug fortran/52387] New: I/O wrong output with nonadvancing output burnus at gcc dot gnu.org
  2012-02-26 10:13 ` [Bug fortran/52387] " burnus at gcc dot gnu.org
  2012-02-26 11:12 ` burnus at gcc dot gnu.org
@ 2012-02-26 12:29 ` burnus at gcc dot gnu.org
  2012-02-27  9:23 ` burnus at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-02-26 12:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-26 11:40:19 UTC ---
(In reply to comment #0)
> According to interpretation 000024 of the Fortran 95 standard

See: http://j3-fortran.org/doc/year/02/02-006c2.txt


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

* [Bug fortran/52387] I/O wrong output with nonadvancing output
  2012-02-26 10:02 [Bug fortran/52387] New: I/O wrong output with nonadvancing output burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2012-02-26 12:29 ` burnus at gcc dot gnu.org
@ 2012-02-27  9:23 ` burnus at gcc dot gnu.org
  2012-02-28 10:15 ` [Bug fortran/52387] I/O output of write after nonadvancing read burnus at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-02-27  9:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-27 09:22:53 UTC ---
I have now asked at J3:
  http://j3-fortran.org/pipermail/j3/2012-February/005062.html

Bob disagrees with my interpretation, see c.l.f and in particular:
  http://groups.google.com/group/comp.lang.fortran/msg/1916a6c8d7f917a1


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

* [Bug fortran/52387] I/O output of write after nonadvancing read
  2012-02-26 10:02 [Bug fortran/52387] New: I/O wrong output with nonadvancing output burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2012-02-27  9:23 ` burnus at gcc dot gnu.org
@ 2012-02-28 10:15 ` burnus at gcc dot gnu.org
  2012-02-29 13:03 ` burnus at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-02-28 10:15 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|I/O wrong output with       |I/O output of write after
                   |nonadvancing output         |nonadvancing read

--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-28 09:58:37 UTC ---
>From the J3 discussion: While Bob thinks that the standard is obvious, Van
disagrees, cf. http://j3-fortran.org/pipermail/j3/2012-February/005067.html

I wrote a draft IR, which is available at
http://j3-fortran.org/pipermail/j3/2012-February/005069.html

I intent to submit the IR for the next meeting (presumably J3 #198 jointly with
WG5 at Toronto in June).


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

* [Bug fortran/52387] I/O output of write after nonadvancing read
  2012-02-26 10:02 [Bug fortran/52387] New: I/O wrong output with nonadvancing output burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2012-02-28 10:15 ` [Bug fortran/52387] I/O output of write after nonadvancing read burnus at gcc dot gnu.org
@ 2012-02-29 13:03 ` burnus at gcc dot gnu.org
  2012-02-29 21:13 ` burnus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-02-29 13:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-29 13:02:21 UTC ---
I think it get's even messier with the following, simpler looking code, which
consists of four variants (without read/with nonadvanced read -- and with
advanced/nonadvanced write):


  OPEN (10, FILE='XXX', status='replace')
  WRITE(10, '(a)') 'ABCDEFGHIJKL'
  WRITE(10, '(a)') '1234567890ab'
  close (10)

  OPEN (10, FILE='XXX', position='REWIND', status='old', &
        action='readwrite') ! or 'write'
!      READ(10, '(tr4)', advance='no') ! << add optionally
  WRITE (10, '(A)', ADVANCE='NO') 'mnop' ! << optional advance == 'yes'
  call FLUSH (10)
  call system ('cat XXX; echo "<"')
  close(10)
  call system ('cat XXX; echo "<"')
end

[With "call flush"->"flush", "system"->"execute_command_line", it should be
F2008 standard conforming.]


-----------------------------------------

With the Cray/Open64/Pathscale compiler, one gets for instance the following:

Without READ:
mnopEFGHIJKL
1234567890ab
<
mnop
<

And with READ (and also with advance='yes') [that's Bobs example, presumably
with the output he expects]:
ABCDmnopIJKL
1234567890ab
<
ABCDmnopIJKL
<

However, without READ and advance='yes' for WRITE, one gets:
MNOP
FGHIJKL
1234567890ab
<
MNOP
<


-----------------------------------------

By contrast, gfortran has for WRITE:
MNOP<
MNOP
<

And for READ:
ABCDMNOP<
ABCDMNOP
<

That's for advance='no'. With advance='yes', each line ends with a line break.


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

* [Bug fortran/52387] I/O output of write after nonadvancing read
  2012-02-26 10:02 [Bug fortran/52387] New: I/O wrong output with nonadvancing output burnus at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2012-02-29 13:03 ` burnus at gcc dot gnu.org
@ 2012-02-29 21:13 ` burnus at gcc dot gnu.org
  2012-03-01  1:48 ` jvdelisle at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-02-29 21:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-29 21:12:46 UTC ---
It gets even messier with STREAM I/O. For a compiler comparison w/o further
comments, see
https://groups.google.com/d/msg/comp.lang.fortran/aUBQsYBto2c/d_noVS80FV4J (and
for an older version, see also J3 thread).


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

* [Bug fortran/52387] I/O output of write after nonadvancing read
  2012-02-26 10:02 [Bug fortran/52387] New: I/O wrong output with nonadvancing output burnus at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2012-02-29 21:13 ` burnus at gcc dot gnu.org
@ 2012-03-01  1:48 ` jvdelisle at gcc dot gnu.org
  2012-03-03  8:10 ` burnus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2012-03-01  1:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2012-03-01 01:48:23 UTC ---
Are all the cards played here yet?  I assume we won't waste time implementing
any changes until the requirements are clearly understood.  Please ping me when
that point is reached.  There are plenty more important issues then this one
out there.
;)


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

* [Bug fortran/52387] I/O output of write after nonadvancing read
  2012-02-26 10:02 [Bug fortran/52387] New: I/O wrong output with nonadvancing output burnus at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2012-03-01  1:48 ` jvdelisle at gcc dot gnu.org
@ 2012-03-03  8:10 ` burnus at gcc dot gnu.org
  2012-10-28  0:36 ` jvdelisle at gcc dot gnu.org
  2014-01-07 14:29 ` dominiq at lps dot ens.fr
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-03-03  8:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-03-03 08:10:14 UTC ---
See also new thread by Bob ("Fortran I/O (long)"):
https://groups.google.com/forum/?fromgroups#!topic/comp.lang.fortran/003shg-vXis


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

* [Bug fortran/52387] I/O output of write after nonadvancing read
  2012-02-26 10:02 [Bug fortran/52387] New: I/O wrong output with nonadvancing output burnus at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2012-03-03  8:10 ` burnus at gcc dot gnu.org
@ 2012-10-28  0:36 ` jvdelisle at gcc dot gnu.org
  2014-01-07 14:29 ` dominiq at lps dot ens.fr
  10 siblings, 0 replies; 12+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2012-10-28  0:36 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #10 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2012-10-28 00:35:41 UTC ---
Tobias, any further information on this one?


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

* [Bug fortran/52387] I/O output of write after nonadvancing read
  2012-02-26 10:02 [Bug fortran/52387] New: I/O wrong output with nonadvancing output burnus at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2012-10-28  0:36 ` jvdelisle at gcc dot gnu.org
@ 2014-01-07 14:29 ` dominiq at lps dot ens.fr
  10 siblings, 0 replies; 12+ messages in thread
From: dominiq at lps dot ens.fr @ 2014-01-07 14:29 UTC (permalink / raw)
  To: gcc-bugs

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

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2014-01-07
     Ever confirmed|0                           |1

--- Comment #11 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> Tobias, any further information on this one?

Any news after more than one year?


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

end of thread, other threads:[~2014-01-07 14:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-26 10:02 [Bug fortran/52387] New: I/O wrong output with nonadvancing output burnus at gcc dot gnu.org
2012-02-26 10:13 ` [Bug fortran/52387] " burnus at gcc dot gnu.org
2012-02-26 11:12 ` burnus at gcc dot gnu.org
2012-02-26 12:29 ` burnus at gcc dot gnu.org
2012-02-27  9:23 ` burnus at gcc dot gnu.org
2012-02-28 10:15 ` [Bug fortran/52387] I/O output of write after nonadvancing read burnus at gcc dot gnu.org
2012-02-29 13:03 ` burnus at gcc dot gnu.org
2012-02-29 21:13 ` burnus at gcc dot gnu.org
2012-03-01  1:48 ` jvdelisle at gcc dot gnu.org
2012-03-03  8:10 ` burnus at gcc dot gnu.org
2012-10-28  0:36 ` jvdelisle at gcc dot gnu.org
2014-01-07 14:29 ` dominiq at lps dot ens.fr

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