/home/arjun/llvm-project/llvm/include/llvm/Support/Compiler.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- llvm/Support/Compiler.h - Compiler abstraction support --*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file defines several macros, based on the current compiler. This allows |
10 | | // use of compiler-specific features in a way that remains portable. This header |
11 | | // can be included from either C or C++. |
12 | | // |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | #ifndef LLVM_SUPPORT_COMPILER_H |
16 | | #define LLVM_SUPPORT_COMPILER_H |
17 | | |
18 | | #include "llvm/Config/llvm-config.h" |
19 | | |
20 | | #ifdef __cplusplus |
21 | | #include <new> |
22 | | #endif |
23 | | #include <stddef.h> |
24 | | |
25 | | #if defined(_MSC_VER) |
26 | | #include <sal.h> |
27 | | #endif |
28 | | |
29 | | #ifndef __has_feature |
30 | | # define __has_feature(x) 0 |
31 | | #endif |
32 | | |
33 | | #ifndef __has_extension |
34 | | # define __has_extension(x) 0 |
35 | | #endif |
36 | | |
37 | | #ifndef __has_attribute |
38 | | # define __has_attribute(x) 0 |
39 | | #endif |
40 | | |
41 | | #ifndef __has_builtin |
42 | | # define __has_builtin(x) 0 |
43 | | #endif |
44 | | |
45 | | // Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in |
46 | | // C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid. |
47 | | #ifndef LLVM_HAS_CPP_ATTRIBUTE |
48 | | #if defined(__cplusplus) && defined(__has_cpp_attribute) |
49 | | # define LLVM_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) |
50 | | #else |
51 | | # define LLVM_HAS_CPP_ATTRIBUTE(x) 0 |
52 | | #endif |
53 | | #endif |
54 | | |
55 | | /// \macro LLVM_GNUC_PREREQ |
56 | | /// Extend the default __GNUC_PREREQ even if glibc's features.h isn't |
57 | | /// available. |
58 | | #ifndef LLVM_GNUC_PREREQ |
59 | | # if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) |
60 | | # define LLVM_GNUC_PREREQ(maj, min, patch) \ |
61 | | ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \ |
62 | | ((maj) << 20) + ((min) << 10) + (patch)) |
63 | | # elif defined(__GNUC__) && defined(__GNUC_MINOR__) |
64 | | # define LLVM_GNUC_PREREQ(maj, min, patch) \ |
65 | | ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10)) |
66 | | # else |
67 | | # define LLVM_GNUC_PREREQ(maj, min, patch) 0 |
68 | | # endif |
69 | | #endif |
70 | | |
71 | | /// \macro LLVM_MSC_PREREQ |
72 | | /// Is the compiler MSVC of at least the specified version? |
73 | | /// The common \param version values to check for are: |
74 | | /// * 1910: VS2017, version 15.1 & 15.2 |
75 | | /// * 1911: VS2017, version 15.3 & 15.4 |
76 | | /// * 1912: VS2017, version 15.5 |
77 | | /// * 1913: VS2017, version 15.6 |
78 | | /// * 1914: VS2017, version 15.7 |
79 | | /// * 1915: VS2017, version 15.8 |
80 | | /// * 1916: VS2017, version 15.9 |
81 | | /// * 1920: VS2019, version 16.0 |
82 | | /// * 1921: VS2019, version 16.1 |
83 | | #ifdef _MSC_VER |
84 | | #define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version)) |
85 | | |
86 | | // We require at least MSVC 2017. |
87 | | #if !LLVM_MSC_PREREQ(1910) |
88 | | #error LLVM requires at least MSVC 2017. |
89 | | #endif |
90 | | |
91 | | #else |
92 | | #define LLVM_MSC_PREREQ(version) 0 |
93 | | #endif |
94 | | |
95 | | /// Does the compiler support ref-qualifiers for *this? |
96 | | /// |
97 | | /// Sadly, this is separate from just rvalue reference support because GCC |
98 | | /// and MSVC implemented this later than everything else. This appears to be |
99 | | /// corrected in MSVC 2019 but not MSVC 2017. |
100 | | #if __has_feature(cxx_rvalue_references) || LLVM_GNUC_PREREQ(4, 8, 1) |
101 | | #define LLVM_HAS_RVALUE_REFERENCE_THIS 1 |
102 | | #else |
103 | | #define LLVM_HAS_RVALUE_REFERENCE_THIS 0 |
104 | | #endif |
105 | | |
106 | | /// Expands to '&' if ref-qualifiers for *this are supported. |
107 | | /// |
108 | | /// This can be used to provide lvalue/rvalue overrides of member functions. |
109 | | /// The rvalue override should be guarded by LLVM_HAS_RVALUE_REFERENCE_THIS |
110 | | #if LLVM_HAS_RVALUE_REFERENCE_THIS |
111 | | #define LLVM_LVALUE_FUNCTION & |
112 | | #else |
113 | | #define LLVM_LVALUE_FUNCTION |
114 | | #endif |
115 | | |
116 | | /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked |
117 | | /// into a shared library, then the class should be private to the library and |
118 | | /// not accessible from outside it. Can also be used to mark variables and |
119 | | /// functions, making them private to any shared library they are linked into. |
120 | | /// On PE/COFF targets, library visibility is the default, so this isn't needed. |
121 | | /// |
122 | | /// LLVM_EXTERNAL_VISIBILITY - classes, functions, and variables marked with |
123 | | /// this attribute will be made public and visible outside of any shared library |
124 | | /// they are linked in to. |
125 | | #if (__has_attribute(visibility) || LLVM_GNUC_PREREQ(4, 0, 0)) && \ |
126 | | !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32) |
127 | | #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden"))) |
128 | | #define LLVM_EXTERNAL_VISIBILITY __attribute__ ((visibility("default"))) |
129 | | #else |
130 | | #define LLVM_LIBRARY_VISIBILITY |
131 | | #define LLVM_EXTERNAL_VISIBILITY |
132 | | #endif |
133 | | |
134 | | #if defined(__GNUC__) |
135 | | #define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality) |
136 | | #else |
137 | | #define LLVM_PREFETCH(addr, rw, locality) |
138 | | #endif |
139 | | |
140 | | #if __has_attribute(used) || LLVM_GNUC_PREREQ(3, 1, 0) |
141 | | #define LLVM_ATTRIBUTE_USED __attribute__((__used__)) |
142 | | #else |
143 | | #define LLVM_ATTRIBUTE_USED |
144 | | #endif |
145 | | |
146 | | /// LLVM_NODISCARD - Warn if a type or return value is discarded. |
147 | | |
148 | | // Use the 'nodiscard' attribute in C++17 or newer mode. |
149 | | #if __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(nodiscard) |
150 | | #define LLVM_NODISCARD [[nodiscard]] |
151 | | #elif LLVM_HAS_CPP_ATTRIBUTE(clang::warn_unused_result) |
152 | | #define LLVM_NODISCARD [[clang::warn_unused_result]] |
153 | | // Clang in C++14 mode claims that it has the 'nodiscard' attribute, but also |
154 | | // warns in the pedantic mode that 'nodiscard' is a C++17 extension (PR33518). |
155 | | // Use the 'nodiscard' attribute in C++14 mode only with GCC. |
156 | | // TODO: remove this workaround when PR33518 is resolved. |
157 | | #elif defined(__GNUC__) && LLVM_HAS_CPP_ATTRIBUTE(nodiscard) |
158 | | #define LLVM_NODISCARD [[nodiscard]] |
159 | | #else |
160 | | #define LLVM_NODISCARD |
161 | | #endif |
162 | | |
163 | | // Indicate that a non-static, non-const C++ member function reinitializes |
164 | | // the entire object to a known state, independent of the previous state of |
165 | | // the object. |
166 | | // |
167 | | // The clang-tidy check bugprone-use-after-move recognizes this attribute as a |
168 | | // marker that a moved-from object has left the indeterminate state and can be |
169 | | // reused. |
170 | | #if LLVM_HAS_CPP_ATTRIBUTE(clang::reinitializes) |
171 | | #define LLVM_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]] |
172 | | #else |
173 | | #define LLVM_ATTRIBUTE_REINITIALIZES |
174 | | #endif |
175 | | |
176 | | // Some compilers warn about unused functions. When a function is sometimes |
177 | | // used or not depending on build settings (e.g. a function only called from |
178 | | // within "assert"), this attribute can be used to suppress such warnings. |
179 | | // |
180 | | // However, it shouldn't be used for unused *variables*, as those have a much |
181 | | // more portable solution: |
182 | | // (void)unused_var_name; |
183 | | // Prefer cast-to-void wherever it is sufficient. |
184 | | #if __has_attribute(unused) || LLVM_GNUC_PREREQ(3, 1, 0) |
185 | | #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__)) |
186 | | #else |
187 | | #define LLVM_ATTRIBUTE_UNUSED |
188 | | #endif |
189 | | |
190 | | // FIXME: Provide this for PE/COFF targets. |
191 | | #if (__has_attribute(weak) || LLVM_GNUC_PREREQ(4, 0, 0)) && \ |
192 | | (!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32)) |
193 | | #define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__)) |
194 | | #else |
195 | | #define LLVM_ATTRIBUTE_WEAK |
196 | | #endif |
197 | | |
198 | | // Prior to clang 3.2, clang did not accept any spelling of |
199 | | // __has_attribute(const), so assume it is supported. |
200 | | #if defined(__clang__) || defined(__GNUC__) |
201 | | // aka 'CONST' but following LLVM Conventions. |
202 | | #define LLVM_READNONE __attribute__((__const__)) |
203 | | #else |
204 | | #define LLVM_READNONE |
205 | | #endif |
206 | | |
207 | | #if __has_attribute(pure) || defined(__GNUC__) |
208 | | // aka 'PURE' but following LLVM Conventions. |
209 | | #define LLVM_READONLY __attribute__((__pure__)) |
210 | | #else |
211 | | #define LLVM_READONLY |
212 | | #endif |
213 | | |
214 | | #if __has_builtin(__builtin_expect) || LLVM_GNUC_PREREQ(4, 0, 0) |
215 | 96 | #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true) |
216 | 6.98k | #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false) |
217 | | #else |
218 | | #define LLVM_LIKELY(EXPR) (EXPR) |
219 | | #define LLVM_UNLIKELY(EXPR) (EXPR) |
220 | | #endif |
221 | | |
222 | | /// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, |
223 | | /// mark a method "not for inlining". |
224 | | #if __has_attribute(noinline) || LLVM_GNUC_PREREQ(3, 4, 0) |
225 | | #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline)) |
226 | | #elif defined(_MSC_VER) |
227 | | #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline) |
228 | | #else |
229 | | #define LLVM_ATTRIBUTE_NOINLINE |
230 | | #endif |
231 | | |
232 | | /// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do |
233 | | /// so, mark a method "always inline" because it is performance sensitive. GCC |
234 | | /// 3.4 supported this but is buggy in various cases and produces unimplemented |
235 | | /// errors, just use it in GCC 4.0 and later. |
236 | | #if __has_attribute(always_inline) || LLVM_GNUC_PREREQ(4, 0, 0) |
237 | | #define LLVM_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline)) |
238 | | #elif defined(_MSC_VER) |
239 | | #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline |
240 | | #else |
241 | | #define LLVM_ATTRIBUTE_ALWAYS_INLINE |
242 | | #endif |
243 | | |
244 | | #ifdef __GNUC__ |
245 | | #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn)) |
246 | | #elif defined(_MSC_VER) |
247 | | #define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn) |
248 | | #else |
249 | | #define LLVM_ATTRIBUTE_NORETURN |
250 | | #endif |
251 | | |
252 | | #if __has_attribute(returns_nonnull) || LLVM_GNUC_PREREQ(4, 9, 0) |
253 | | #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) |
254 | | #elif defined(_MSC_VER) |
255 | | #define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_ |
256 | | #else |
257 | | #define LLVM_ATTRIBUTE_RETURNS_NONNULL |
258 | | #endif |
259 | | |
260 | | /// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a |
261 | | /// pointer that does not alias any other valid pointer. |
262 | | #ifdef __GNUC__ |
263 | | #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) |
264 | | #elif defined(_MSC_VER) |
265 | | #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict) |
266 | | #else |
267 | | #define LLVM_ATTRIBUTE_RETURNS_NOALIAS |
268 | | #endif |
269 | | |
270 | | /// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements. |
271 | | #if __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough) |
272 | | #define LLVM_FALLTHROUGH [[fallthrough]] |
273 | | #elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough) |
274 | | #define LLVM_FALLTHROUGH [[gnu::fallthrough]] |
275 | | #elif __has_attribute(fallthrough) |
276 | | #define LLVM_FALLTHROUGH __attribute__((fallthrough)) |
277 | | #elif LLVM_HAS_CPP_ATTRIBUTE(clang::fallthrough) |
278 | 36 | #define LLVM_FALLTHROUGH [[clang::fallthrough]] |
279 | | #else |
280 | | #define LLVM_FALLTHROUGH |
281 | | #endif |
282 | | |
283 | | /// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that |
284 | | /// they are constant initialized. |
285 | | #if LLVM_HAS_CPP_ATTRIBUTE(clang::require_constant_initialization) |
286 | | #define LLVM_REQUIRE_CONSTANT_INITIALIZATION \ |
287 | | [[clang::require_constant_initialization]] |
288 | | #else |
289 | | #define LLVM_REQUIRE_CONSTANT_INITIALIZATION |
290 | | #endif |
291 | | |
292 | | /// LLVM_GSL_OWNER - Apply this to owning classes like SmallVector to enable |
293 | | /// lifetime warnings. |
294 | | #if LLVM_HAS_CPP_ATTRIBUTE(gsl::Owner) |
295 | | #define LLVM_GSL_OWNER [[gsl::Owner]] |
296 | | #else |
297 | | #define LLVM_GSL_OWNER |
298 | | #endif |
299 | | |
300 | | /// LLVM_GSL_POINTER - Apply this to non-owning classes like |
301 | | /// StringRef to enable lifetime warnings. |
302 | | #if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer) |
303 | | #define LLVM_GSL_POINTER [[gsl::Pointer]] |
304 | | #else |
305 | | #define LLVM_GSL_POINTER |
306 | | #endif |
307 | | |
308 | | /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress |
309 | | /// pedantic diagnostics. |
310 | | #ifdef __GNUC__ |
311 | 0 | #define LLVM_EXTENSION __extension__ |
312 | | #else |
313 | | #define LLVM_EXTENSION |
314 | | #endif |
315 | | |
316 | | // LLVM_ATTRIBUTE_DEPRECATED(decl, "message") |
317 | | #if __has_feature(attribute_deprecated_with_message) |
318 | | # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \ |
319 | | decl __attribute__((deprecated(message))) |
320 | | #elif defined(__GNUC__) |
321 | | # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \ |
322 | | decl __attribute__((deprecated)) |
323 | | #elif defined(_MSC_VER) |
324 | | # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \ |
325 | | __declspec(deprecated(message)) decl |
326 | | #else |
327 | | # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \ |
328 | | decl |
329 | | #endif |
330 | | |
331 | | /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands |
332 | | /// to an expression which states that it is undefined behavior for the |
333 | | /// compiler to reach this point. Otherwise is not defined. |
334 | | #if __has_builtin(__builtin_unreachable) || LLVM_GNUC_PREREQ(4, 5, 0) |
335 | 0 | # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable() |
336 | | #elif defined(_MSC_VER) |
337 | | # define LLVM_BUILTIN_UNREACHABLE __assume(false) |
338 | | #endif |
339 | | |
340 | | /// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression |
341 | | /// which causes the program to exit abnormally. |
342 | | #if __has_builtin(__builtin_trap) || LLVM_GNUC_PREREQ(4, 3, 0) |
343 | | # define LLVM_BUILTIN_TRAP __builtin_trap() |
344 | | #elif defined(_MSC_VER) |
345 | | // The __debugbreak intrinsic is supported by MSVC, does not require forward |
346 | | // declarations involving platform-specific typedefs (unlike RaiseException), |
347 | | // results in a call to vectored exception handlers, and encodes to a short |
348 | | // instruction that still causes the trapping behavior we want. |
349 | | # define LLVM_BUILTIN_TRAP __debugbreak() |
350 | | #else |
351 | | # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0 |
352 | | #endif |
353 | | |
354 | | /// LLVM_BUILTIN_DEBUGTRAP - On compilers which support it, expands to |
355 | | /// an expression which causes the program to break while running |
356 | | /// under a debugger. |
357 | | #if __has_builtin(__builtin_debugtrap) |
358 | | # define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap() |
359 | | #elif defined(_MSC_VER) |
360 | | // The __debugbreak intrinsic is supported by MSVC and breaks while |
361 | | // running under the debugger, and also supports invoking a debugger |
362 | | // when the OS is configured appropriately. |
363 | | # define LLVM_BUILTIN_DEBUGTRAP __debugbreak() |
364 | | #else |
365 | | // Just continue execution when built with compilers that have no |
366 | | // support. This is a debugging aid and not intended to force the |
367 | | // program to abort if encountered. |
368 | | # define LLVM_BUILTIN_DEBUGTRAP |
369 | | #endif |
370 | | |
371 | | /// \macro LLVM_ASSUME_ALIGNED |
372 | | /// Returns a pointer with an assumed alignment. |
373 | | #if __has_builtin(__builtin_assume_aligned) || LLVM_GNUC_PREREQ(4, 7, 0) |
374 | 0 | # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a) |
375 | | #elif defined(LLVM_BUILTIN_UNREACHABLE) |
376 | | # define LLVM_ASSUME_ALIGNED(p, a) \ |
377 | | (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p))) |
378 | | #else |
379 | | # define LLVM_ASSUME_ALIGNED(p, a) (p) |
380 | | #endif |
381 | | |
382 | | /// \macro LLVM_PACKED |
383 | | /// Used to specify a packed structure. |
384 | | /// LLVM_PACKED( |
385 | | /// struct A { |
386 | | /// int i; |
387 | | /// int j; |
388 | | /// int k; |
389 | | /// long long l; |
390 | | /// }); |
391 | | /// |
392 | | /// LLVM_PACKED_START |
393 | | /// struct B { |
394 | | /// int i; |
395 | | /// int j; |
396 | | /// int k; |
397 | | /// long long l; |
398 | | /// }; |
399 | | /// LLVM_PACKED_END |
400 | | #ifdef _MSC_VER |
401 | | # define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop)) |
402 | | # define LLVM_PACKED_START __pragma(pack(push, 1)) |
403 | | # define LLVM_PACKED_END __pragma(pack(pop)) |
404 | | #else |
405 | | # define LLVM_PACKED(d) d __attribute__((packed)) |
406 | | # define LLVM_PACKED_START _Pragma("pack(push, 1)") |
407 | | # define LLVM_PACKED_END _Pragma("pack(pop)") |
408 | | #endif |
409 | | |
410 | | /// \macro LLVM_PTR_SIZE |
411 | | /// A constant integer equivalent to the value of sizeof(void*). |
412 | | /// Generally used in combination with alignas or when doing computation in the |
413 | | /// preprocessor. |
414 | | #ifdef __SIZEOF_POINTER__ |
415 | | # define LLVM_PTR_SIZE __SIZEOF_POINTER__ |
416 | | #elif defined(_WIN64) |
417 | | # define LLVM_PTR_SIZE 8 |
418 | | #elif defined(_WIN32) |
419 | | # define LLVM_PTR_SIZE 4 |
420 | | #elif defined(_MSC_VER) |
421 | | # error "could not determine LLVM_PTR_SIZE as a constant int for MSVC" |
422 | | #else |
423 | | # define LLVM_PTR_SIZE sizeof(void *) |
424 | | #endif |
425 | | |
426 | | /// \macro LLVM_MEMORY_SANITIZER_BUILD |
427 | | /// Whether LLVM itself is built with MemorySanitizer instrumentation. |
428 | | #if __has_feature(memory_sanitizer) |
429 | | # define LLVM_MEMORY_SANITIZER_BUILD 1 |
430 | | # include <sanitizer/msan_interface.h> |
431 | | # define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__((no_sanitize_memory)) |
432 | | #else |
433 | | # define LLVM_MEMORY_SANITIZER_BUILD 0 |
434 | | # define __msan_allocated_memory(p, size) |
435 | | # define __msan_unpoison(p, size) |
436 | | # define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE |
437 | | #endif |
438 | | |
439 | | /// \macro LLVM_ADDRESS_SANITIZER_BUILD |
440 | | /// Whether LLVM itself is built with AddressSanitizer instrumentation. |
441 | | #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) |
442 | | # define LLVM_ADDRESS_SANITIZER_BUILD 1 |
443 | | # include <sanitizer/asan_interface.h> |
444 | | #else |
445 | | # define LLVM_ADDRESS_SANITIZER_BUILD 0 |
446 | | # define __asan_poison_memory_region(p, size) |
447 | | # define __asan_unpoison_memory_region(p, size) |
448 | | #endif |
449 | | |
450 | | /// \macro LLVM_THREAD_SANITIZER_BUILD |
451 | | /// Whether LLVM itself is built with ThreadSanitizer instrumentation. |
452 | | #if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__) |
453 | | # define LLVM_THREAD_SANITIZER_BUILD 1 |
454 | | #else |
455 | | # define LLVM_THREAD_SANITIZER_BUILD 0 |
456 | | #endif |
457 | | |
458 | | #if LLVM_THREAD_SANITIZER_BUILD |
459 | | // Thread Sanitizer is a tool that finds races in code. |
460 | | // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations . |
461 | | // tsan detects these exact functions by name. |
462 | | #ifdef __cplusplus |
463 | | extern "C" { |
464 | | #endif |
465 | | void AnnotateHappensAfter(const char *file, int line, const volatile void *cv); |
466 | | void AnnotateHappensBefore(const char *file, int line, const volatile void *cv); |
467 | | void AnnotateIgnoreWritesBegin(const char *file, int line); |
468 | | void AnnotateIgnoreWritesEnd(const char *file, int line); |
469 | | #ifdef __cplusplus |
470 | | } |
471 | | #endif |
472 | | |
473 | | // This marker is used to define a happens-before arc. The race detector will |
474 | | // infer an arc from the begin to the end when they share the same pointer |
475 | | // argument. |
476 | | # define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv) |
477 | | |
478 | | // This marker defines the destination of a happens-before arc. |
479 | | # define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv) |
480 | | |
481 | | // Ignore any races on writes between here and the next TsanIgnoreWritesEnd. |
482 | | # define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__) |
483 | | |
484 | | // Resume checking for racy writes. |
485 | | # define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__) |
486 | | #else |
487 | | # define TsanHappensBefore(cv) |
488 | | # define TsanHappensAfter(cv) |
489 | | # define TsanIgnoreWritesBegin() |
490 | | # define TsanIgnoreWritesEnd() |
491 | | #endif |
492 | | |
493 | | /// \macro LLVM_NO_SANITIZE |
494 | | /// Disable a particular sanitizer for a function. |
495 | | #if __has_attribute(no_sanitize) |
496 | | #define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND))) |
497 | | #else |
498 | | #define LLVM_NO_SANITIZE(KIND) |
499 | | #endif |
500 | | |
501 | | /// Mark debug helper function definitions like dump() that should not be |
502 | | /// stripped from debug builds. |
503 | | /// Note that you should also surround dump() functions with |
504 | | /// `#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)` so they do always |
505 | | /// get stripped in release builds. |
506 | | // FIXME: Move this to a private config.h as it's not usable in public headers. |
507 | | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
508 | | #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED |
509 | | #else |
510 | | #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE |
511 | | #endif |
512 | | |
513 | | /// \macro LLVM_PRETTY_FUNCTION |
514 | | /// Gets a user-friendly looking function signature for the current scope |
515 | | /// using the best available method on each platform. The exact format of the |
516 | | /// resulting string is implementation specific and non-portable, so this should |
517 | | /// only be used, for example, for logging or diagnostics. |
518 | | #if defined(_MSC_VER) |
519 | | #define LLVM_PRETTY_FUNCTION __FUNCSIG__ |
520 | | #elif defined(__GNUC__) || defined(__clang__) |
521 | | #define LLVM_PRETTY_FUNCTION __PRETTY_FUNCTION__ |
522 | | #else |
523 | | #define LLVM_PRETTY_FUNCTION __func__ |
524 | | #endif |
525 | | |
526 | | /// \macro LLVM_THREAD_LOCAL |
527 | | /// A thread-local storage specifier which can be used with globals, |
528 | | /// extern globals, and static globals. |
529 | | /// |
530 | | /// This is essentially an extremely restricted analog to C++11's thread_local |
531 | | /// support. It uses thread_local if available, falling back on gcc __thread |
532 | | /// if not. __thread doesn't support many of the C++11 thread_local's |
533 | | /// features. You should only use this for PODs that you can statically |
534 | | /// initialize to some constant value. In almost all circumstances this is most |
535 | | /// appropriate for use with a pointer, integer, or small aggregation of |
536 | | /// pointers and integers. |
537 | | #if LLVM_ENABLE_THREADS |
538 | | #if __has_feature(cxx_thread_local) || defined(_MSC_VER) |
539 | | #define LLVM_THREAD_LOCAL thread_local |
540 | | #else |
541 | | // Clang, GCC, and other compatible compilers used __thread prior to C++11 and |
542 | | // we only need the restricted functionality that provides. |
543 | | #define LLVM_THREAD_LOCAL __thread |
544 | | #endif |
545 | | #else // !LLVM_ENABLE_THREADS |
546 | | // If threading is disabled entirely, this compiles to nothing and you get |
547 | | // a normal global variable. |
548 | | #define LLVM_THREAD_LOCAL |
549 | | #endif |
550 | | |
551 | | /// \macro LLVM_ENABLE_EXCEPTIONS |
552 | | /// Whether LLVM is built with exception support. |
553 | | #if __has_feature(cxx_exceptions) |
554 | | #define LLVM_ENABLE_EXCEPTIONS 1 |
555 | | #elif defined(__GNUC__) && defined(__EXCEPTIONS) |
556 | | #define LLVM_ENABLE_EXCEPTIONS 1 |
557 | | #elif defined(_MSC_VER) && defined(_CPPUNWIND) |
558 | | #define LLVM_ENABLE_EXCEPTIONS 1 |
559 | | #endif |
560 | | |
561 | | #endif |