diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp index c11e4271b20e..d730dd844c2a 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 9cef0f5cb0af..729bce8ddfa1 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(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 c58f71c00186..03a4a44fa95a 100644 --- a/flang/runtime/unit.h +++ b/flang/runtime/unit.h @@ -39,6 +39,7 @@ public: explicit ExternalFileUnit(int unitNumber) : unitNumber_{unitNumber} { isUTF8 = executionEnvironment.defaultUTF8; asyncIdAvailable_.set(); + asyncIdAvailable_.reset(0); } ~ExternalFileUnit() {}