Skip to content

[flang][runtime] Don't crash on ASYNCHRONOUS='NO' in child I/O #124208

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
Jan 27, 2025

Conversation

klausler
Copy link
Contributor

When ASYNCHRONOUS='NO' appears in a data transfer statement control item list, don't crash if it isn't appropriate for the kind of I/O under way (such as child I/O).

Fixes #124135.

When ASYNCHRONOUS='NO' appears in a data transfer statement control
item list, don't crash if it isn't appropriate for the kind of I/O
under way (such as child I/O).

Fixes llvm#124135.
@klausler klausler requested a review from DanielCChen January 23, 2025 23:22
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Jan 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 23, 2025

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

Changes

When ASYNCHRONOUS='NO' appears in a data transfer statement control item list, don't crash if it isn't appropriate for the kind of I/O under way (such as child I/O).

Fixes #124135.


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

1 Files Affected:

  • (modified) flang/runtime/io-api.cpp (+8-8)
diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index 7023f61ba34de7..9dfa09ab332c2a 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -770,18 +770,18 @@ bool IODEF(SetAsynchronous)(
           "SetAsynchronous() called after GetNewUnit() for an OPEN statement");
     }
     open->unit().set_mayAsynchronous(isYes);
+  } else if (!isYes) {
+    // ASYNCHRONOUS='NO' is the default, so this is a no-op
   } else if (auto *ext{io.get_if<ExternalIoStatementBase>()}) {
-    if (isYes) {
-      if (ext->unit().mayAsynchronous()) {
-        ext->SetAsynchronous();
-      } else {
-        handler.SignalError(IostatBadAsynchronous);
-      }
+    if (ext->unit().mayAsynchronous()) {
+      ext->SetAsynchronous();
+    } else {
+      handler.SignalError(IostatBadAsynchronous);
     }
   } else if (!io.get_if<NoopStatementState>() &&
       !io.get_if<ErroneousIoStatementState>()) {
-    handler.Crash("SetAsynchronous() called when not in an OPEN or external "
-                  "I/O statement");
+    handler.Crash("SetAsynchronous('YES') called when not in an OPEN or "
+                  "external I/O statement");
   }
   return !handler.InError();
 }

Copy link
Contributor

@DanielCChen DanielCChen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Thanks for the quick fix!

@klausler klausler merged commit fee393e into llvm:main Jan 27, 2025
11 checks passed
@klausler klausler deleted the bug124135 branch January 27, 2025 16:59
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.

[Flang] User-defined READ/WRITE failed at SetAsynchronous() even though it has ASYNCHRONOUS=NO.
3 participants