[flang-commits] [flang] 435641b - [flang] Catch bad OPEN(STATUS=) cases
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Fri Mar 25 18:24:58 PDT 2022
Author: Peter Klausler
Date: 2022-03-25T18:24:50-07:00
New Revision: 435641bc3d8e7cd9acb6efeacd32962e2cc167cc
URL: https://github.com/llvm/llvm-project/commit/435641bc3d8e7cd9acb6efeacd32962e2cc167cc
DIFF: https://github.com/llvm/llvm-project/commit/435641bc3d8e7cd9acb6efeacd32962e2cc167cc.diff
LOG: [flang] Catch bad OPEN(STATUS=) cases
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
Added:
Modified:
flang/runtime/io-stmt.cpp
Removed:
################################################################################
diff --git a/flang/runtime/io-stmt.cpp b/flang/runtime/io-stmt.cpp
index ade7f9cb4a59c..0f51d24ed1c2c 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/flang/runtime/io-stmt.cpp
@@ -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),
More information about the flang-commits
mailing list