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