[flang-commits] [flang] ce71f8e - [flang] Fix crash on empty formatted external READs
peter klausler via flang-commits
flang-commits at lists.llvm.org
Fri Oct 22 15:52:35 PDT 2021
Author: peter klausler
Date: 2021-10-22T15:48:45-07:00
New Revision: ce71f8e01742598f9f0b563d259561e755e1cbce
URL: https://github.com/llvm/llvm-project/commit/ce71f8e01742598f9f0b563d259561e755e1cbce
DIFF: https://github.com/llvm/llvm-project/commit/ce71f8e01742598f9f0b563d259561e755e1cbce.diff
LOG: [flang] Fix crash on empty formatted external READs
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.
Differential Revision: https://reviews.llvm.org/D112351
Added:
Modified:
flang/runtime/io-stmt.cpp
Removed:
################################################################################
diff --git a/flang/runtime/io-stmt.cpp b/flang/runtime/io-stmt.cpp
index 57e484c6c1e9..44fc7aefea6e 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/flang/runtime/io-stmt.cpp
@@ -388,6 +388,9 @@ ExternalFormattedIoStatementState<DIR, CHAR>::ExternalFormattedIoStatementState(
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();
}
More information about the flang-commits
mailing list