Skip to content

Commit b0a971d

Browse files
committed
[flang] Prevent bogus runtime I/O error message
The runtime was requiring that STATUS='OLD' be explicitly specified on an OPEN statement for a connected unit. There error should issue only if a STATUS= other than 'OLD' is specified; an OPEN with no STATUS= specifier is okay. Reviewed By: sscalpone Differential Revision: https://reviews.llvm.org/D84079
1 parent 8305a92 commit b0a971d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

flang/runtime/io-stmt.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,12 @@ void OpenStatementState::set_path(
162162
}
163163

164164
int OpenStatementState::EndIoStatement() {
165-
if (wasExtant_ && status_ != OpenStatus::Old) {
166-
SignalError("OPEN statement for connected unit must have STATUS='OLD'");
165+
if (wasExtant_ && status_ && *status_ != OpenStatus::Old) {
166+
SignalError("OPEN statement for connected unit may not have STATUS= other "
167+
"than 'OLD'");
167168
}
168-
unit().OpenUnit(
169-
status_, action_, position_, std::move(path_), pathLength_, *this);
169+
unit().OpenUnit(status_.value_or(OpenStatus::Unknown), action_, position_,
170+
std::move(path_), pathLength_, *this);
170171
return ExternalIoStatementBase::EndIoStatement();
171172
}
172173

flang/runtime/io-stmt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class OpenStatementState : public ExternalIoStatementBase {
302302

303303
private:
304304
bool wasExtant_;
305-
OpenStatus status_{OpenStatus::Unknown};
305+
std::optional<OpenStatus> status_;
306306
Position position_{Position::AsIs};
307307
std::optional<Action> action_;
308308
OwningPtr<char> path_;

0 commit comments

Comments
 (0)