[flang-commits] [flang] [flang][runtime] Enable more code for offload device builds. (PR #67489)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Sep 26 14:45:50 PDT 2023


================
@@ -12,26 +12,47 @@
 
 namespace Fortran::runtime {
 
-[[noreturn]] void Terminator::Crash(const char *message, ...) const {
-  va_list ap;
-  va_start(ap, message);
-  CrashArgs(message, ap);
-  va_end(ap);
-}
-
-static void (*crashHandler)(const char *, int, const char *, va_list &){
+#if !defined(RT_DEVICE_COMPILATION)
+[[maybe_unused]] static void (*crashHandler)(const char *, int, const char *, va_list &){
     nullptr};
 
 void Terminator::RegisterCrashHandler(
     void (*handler)(const char *, int, const char *, va_list &)) {
   crashHandler = handler;
 }
 
-[[noreturn]] void Terminator::CrashArgs(
-    const char *message, va_list &ap) const {
+void Terminator::InvokeCrashHandler(const char *message, ...) const {
   if (crashHandler) {
+    va_list ap;
+    va_start(ap, message);
     crashHandler(sourceFileName_, sourceLine_, message, ap);
+    va_end(ap);
+  }
+}
+
+[[noreturn]] void Terminator::CrashArgs(
+    const char *message, va_list &ap) const {
+  CrashHeader();
+  std::vfprintf(stderr, message, ap);
+  va_end(ap);
+  CrashFooter();
+}
+#endif
+
+RT_OFFLOAD_API_GROUP_BEGIN
+
+RT_API_ATTRS void Terminator::CrashHeader() const {
+#if defined(RT_DEVICE_COMPILATION)
+  std::printf("\nfatal Fortran runtime error");
----------------
klausler wrote:

Am I misreading the new code?  `CrashArgs()` calls `CrashHeader()` & `CrashFooter()` and they write to stdout.  But the `vfprintf()` writes to stderr.  Is that not a problem?

https://github.com/llvm/llvm-project/pull/67489


More information about the flang-commits mailing list