Skip to content

[flang] Support read-only access to an anonymous unit #105859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

klausler
Copy link
Contributor

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

Don't require the "fort.123" file implicitly opened by READ(123, ...
to be writable.
@klausler klausler requested a review from vdonaldson August 23, 2024 17:13
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Aug 23, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 23, 2024

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

Changes

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

@klausler klausler merged commit 2326a02 into llvm:main Aug 26, 2024
11 checks passed
@klausler klausler deleted the bug1712 branch August 26, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants