[flang][runtime] BACKSPACE after non-advancing I/O

A BACKSPACE statement on a unit after a READ or WRITE with ADVANCE="NO"
must reset the position to the beginning of the record, not to the
beginning of the previous one.

Differential Revision: https://reviews.llvm.org/D125057
This commit is contained in:
Peter Klausler 2022-04-28 16:54:40 -07:00
parent 28b5e99a4c
commit 72831a592e
2 changed files with 6 additions and 0 deletions

View File

@ -315,6 +315,9 @@ void ExternalIoStatementState<DIR>::CompleteOperation() {
}
if constexpr (DIR == Direction::Input) {
BeginReadingRecord(); // in case there were no I/O items
if (mutableModes().nonAdvancing) {
unit().leftTabLimit = unit().furthestPositionInRecord;
}
if (!mutableModes().nonAdvancing || GetIoStat() == IostatEor) {
FinishReadingRecord();
}

View File

@ -569,6 +569,9 @@ void ExternalFileUnit::BackspaceRecord(IoErrorHandler &handler) {
if (IsAfterEndfile()) {
// BACKSPACE after explicit ENDFILE
currentRecordNumber = *endfileRecordNumber;
} else if (leftTabLimit) {
// BACKSPACE after non-advancing I/O
leftTabLimit.reset();
} else {
DoImpliedEndfile(handler);
if (frameOffsetInFile_ + recordOffsetInFrame_ > 0) {