diff --git a/flang/runtime/io-stmt.cpp b/flang/runtime/io-stmt.cpp --- a/flang/runtime/io-stmt.cpp +++ b/flang/runtime/io-stmt.cpp @@ -315,6 +315,9 @@ } 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(); } diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp --- a/flang/runtime/unit.cpp +++ b/flang/runtime/unit.cpp @@ -569,6 +569,9 @@ 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) {