Skip to content

Commit ce71f8e

Browse files
committed
[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
1 parent bf6f955 commit ce71f8e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

flang/runtime/io-stmt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ ExternalFormattedIoStatementState<DIR, CHAR>::ExternalFormattedIoStatementState(
388388

389389
template <Direction DIR, typename CHAR>
390390
int ExternalFormattedIoStatementState<DIR, CHAR>::EndIoStatement() {
391+
if constexpr (DIR == Direction::Input) {
392+
this->BeginReadingRecord(); // in case there were no I/O items
393+
}
391394
format_.Finish(*this);
392395
return ExternalIoStatementState<DIR>::EndIoStatement();
393396
}

0 commit comments

Comments
 (0)