diff --git a/flang/runtime/environment.h b/flang/runtime/environment.h --- a/flang/runtime/environment.h +++ b/flang/runtime/environment.h @@ -37,9 +37,11 @@ int argc; const char **argv; const char **envp; - int listDirectedOutputLineLengthLimit; + + int listDirectedOutputLineLengthLimit; // FORT_FMT_RECL enum decimal::FortranRounding defaultOutputRoundingMode; - Convert conversion; + Convert conversion; // FORT_CONVERT + bool noStopMessage; // NO_STOP_MESSAGE=1 inhibits "Fortran STOP" }; extern ExecutionEnvironment executionEnvironment; } // namespace Fortran::runtime diff --git a/flang/runtime/environment.cpp b/flang/runtime/environment.cpp --- a/flang/runtime/environment.cpp +++ b/flang/runtime/environment.cpp @@ -67,6 +67,17 @@ } } + if (auto *x{std::getenv("NO_STOP_MESSAGE")}) { + char *end; + auto n{std::strtol(x, &end, 10)}; + if (n >= 0 && n <= 1 && *end == '\0') { + noStopMessage = n != 0; + } else { + std::fprintf(stderr, + "Fortran runtime: NO_STOP_MESSAGE=%s is invalid; ignored\n", x); + } + } + // TODO: Set RP/ROUND='PROCESSOR_DEFINED' from environment } diff --git a/flang/runtime/stop.cpp b/flang/runtime/stop.cpp --- a/flang/runtime/stop.cpp +++ b/flang/runtime/stop.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/stop.h" +#include "environment.h" #include "file.h" #include "io-error.h" #include "terminator.h" @@ -52,6 +53,9 @@ [[noreturn]] void RTNAME(StopStatement)( int code, bool isErrorStop, bool quiet) { CloseAllExternalUnits("STOP statement"); + if (Fortran::runtime::executionEnvironment.noStopMessage && code == 0) { + quiet = true; + } if (!quiet) { std::fprintf(stderr, "Fortran %s", isErrorStop ? "ERROR STOP" : "STOP"); if (code != EXIT_SUCCESS) {