[Openmp-commits] [openmp] r340767 - [OpenMP][libomptarget] rework of fatal error reporting

Alexandre Eichenberger via Openmp-commits openmp-commits at lists.llvm.org
Mon Aug 27 11:20:15 PDT 2018


Author: alexeichenberger
Date: Mon Aug 27 11:20:15 2018
New Revision: 340767

URL: http://llvm.org/viewvc/llvm-project?rev=340767&view=rev
Log:
[OpenMP][libomptarget] rework of fatal error reporting

Summary:
Removed the function that used a lock and varargs
Used the same mechanism as for debug messages

Reviewers: ABataev, gtbercea, grokos, Hahnfeld

Reviewed By: gtbercea, Hahnfeld

Subscribers: mikerice, ABataev, RaviNarayanaswamy, guansong, openmp-commits

Differential Revision: https://reviews.llvm.org/D51226

Modified:
    openmp/trunk/libomptarget/src/interface.cpp
    openmp/trunk/libomptarget/src/omptarget.cpp
    openmp/trunk/libomptarget/src/private.h

Modified: openmp/trunk/libomptarget/src/interface.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/src/interface.cpp?rev=340767&r1=340766&r2=340767&view=diff
==============================================================================
--- openmp/trunk/libomptarget/src/interface.cpp (original)
+++ openmp/trunk/libomptarget/src/interface.cpp Mon Aug 27 11:20:15 2018
@@ -55,16 +55,16 @@ static void HandleTargetOutcome(bool suc
   switch (TargetOffloadPolicy) {
     case tgt_disabled:
       if (success) {
-        FatalMessage(1, "expected no offloading while offloading is disabled");
+        FATAL_MESSAGE0(1, "expected no offloading while offloading is disabled");
       }
       break;
     case tgt_default:
-      DP("Should never reach this test with target offload set to default\n");
-      assert(false);
+        FATAL_MESSAGE0(1, "default offloading policy must switched to " 
+            "mandatory or disabled");
       break;
     case tgt_mandatory:
       if (!success) {
-        FatalMessage(1, "failure of target construct while offloading is mandatory");
+        FATAL_MESSAGE0(1, "failure of target construct while offloading is mandatory");
       }
       break;
   }

Modified: openmp/trunk/libomptarget/src/omptarget.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/src/omptarget.cpp?rev=340767&r1=340766&r2=340767&view=diff
==============================================================================
--- openmp/trunk/libomptarget/src/omptarget.cpp (original)
+++ openmp/trunk/libomptarget/src/omptarget.cpp Mon Aug 27 11:20:15 2018
@@ -26,23 +26,6 @@
 int DebugLevel = 0;
 #endif // OMPTARGET_DEBUG
 
-////////////////////////////////////////////////////////////////////////////////
-/// support for fatal messages
-
-// mutex
-std::mutex LibomptargetPrintMtx;
-
-void FatalMessage(const int errorNum, const char *fmt, ...) {
-  va_list args;
-  va_start(args, fmt);
-  LibomptargetPrintMtx.lock();
-  fprintf(stderr, "Libomptarget error %d:", errorNum);
-  vfprintf(stderr, fmt, args);
-  fprintf(stderr, "\n");
-  LibomptargetPrintMtx.unlock();
-  va_end(args);
-  exit(1);
-}
 
 
 /* All begin addresses for partially mapped structs must be 8-aligned in order

Modified: openmp/trunk/libomptarget/src/private.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/src/private.h?rev=340767&r1=340766&r2=340767&view=diff
==============================================================================
--- openmp/trunk/libomptarget/src/private.h (original)
+++ openmp/trunk/libomptarget/src/private.h Mon Aug 27 11:20:15 2018
@@ -42,6 +42,23 @@ enum kmp_target_offload_kind {
 typedef enum kmp_target_offload_kind kmp_target_offload_kind_t;
 extern kmp_target_offload_kind_t TargetOffloadPolicy;
 
+////////////////////////////////////////////////////////////////////////////////
+// implemtation for fatal messages
+////////////////////////////////////////////////////////////////////////////////
+
+#define FATAL_MESSAGE0(_num, _str)                                    \
+  do {                                                                \
+    fprintf(stderr, "Libomptarget fatal error %d: %s\n", _num, _str); \
+    exit(1);                                                          \
+  } while (0)
+
+#define FATAL_MESSAGE(_num, _str, ...)                              \
+  do {                                                              \
+    fprintf(stderr, "Libomptarget fatal error %d:" _str "\n", _num, \
+            __VA_ARGS__);                                           \
+    exit(1);                                                        \
+  } while (0)
+
 // Implemented in libomp, they are called from within __tgt_* functions.
 #ifdef __cplusplus
 extern "C" {
@@ -54,8 +71,6 @@ int __kmpc_get_target_offload(void) __at
 }
 #endif
 
-void FatalMessage(const int errorNum, const char *fmt, ...);
-
 #ifdef OMPTARGET_DEBUG
 extern int DebugLevel;
 




More information about the Openmp-commits mailing list