[memprof] Upgrade a unit test to MemProf Version 3 (#117063)
[llvm-project.git] / openmp / runtime / src / kmp_debug.h
blob08d52cc04a108d96a31fb60f7d738c14b01eebaa
1 /*
2 * kmp_debug.h -- debug / assertion code for Assure library
3 */
5 //===----------------------------------------------------------------------===//
6 //
7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 // See https://llvm.org/LICENSE.txt for license information.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11 //===----------------------------------------------------------------------===//
13 #ifndef KMP_DEBUG_H
14 #define KMP_DEBUG_H
16 #include <stdarg.h>
18 #ifdef __cplusplus
19 extern "C" {
20 #endif // __cplusplus
22 // -----------------------------------------------------------------------------
23 // Build-time assertion.
25 // New C++11 style build assert
26 #define KMP_BUILD_ASSERT(expr) static_assert(expr, "Build condition error")
28 // -----------------------------------------------------------------------------
29 // Run-time assertions.
31 extern void __kmp_dump_debug_buffer(void);
33 #ifdef KMP_USE_ASSERT
34 extern int __kmp_debug_assert(char const *expr, char const *file, int line);
35 #ifdef KMP_DEBUG
36 #define KMP_ASSERT(cond) \
37 if (!(cond)) { \
38 __kmp_debug_assert(#cond, __FILE__, __LINE__); \
40 #define KMP_ASSERT2(cond, msg) \
41 if (!(cond)) { \
42 __kmp_debug_assert((msg), __FILE__, __LINE__); \
44 #define KMP_DEBUG_ASSERT(cond) KMP_ASSERT(cond)
45 #define KMP_DEBUG_ASSERT2(cond, msg) KMP_ASSERT2(cond, msg)
46 #define KMP_DEBUG_USE_VAR(x) /* Nothing (it is used!) */
47 #else
48 // Do not expose condition in release build. Use "assertion failure".
49 #define KMP_ASSERT(cond) \
50 if (!(cond)) { \
51 __kmp_debug_assert("assertion failure", __FILE__, __LINE__); \
53 #define KMP_ASSERT2(cond, msg) KMP_ASSERT(cond)
54 #define KMP_DEBUG_ASSERT(cond) /* Nothing */
55 #define KMP_DEBUG_ASSERT2(cond, msg) /* Nothing */
56 #define KMP_DEBUG_USE_VAR(x) ((void)(x))
57 #endif // KMP_DEBUG
58 #else
59 #define KMP_ASSERT(cond) /* Nothing */
60 #define KMP_ASSERT2(cond, msg) /* Nothing */
61 #define KMP_DEBUG_ASSERT(cond) /* Nothing */
62 #define KMP_DEBUG_ASSERT2(cond, msg) /* Nothing */
63 #define KMP_DEBUG_USE_VAR(x) ((void)(x))
64 #endif // KMP_USE_ASSERT
66 #ifdef KMP_DEBUG
67 extern void __kmp_debug_printf_stdout(char const *format, ...);
68 #endif
69 extern void __kmp_debug_printf(char const *format, ...);
71 #ifdef KMP_DEBUG
73 extern int kmp_a_debug;
74 extern int kmp_b_debug;
75 extern int kmp_c_debug;
76 extern int kmp_d_debug;
77 extern int kmp_e_debug;
78 extern int kmp_f_debug;
79 extern int kmp_diag;
81 #define KA_TRACE(d, x) \
82 if (kmp_a_debug >= d) { \
83 __kmp_debug_printf x; \
85 #define KB_TRACE(d, x) \
86 if (kmp_b_debug >= d) { \
87 __kmp_debug_printf x; \
89 #define KC_TRACE(d, x) \
90 if (kmp_c_debug >= d) { \
91 __kmp_debug_printf x; \
93 #define KD_TRACE(d, x) \
94 if (kmp_d_debug >= d) { \
95 __kmp_debug_printf x; \
97 #define KE_TRACE(d, x) \
98 if (kmp_e_debug >= d) { \
99 __kmp_debug_printf x; \
101 #define KF_TRACE(d, x) \
102 if (kmp_f_debug >= d) { \
103 __kmp_debug_printf x; \
105 #define K_DIAG(d, x) \
107 if (kmp_diag == d) { \
108 __kmp_debug_printf_stdout x; \
112 #define KA_DUMP(d, x) \
113 if (kmp_a_debug >= d) { \
114 int ks; \
115 __kmp_disable(&ks); \
116 (x); \
117 __kmp_enable(ks); \
119 #define KB_DUMP(d, x) \
120 if (kmp_b_debug >= d) { \
121 int ks; \
122 __kmp_disable(&ks); \
123 (x); \
124 __kmp_enable(ks); \
126 #define KC_DUMP(d, x) \
127 if (kmp_c_debug >= d) { \
128 int ks; \
129 __kmp_disable(&ks); \
130 (x); \
131 __kmp_enable(ks); \
133 #define KD_DUMP(d, x) \
134 if (kmp_d_debug >= d) { \
135 int ks; \
136 __kmp_disable(&ks); \
137 (x); \
138 __kmp_enable(ks); \
140 #define KE_DUMP(d, x) \
141 if (kmp_e_debug >= d) { \
142 int ks; \
143 __kmp_disable(&ks); \
144 (x); \
145 __kmp_enable(ks); \
147 #define KF_DUMP(d, x) \
148 if (kmp_f_debug >= d) { \
149 int ks; \
150 __kmp_disable(&ks); \
151 (x); \
152 __kmp_enable(ks); \
155 #else
157 #define KA_TRACE(d, x) /* nothing to do */
158 #define KB_TRACE(d, x) /* nothing to do */
159 #define KC_TRACE(d, x) /* nothing to do */
160 #define KD_TRACE(d, x) /* nothing to do */
161 #define KE_TRACE(d, x) /* nothing to do */
162 #define KF_TRACE(d, x) /* nothing to do */
163 #define K_DIAG(d, x) \
164 {} /* nothing to do */
166 #define KA_DUMP(d, x) /* nothing to do */
167 #define KB_DUMP(d, x) /* nothing to do */
168 #define KC_DUMP(d, x) /* nothing to do */
169 #define KD_DUMP(d, x) /* nothing to do */
170 #define KE_DUMP(d, x) /* nothing to do */
171 #define KF_DUMP(d, x) /* nothing to do */
173 #endif // KMP_DEBUG
175 #ifdef __cplusplus
176 } // extern "C"
177 #endif // __cplusplus
179 #endif /* KMP_DEBUG_H */