This is an archive of the discontinued LLVM Phabricator instance.

[flang] runtime: fix problems with I/O around EOF & delimited characters
ClosedPublic

Authored by klausler on Jul 23 2021, 12:03 PM.

Details

Summary

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.

Diff Detail

Event Timeline

klausler created this revision.Jul 23 2021, 12:03 PM
klausler requested review of this revision.Jul 23 2021, 12:03 PM
PeteSteinfeld accepted this revision.Jul 23 2021, 2:49 PM

All builds, tests, and looks good.

This revision is now accepted and ready to land.Jul 23 2021, 2:49 PM
This revision was landed with ongoing or failed builds.Jul 23 2021, 6:48 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2021, 6:48 PM