[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

GitOrigin-RevId: ce71f8e01742598f9f0b563d259561e755e1cbce
diff --git a/runtime/io-stmt.cpp b/runtime/io-stmt.cpp
index 57e484c..44fc7ae 100644
--- a/runtime/io-stmt.cpp
+++ b/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();
 }