[flang-commits] [flang] 9ddd079 - [flang] Handle FLUSH(unknown unit)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Thu Jan 20 15:38:34 PST 2022
Author: Peter Klausler
Date: 2022-01-20T15:35:34-08:00
New Revision: 9ddd07922f65ec7b633228b8b71076031355937e
URL: https://github.com/llvm/llvm-project/commit/9ddd07922f65ec7b633228b8b71076031355937e
DIFF: https://github.com/llvm/llvm-project/commit/9ddd07922f65ec7b633228b8b71076031355937e.diff
LOG: [flang] Handle FLUSH(unknown unit)
The unit number passed to a FLUSH statement is not required to
be a valid open unit; nothing happens (esp. not the creation of
an empty fort.n file) in this case.
Differential Revision: https://reviews.llvm.org/D117819
Added:
Modified:
flang/runtime/io-api.cpp
flang/runtime/io-stmt.h
Removed:
################################################################################
diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index 2f12bfcad350d..03c878d1a8506 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -317,7 +317,7 @@ Cookie IONAME(BeginClose)(
} 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(BeginClose)(
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 @@ bool IONAME(SetStatus)(Cookie cookie, const char *keyword, std::size_t length) {
}
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
index bf84f4a3369a0..8327326c7f9ef 100644
--- a/flang/runtime/io-stmt.h
+++ b/flang/runtime/io-stmt.h
@@ -34,7 +34,7 @@ class InquireUnconnectedFileState;
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 @@ class IoStatementState {
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 @@ class NoUnitIoStatementState : public IoStatementBase {
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
};
More information about the flang-commits
mailing list