[flang-commits] [flang] 1785392 - [flang] Correct implementation of WAIT with no ID

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Jun 16 10:00:51 PDT 2022


Author: Peter Klausler
Date: 2022-06-16T10:00:40-07:00
New Revision: 17853928a69b6efe7c3b2db8aba631edd3aa2ed8

URL: https://github.com/llvm/llvm-project/commit/17853928a69b6efe7c3b2db8aba631edd3aa2ed8
DIFF: https://github.com/llvm/llvm-project/commit/17853928a69b6efe7c3b2db8aba631edd3aa2ed8.diff

LOG: [flang] Correct implementation of WAIT with no ID

Previous one was returning a bogus error status about a bad WAIT
statement ID number.

Differential Revision: https://reviews.llvm.org/D127979

Added: 
    

Modified: 
    flang/runtime/io-api.cpp
    flang/runtime/unit.cpp
    flang/runtime/unit.h

Removed: 
    


################################################################################
diff  --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index c11e4271b20eb..d730dd844c2ac 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -400,7 +400,7 @@ Cookie IONAME(BeginWait)(ExternalUnit unitNumber, AsynchronousId id,
 }
 Cookie IONAME(BeginWaitAll)(
     ExternalUnit unitNumber, const char *sourceFile, int sourceLine) {
-  return IONAME(BeginWait)(unitNumber, 0 /*no ID=*/);
+  return IONAME(BeginWait)(unitNumber, 0 /*no ID=*/, sourceFile, sourceLine);
 }
 
 Cookie IONAME(BeginClose)(

diff  --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index 9cef0f5cb0afd..729bce8ddfa16 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -918,11 +918,13 @@ int ExternalFileUnit::GetAsynchronousId(IoErrorHandler &handler) {
 }
 
 bool ExternalFileUnit::Wait(int id) {
-  if (id < 0 || asyncIdAvailable_.test(id)) {
+  if (static_cast<std::size_t>(id) >= asyncIdAvailable_.size() ||
+      asyncIdAvailable_.test(id)) {
     return false;
   } else {
-    if (id == 0) {
+    if (id == 0) { // means "all IDs"
       asyncIdAvailable_.set();
+      asyncIdAvailable_.reset(0);
     } else {
       asyncIdAvailable_.set(id);
     }

diff  --git a/flang/runtime/unit.h b/flang/runtime/unit.h
index c58f71c00186f..03a4a44fa95af 100644
--- a/flang/runtime/unit.h
+++ b/flang/runtime/unit.h
@@ -39,6 +39,7 @@ class ExternalFileUnit : public ConnectionState,
   explicit ExternalFileUnit(int unitNumber) : unitNumber_{unitNumber} {
     isUTF8 = executionEnvironment.defaultUTF8;
     asyncIdAvailable_.set();
+    asyncIdAvailable_.reset(0);
   }
   ~ExternalFileUnit() {}
 


        


More information about the flang-commits mailing list