[flang-commits] [flang] [flang] Support read-only access to an anonymous unit (PR #105859)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Fri Aug 23 10:13:12 PDT 2024
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/105859
Don't require the "fort.123" file implicitly opened by READ(123, ... to be writable.
>From 88c7779d2830360020af1fe1a54a63a95155fc9c Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Fri, 23 Aug 2024 09:54:32 -0700
Subject: [PATCH] [flang] Support read-only access to an anonymous unit
Don't require the "fort.123" file implicitly opened by READ(123, ...
to be writable.
---
flang/runtime/external-unit.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/flang/runtime/external-unit.cpp b/flang/runtime/external-unit.cpp
index 8009151a8a370c..d17a92622f8448 100644
--- a/flang/runtime/external-unit.cpp
+++ b/flang/runtime/external-unit.cpp
@@ -65,9 +65,13 @@ ExternalFileUnit *ExternalFileUnit::LookUpOrCreateAnonymous(int unit,
bool exists{false};
ExternalFileUnit *result{GetUnitMap().LookUpOrCreate(unit, handler, exists)};
if (result && !exists) {
+ common::optional<Action> action;
+ if (dir == Direction::Output) {
+ action = Action::ReadWrite;
+ }
if (!result->OpenAnonymousUnit(
dir == Direction::Input ? OpenStatus::Unknown : OpenStatus::Replace,
- Action::ReadWrite, Position::Rewind, Convert::Unknown, handler)) {
+ action, Position::Rewind, Convert::Unknown, handler)) {
// fort.N isn't a writable file
if (ExternalFileUnit * closed{LookUpForClose(result->unitNumber())}) {
closed->DestroyClosed();
More information about the flang-commits
mailing list