diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp --- a/flang/runtime/io-api.cpp +++ b/flang/runtime/io-api.cpp @@ -400,7 +400,7 @@ } 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.h b/flang/runtime/unit.h --- a/flang/runtime/unit.h +++ b/flang/runtime/unit.h @@ -39,6 +39,7 @@ explicit ExternalFileUnit(int unitNumber) : unitNumber_{unitNumber} { isUTF8 = executionEnvironment.defaultUTF8; asyncIdAvailable_.set(); + asyncIdAvailable_.reset(0); } ~ExternalFileUnit() {} diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp --- a/flang/runtime/unit.cpp +++ b/flang/runtime/unit.cpp @@ -918,11 +918,13 @@ } 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); }