[flang-commits] [flang] [flang][runtime] Ensure that the anonymous unit returned by LookUpOrCreateAnonymous has been opened. (PR #74468)
via flang-commits
flang-commits at lists.llvm.org
Tue Dec 5 07:46:01 PST 2023
https://github.com/sihuan updated https://github.com/llvm/llvm-project/pull/74468
>From 1c8022ca1aaf2af193e5bb2c89aedbd64ce34bfc Mon Sep 17 00:00:00 2001
From: SiHuaN <liyongtai at iscas.ac.cn>
Date: Tue, 5 Dec 2023 21:38:22 +0800
Subject: [PATCH 1/2] [flang][runtime] Ensure that the anonymous unit returned
by LookUpOrCreateAnonymous has been opened.
---
flang/runtime/unit.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index 995656b9480c4..fa9efee78127e 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -20,6 +20,7 @@ namespace Fortran::runtime::io {
// The per-unit data structures are created on demand so that Fortran I/O
// should work without a Fortran main program.
static Lock unitMapLock;
+static Lock createOpenLock;
static UnitMap *unitMap{nullptr};
static ExternalFileUnit *defaultInput{nullptr}; // unit 5
static ExternalFileUnit *defaultOutput{nullptr}; // unit 6
@@ -52,6 +53,9 @@ ExternalFileUnit *ExternalFileUnit::LookUpOrCreate(
ExternalFileUnit *ExternalFileUnit::LookUpOrCreateAnonymous(int unit,
Direction dir, std::optional<bool> isUnformatted,
const Terminator &terminator) {
+ // Make sure that the returned anonymous unit has been opened
+ // not just created in the unitmap.
+ CriticalSection critical{createOpenLock};
bool exists{false};
ExternalFileUnit *result{
GetUnitMap().LookUpOrCreate(unit, terminator, exists)};
>From 78269ad87441003fd7c6bd7ed2c5d73b55ced86a Mon Sep 17 00:00:00 2001
From: SiHuaN <liyongtai at iscas.ac.cn>
Date: Tue, 5 Dec 2023 23:45:38 +0800
Subject: [PATCH 2/2] fix typo
---
flang/runtime/unit.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index fa9efee78127e..5fa8565c2f61f 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -54,7 +54,7 @@ ExternalFileUnit *ExternalFileUnit::LookUpOrCreateAnonymous(int unit,
Direction dir, std::optional<bool> isUnformatted,
const Terminator &terminator) {
// Make sure that the returned anonymous unit has been opened
- // not just created in the unitmap.
+ // not just created in the unitMap.
CriticalSection critical{createOpenLock};
bool exists{false};
ExternalFileUnit *result{
More information about the flang-commits
mailing list