Skip to content

Commit 4a0af82

Browse files
committed
[flang] Respect NO_STOP_MESSAGE=1 in runtime
When an environment variable NO_STOP_MESSAGE=1 is set, assume that STOP statements with a successful code have QUIET=.TRUE. Differential Revision: https://reviews.llvm.org/D113701
1 parent 3fb6416 commit 4a0af82

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

flang/runtime/environment.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ void ExecutionEnvironment::Configure(
6767
}
6868
}
6969

70+
if (auto *x{std::getenv("NO_STOP_MESSAGE")}) {
71+
char *end;
72+
auto n{std::strtol(x, &end, 10)};
73+
if (n >= 0 && n <= 1 && *end == '\0') {
74+
noStopMessage = n != 0;
75+
} else {
76+
std::fprintf(stderr,
77+
"Fortran runtime: NO_STOP_MESSAGE=%s is invalid; ignored\n", x);
78+
}
79+
}
80+
7081
// TODO: Set RP/ROUND='PROCESSOR_DEFINED' from environment
7182
}
7283

flang/runtime/environment.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ struct ExecutionEnvironment {
3737
int argc;
3838
const char **argv;
3939
const char **envp;
40-
int listDirectedOutputLineLengthLimit;
40+
41+
int listDirectedOutputLineLengthLimit; // FORT_FMT_RECL
4142
enum decimal::FortranRounding defaultOutputRoundingMode;
42-
Convert conversion;
43+
Convert conversion; // FORT_CONVERT
44+
bool noStopMessage; // NO_STOP_MESSAGE=1 inhibits "Fortran STOP"
4345
};
4446
extern ExecutionEnvironment executionEnvironment;
4547
} // namespace Fortran::runtime

flang/runtime/stop.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "flang/Runtime/stop.h"
10+
#include "environment.h"
1011
#include "file.h"
1112
#include "io-error.h"
1213
#include "terminator.h"
@@ -52,6 +53,9 @@ static void CloseAllExternalUnits(const char *why) {
5253
[[noreturn]] void RTNAME(StopStatement)(
5354
int code, bool isErrorStop, bool quiet) {
5455
CloseAllExternalUnits("STOP statement");
56+
if (Fortran::runtime::executionEnvironment.noStopMessage && code == 0) {
57+
quiet = true;
58+
}
5559
if (!quiet) {
5660
std::fprintf(stderr, "Fortran %s", isErrorStop ? "ERROR STOP" : "STOP");
5761
if (code != EXIT_SUCCESS) {

0 commit comments

Comments
 (0)