[flang-commits] [PATCH] D113701: [flang] Respect NO_STOP_MESSAGE=1 in runtime

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Nov 11 10:53:57 PST 2021


klausler created this revision.
klausler added a reviewer: jeanPerier.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.

When an environment variable NO_STOP_MESSAGE=1 is set,
assume that STOP statements with a successful code
have QUIET=.TRUE.


https://reviews.llvm.org/D113701

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


Index: flang/runtime/stop.cpp
===================================================================
--- flang/runtime/stop.cpp
+++ 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) {
Index: flang/runtime/environment.h
===================================================================
--- flang/runtime/environment.h
+++ 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
Index: flang/runtime/environment.cpp
===================================================================
--- flang/runtime/environment.cpp
+++ 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
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113701.386593.patch
Type: text/x-patch
Size: 1967 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20211111/dbbd8140/attachment-0001.bin>


More information about the flang-commits mailing list