diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp --- a/flang/runtime/io-api.cpp +++ b/flang/runtime/io-api.cpp @@ -317,7 +317,7 @@ } else { // CLOSE(UNIT=bad unit) is just a no-op Terminator oom{sourceFile, sourceLine}; - return &New<NoopCloseStatementState>{oom}(sourceFile, sourceLine) + return &New<NoopStatementState>{oom}(sourceFile, sourceLine) .release() ->ioStatementState(); } @@ -325,11 +325,16 @@ Cookie IONAME(BeginFlush)( ExternalUnit unitNumber, const char *sourceFile, int sourceLine) { - Terminator terminator{sourceFile, sourceLine}; - ExternalFileUnit &unit{ - ExternalFileUnit::LookUpOrCrash(unitNumber, terminator)}; - return &unit.BeginIoStatement<ExternalMiscIoStatementState>( - unit, ExternalMiscIoStatementState::Flush, sourceFile, sourceLine); + if (ExternalFileUnit * unit{ExternalFileUnit::LookUp(unitNumber)}) { + return &unit->BeginIoStatement<ExternalMiscIoStatementState>( + *unit, ExternalMiscIoStatementState::Flush, sourceFile, sourceLine); + } else { + // FLUSH(UNIT=unknown) is a no-op + Terminator oom{sourceFile, sourceLine}; + return &New<NoopStatementState>{oom}(sourceFile, sourceLine) + .release() + ->ioStatementState(); + } } Cookie IONAME(BeginBackspace)( @@ -880,7 +885,7 @@ } return false; } - if (io.get_if<NoopCloseStatementState>()) { + if (io.get_if<NoopStatementState>()) { return true; // don't bother validating STATUS= in a no-op CLOSE } io.GetIoErrorHandler().Crash( diff --git a/flang/runtime/io-stmt.h b/flang/runtime/io-stmt.h --- a/flang/runtime/io-stmt.h +++ b/flang/runtime/io-stmt.h @@ -34,7 +34,7 @@ class InquireIOLengthState; class ExternalMiscIoStatementState; class CloseStatementState; -class NoopCloseStatementState; +class NoopStatementState; // CLOSE or FLUSH on unknown unit template <Direction, typename CHAR = char> class InternalFormattedIoStatementState; @@ -238,7 +238,7 @@ private: std::variant<std::reference_wrapper<OpenStatementState>, std::reference_wrapper<CloseStatementState>, - std::reference_wrapper<NoopCloseStatementState>, + std::reference_wrapper<NoopStatementState>, std::reference_wrapper< InternalFormattedIoStatementState<Direction::Output>>, std::reference_wrapper< @@ -616,9 +616,9 @@ ConnectionState connection_; }; -class NoopCloseStatementState : public NoUnitIoStatementState { +class NoopStatementState : public NoUnitIoStatementState { public: - NoopCloseStatementState(const char *sourceFile, int sourceLine) + NoopStatementState(const char *sourceFile, int sourceLine) : NoUnitIoStatementState{sourceFile, sourceLine, *this} {} void set_status(CloseStatus) {} // discards };