[flang-commits] [flang] 4a0af82 - [flang] Respect NO_STOP_MESSAGE=1 in runtime
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Fri Nov 12 10:50:43 PST 2021
Author: Peter Klausler
Date: 2021-11-12T10:50:36-08:00
New Revision: 4a0af824ee22d21362b5e6eccdb38a666e2d9b27
URL: https://github.com/llvm/llvm-project/commit/4a0af824ee22d21362b5e6eccdb38a666e2d9b27
DIFF: https://github.com/llvm/llvm-project/commit/4a0af824ee22d21362b5e6eccdb38a666e2d9b27.diff
LOG: [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
Added:
Modified:
flang/runtime/environment.cpp
flang/runtime/environment.h
flang/runtime/stop.cpp
Removed:
################################################################################
diff --git a/flang/runtime/environment.cpp b/flang/runtime/environment.cpp
index 491906b0ff0f..53af239facea 100644
--- a/flang/runtime/environment.cpp
+++ b/flang/runtime/environment.cpp
@@ -67,6 +67,17 @@ void ExecutionEnvironment::Configure(
}
}
+ 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/environment.h b/flang/runtime/environment.h
index bc3a4e3dffe1..7db6cf3f5723 100644
--- a/flang/runtime/environment.h
+++ b/flang/runtime/environment.h
@@ -37,9 +37,11 @@ struct ExecutionEnvironment {
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/stop.cpp b/flang/runtime/stop.cpp
index 02779a857d26..765c4019fa5b 100644
--- 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 @@ static void CloseAllExternalUnits(const char *why) {
[[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) {
More information about the flang-commits
mailing list