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

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon May 9 13:07:52 PDT 2022


Author: Peter Klausler
Date: 2022-05-09T13:00:41-07:00
New Revision: 72831a592edf1bdcca15354181867079a17d4f76

URL: https://github.com/llvm/llvm-project/commit/72831a592edf1bdcca15354181867079a17d4f76
DIFF: https://github.com/llvm/llvm-project/commit/72831a592edf1bdcca15354181867079a17d4f76.diff

LOG: [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

Added: 
    

Modified: 
    flang/runtime/io-stmt.cpp
    flang/runtime/unit.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/io-stmt.cpp b/flang/runtime/io-stmt.cpp
index 8080263ff20d..237d2648b61d 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/flang/runtime/io-stmt.cpp
@@ -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();
     }

diff  --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index 31c350f33d3b..7b4a0ea27bf9 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -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) {


        


More information about the flang-commits mailing list