Skip to content

Commit

Permalink
[flang] Catch bad OPEN(STATUS=) cases
Browse files Browse the repository at this point in the history
STATUS='NEW' and 'REPLACE' require FILE= to be present.
STATUS='SCRATCH' may not appear with FILE=.

These errors are caught at compilation time when constant character
strings are used in an OPEN statement, but the runtime needs
to enforce them as well to catch errors in OPEN statements
with character variables and expressions.

Differential Revision: https://reviews.llvm.org/D122509
  • Loading branch information
klausler committed Mar 26, 2022
1 parent 5576579 commit 435641b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions flang/runtime/io-stmt.cpp
Expand Up @@ -232,6 +232,14 @@ void OpenStatementState::CompleteOperation() {
position_.reset();
}
}
if (status_) { // 12.5.6.10
if ((*status_ == OpenStatus::New || *status_ == OpenStatus::Replace) &&
!path_.get()) {
SignalError("FILE= required on OPEN with STATUS='NEW' or 'REPLACE'");
} else if (*status_ == OpenStatus::Scratch && path_.get()) {
SignalError("FILE= may not appear on OPEN with STATUS='SCRATCH'");
}
}
if (path_.get() || wasExtant_ ||
(status_ && *status_ == OpenStatus::Scratch)) {
unit().OpenUnit(status_, action_, position_.value_or(Position::AsIs),
Expand Down

0 comments on commit 435641b

Please sign in to comment.