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