[Openmp-commits] [PATCH] D112842: [OpenMP] Use the assertion formatting from assert.h

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Fri Oct 29 13:30:13 PDT 2021


jhuber6 updated this revision to Diff 383487.
jhuber6 added a comment.

Changing to use `assert_fail` to avoid duplicatio.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112842/new/

https://reviews.llvm.org/D112842

Files:
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/src/Debug.cpp


Index: openmp/libomptarget/DeviceRTL/src/Debug.cpp
===================================================================
--- openmp/libomptarget/DeviceRTL/src/Debug.cpp
+++ openmp/libomptarget/DeviceRTL/src/Debug.cpp
@@ -21,14 +21,7 @@
 #pragma omp declare target
 
 extern "C" {
-void __assert_assume(bool cond, const char *exp, const char *file, int line) {
-  if (!cond && config::isDebugMode(config::DebugKind::Assertion)) {
-    PRINTF("ASSERTION failed: %s at %s, line %d\n", exp, file, line);
-    __builtin_trap();
-  }
-
-  __builtin_assume(cond);
-}
+void __assert_assume(bool condition) { __builtin_assume(condition); }
 
 void __assert_fail(const char *assertion, const char *file, unsigned line,
                    const char *function) {
Index: openmp/libomptarget/DeviceRTL/include/Debug.h
===================================================================
--- openmp/libomptarget/DeviceRTL/include/Debug.h
+++ openmp/libomptarget/DeviceRTL/include/Debug.h
@@ -12,16 +12,24 @@
 #ifndef OMPTARGET_DEVICERTL_DEBUG_H
 #define OMPTARGET_DEVICERTL_DEBUG_H
 
+#include "Configuration.h"
+
 /// Assertion
 ///
 /// {
 extern "C" {
-void __assert_assume(bool cond, const char *exp, const char *file, int line);
+void __assert_assume(bool condition);
 void __assert_fail(const char *assertion, const char *file, unsigned line,
                    const char *function);
 }
 
-#define ASSERT(e) __assert_assume(e, #e, __FILE__, __LINE__)
+#define ASSERT(expr)                                                           \
+  {                                                                            \
+    if (config::isDebugMode(config::DebugKind::Assertion) && !expr)            \
+      __assert_fail(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__);           \
+    else                                                                       \
+      __assert_assume(expr);                                                   \
+  }
 
 ///}
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112842.383487.patch
Type: text/x-patch
Size: 1950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20211029/a5f0e6c7/attachment-0001.bin>


More information about the Openmp-commits mailing list