[flang-commits] [PATCH] D112351: [flang] Fix crash on empty formatted external READs

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Oct 22 14:53:57 PDT 2021


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.

ExternalFileUnit::BeginReadingRecord() must be called at least once
during an external formatted READ statement before FinishReadingRecord().
In the case of a formatted external READ with no data items, the call
to finish processing of the format (which might have lingering control
items that need doing) was taking place before the call to BeginReadingRecord
from ExternalIoStatementState::EndIoStatement.  Add a call to
BeginReadingRecord on this path.


https://reviews.llvm.org/D112351

Files:
  flang/runtime/io-stmt.cpp


Index: flang/runtime/io-stmt.cpp
===================================================================
--- flang/runtime/io-stmt.cpp
+++ flang/runtime/io-stmt.cpp
@@ -388,6 +388,9 @@
 
 template <Direction DIR, typename CHAR>
 int ExternalFormattedIoStatementState<DIR, CHAR>::EndIoStatement() {
+  if constexpr (DIR == Direction::Input) {
+    this->BeginReadingRecord(); // in case there were no I/O items
+  }
   format_.Finish(*this);
   return ExternalIoStatementState<DIR>::EndIoStatement();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112351.381666.patch
Type: text/x-patch
Size: 499 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20211022/6579c19b/attachment.bin>


More information about the flang-commits mailing list