[flang-commits] [flang] [flang] Support read-only access to an anonymous unit (PR #105859)

via flang-commits flang-commits at lists.llvm.org
Fri Aug 23 10:13:48 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

Don't require the "fort.123" file implicitly opened by READ(123, ... to be writable.

---
Full diff: https://github.com/llvm/llvm-project/pull/105859.diff


1 Files Affected:

- (modified) flang/runtime/external-unit.cpp (+5-1) 


``````````diff
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();

``````````

</details>


https://github.com/llvm/llvm-project/pull/105859


More information about the flang-commits mailing list