[flang][runtime] Skip remainder of bad input record even with ADVANCE='NO'
authorPeter Klausler <pklausler@nvidia.com>
Wed, 8 Jun 2022 22:23:56 +0000 (15:23 -0700)
committerPeter Klausler <pklausler@nvidia.com>
Mon, 13 Jun 2022 23:36:19 +0000 (16:36 -0700)
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

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

index 0201ad2..480cbea 100644 (file)
@@ -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
index c7df78a..27ad178 100644 (file)
@@ -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());