[flang] Respect NO_STOP_MESSAGE=1 in runtime
authorPeter Klausler <pklausler@nvidia.com>
Wed, 10 Nov 2021 19:55:46 +0000 (11:55 -0800)
committerPeter Klausler <pklausler@nvidia.com>
Fri, 12 Nov 2021 18:50:36 +0000 (10:50 -0800)
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

flang/runtime/environment.cpp
flang/runtime/environment.h
flang/runtime/stop.cpp

index 491906b0ff0f4bd76cfdd6ed0ec52aa8d2fceec9..53af239facea2d79e1a26cf9548220782bd5bf42 100644 (file)
@@ -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
 }
 
index bc3a4e3dffe1acb027963146194ef8ed9e5e7a71..7db6cf3f5723b76f12b99e41ff30d5ccddb0ee06 100644 (file)
@@ -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
index 02779a857d2626a17245d46ef4cdd5134b84cee5..765c4019fa5b459f0d461b2727be6416b332de7d 100644 (file)
@@ -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) {