[Openmp-commits] [openmp] b266bcb - [OpenMP] Implement __assert_fail in the new device runtime

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Fri Sep 17 18:25:57 PDT 2021


Author: Joseph Huber
Date: 2021-09-17T21:25:28-04:00
New Revision: b266bcb13557f6a9fcf58a2d2be271a631aee72f

URL: https://github.com/llvm/llvm-project/commit/b266bcb13557f6a9fcf58a2d2be271a631aee72f
DIFF: https://github.com/llvm/llvm-project/commit/b266bcb13557f6a9fcf58a2d2be271a631aee72f.diff

LOG: [OpenMP] Implement __assert_fail in the new device runtime

This patch implements the `__assert_fail` function in the new device
runtime. This allows users and developers to use the standars assert
function inside of the device.

Reviewed By: tianshilei1992

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/DeviceRTL/include/Debug.h b/openmp/libomptarget/DeviceRTL/include/Debug.h
index b304bff5302f..4e2a69937a9f 100644
--- a/openmp/libomptarget/DeviceRTL/include/Debug.h
+++ b/openmp/libomptarget/DeviceRTL/include/Debug.h
@@ -17,6 +17,8 @@
 /// {
 extern "C" {
 void __assert_assume(bool cond, const char *exp, const char *file, int line);
+void __assert_fail(const char *assertion, const char *file, unsigned line,
+                   const char *function);
 }
 
 #define ASSERT(e) __assert_assume(e, #e, __FILE__, __LINE__)

diff  --git a/openmp/libomptarget/DeviceRTL/src/Debug.cpp b/openmp/libomptarget/DeviceRTL/src/Debug.cpp
index 69d04d69604d..af78836ef0dd 100644
--- a/openmp/libomptarget/DeviceRTL/src/Debug.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Debug.cpp
@@ -26,6 +26,13 @@ void __assert_assume(bool cond, const char *exp, const char *file, int line) {
 
   __builtin_assume(cond);
 }
+
+void __assert_fail(const char *assertion, const char *file, unsigned line,
+                   const char *function) {
+  PRINTF("%s:%u: %s: Assertion `%s' failed.\n", file, line, function,
+         assertion);
+  __builtin_trap();
+}
 }
 
 #pragma omp end declare target


        


More information about the Openmp-commits mailing list