Skip to content

Move deallocation of I/O resources under STOP to a critical section #74181

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions flang/runtime/stop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cstdio>
#include <cstdlib>

static Fortran::runtime::Lock lock;
extern "C" {

static void DescribeIEEESignaledExceptions() {
Expand Down Expand Up @@ -52,7 +53,8 @@ static void CloseAllExternalUnits(const char *why) {

[[noreturn]] void RTNAME(StopStatement)(
int code, bool isErrorStop, bool quiet) {
CloseAllExternalUnits("STOP statement");

Fortran::runtime::CriticalSection critical{lock};
if (Fortran::runtime::executionEnvironment.noStopMessage && code == 0) {
quiet = true;
}
Expand All @@ -64,12 +66,13 @@ static void CloseAllExternalUnits(const char *why) {
std::fputc('\n', stderr);
DescribeIEEESignaledExceptions();
}
CloseAllExternalUnits("STOP statement");
std::exit(code);
}

[[noreturn]] void RTNAME(StopStatementText)(
const char *code, std::size_t length, bool isErrorStop, bool quiet) {
CloseAllExternalUnits("STOP statement");
Fortran::runtime::CriticalSection critical{lock};
if (!quiet) {
if (Fortran::runtime::executionEnvironment.noStopMessage && !isErrorStop) {
std::fprintf(stderr, "%.*s\n", static_cast<int>(length), code);
Expand All @@ -79,6 +82,7 @@ static void CloseAllExternalUnits(const char *why) {
}
DescribeIEEESignaledExceptions();
}
CloseAllExternalUnits("STOP statement");
if (isErrorStop) {
std::exit(EXIT_FAILURE);
} else {
Expand Down