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

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Tue Sep 26 14:43:12 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");
----------------
vzakhari wrote:

I had to comment out `Terminator::CrashArgs` for the device compilation (with `#if !defined(RT_DEVICE_COMPILATION)` at line 15), since neither `stderr` nor `va_list` are supported.  There are direct uses of `CrashArgs` in not yet enabled parts of the library, and I will have to deal with them as well.

Note that the `crashHandler` support is also not enabled for the device compilation.  It seems to be used only for in-tree testing, so I thought it would not be a problem (at least for now).

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


More information about the flang-commits mailing list