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