[flang-commits] [flang] 6ce0fba - [flang][runtime] Skip remainder of bad input record even with ADVANCE='NO'

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon Jun 13 16:36:29 PDT 2022


Author: Peter Klausler
Date: 2022-06-13T16:36:19-07:00
New Revision: 6ce0fba0e800155e40964a955f9002cdfac560c7

URL: https://github.com/llvm/llvm-project/commit/6ce0fba0e800155e40964a955f9002cdfac560c7
DIFF: https://github.com/llvm/llvm-project/commit/6ce0fba0e800155e40964a955f9002cdfac560c7.diff

LOG: [flang][runtime] Skip remainder of bad input record even with ADVANCE='NO'

After a recoverable error condition in a READ statement with ADVANCE='NO',
skip the remainder of the current record.

Differential Revision: https://reviews.llvm.org/D127433

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 0201ad2bf7da..480cbea81821 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/flang/runtime/io-stmt.cpp
@@ -319,10 +319,9 @@ void ExternalIoStatementState<DIR>::CompleteOperation() {
   }
   if constexpr (DIR == Direction::Input) {
     BeginReadingRecord(); // in case there were no I/O items
-    if (mutableModes().nonAdvancing) {
+    if (mutableModes().nonAdvancing && !InError()) {
       unit().leftTabLimit = unit().furthestPositionInRecord;
-    }
-    if (!mutableModes().nonAdvancing || GetIoStat() == IostatEor) {
+    } else {
       FinishReadingRecord();
     }
   } else { // output

diff  --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index c7df78a1ed0d..27ad178d5b27 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -458,14 +458,14 @@ bool ExternalFileUnit::BeginReadingRecord(IoErrorHandler &handler) {
 void ExternalFileUnit::FinishReadingRecord(IoErrorHandler &handler) {
   RUNTIME_CHECK(handler, direction_ == Direction::Input && beganReadingRecord_);
   beganReadingRecord_ = false;
-  if (handler.InError() && handler.GetIoStat() != IostatEor) {
+  if (handler.GetIoStat() == IostatEnd ||
+      (IsRecordFile() && !recordLength.has_value())) {
     // Avoid bogus crashes in END/ERR circumstances; but
     // still increment the current record number so that
     // an attempted read of an endfile record, followed by
     // a BACKSPACE, will still be at EOF.
     ++currentRecordNumber;
   } else if (IsRecordFile()) {
-    RUNTIME_CHECK(handler, recordLength.has_value());
     recordOffsetInFrame_ += *recordLength;
     if (access != Access::Direct) {
       RUNTIME_CHECK(handler, isUnformatted.has_value());


        


More information about the flang-commits mailing list