[flang-commits] [flang] [flang] Fix code that deletes unit from bad OPEN (PR #108994)
via flang-commits
flang-commits at lists.llvm.org
Tue Sep 17 08:38:37 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-runtime
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
When an OPEN statement fails, a unit that was created for the OPEN needs to be removed from the unit map. The code that tried to do this was incorrect -- it needs to re-acquire the unit via LookUpForClose as a CLOSE statement does. (The failure to do this completely was leaving a zombie unit active that could break a later OPEN on the same unit number.)
---
Full diff: https://github.com/llvm/llvm-project/pull/108994.diff
1 Files Affected:
- (modified) flang/runtime/io-stmt.cpp (+5-2)
``````````diff
diff --git a/flang/runtime/io-stmt.cpp b/flang/runtime/io-stmt.cpp
index 265bd0dc9d9499..cd7a196335d31e 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/flang/runtime/io-stmt.cpp
@@ -329,8 +329,11 @@ void OpenStatementState::CompleteOperation() {
}
if (!wasExtant_ && InError()) {
// Release the new unit on failure
- unit().CloseUnit(CloseStatus::Delete, *this);
- unit().DestroyClosed();
+ if (ExternalFileUnit *
+ toClose{unit().LookUpForClose(unit().unitNumber())}) {
+ toClose->Close(CloseStatus::Delete, *this);
+ toClose->DestroyClosed();
+ }
}
IoStatementBase::CompleteOperation();
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/108994
More information about the flang-commits
mailing list