[flang-commits] [PATCH] D106695: [flang] runtime: fix problems with I/O around EOF & delimited characters

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jul 23 12:04:01 PDT 2021


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.

When a WRITE overwrites an endfile record, we need to forget
that there was an endfile record.  When doing a BACKSPACE
after an explicit ENDFILE statement, the position afterwards
must be upon the endfile record.

Attempts to join list-directed delimited character input across
record boundaries was due to a bad reading of the standard
and has been deleted, now that the requirements are better understood.
This problem would cause a read attempt past EOF if a delimited
character input value was at the end of a record.

It turns out that delimited list-directed (and NAMELIST) character
output is required to emit contiguous doubled instances of the
delimiter character when it appears in the output value.  When
fixed-size records are being emitted, as is the case with internal
output, this is not possible when the problematic character falls
on the last position of a record.  No two other Fortran compilers
do the same thing in this situation so there is no good precedent
to follow.

Because it seems least wrong, with this patch we now emit one copy
of the delimiter as the last character of the current record and
another as the first character of the next record.  (The
second-least-wrong alternative might be to flag a runtime error,
but that seems harsh since it's not an explicit error in the standard,
and the output may not have to be usable later as input anyway.)
Consequently, the output is not suitable for use as list-directed or
NAMELIST input.

If a later standard were to clarify this case, this behavior will of
course change as needed to conform.


https://reviews.llvm.org/D106695

Files:
  flang/docs/Extensions.md
  flang/runtime/edit-input.cpp
  flang/runtime/edit-output.cpp
  flang/runtime/unit.cpp
  flang/unittests/RuntimeGTest/Namelist.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106695.361293.patch
Type: text/x-patch
Size: 8273 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210723/890ff8b1/attachment.bin>


More information about the flang-commits mailing list