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 #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) 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) 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) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \ 193 !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_attribute(minsize) 216 #define LLVM_ATTRIBUTE_MINSIZE __attribute__((minsize)) 217 #else 218 #define LLVM_ATTRIBUTE_MINSIZE 219 #endif 220 221 #if __has_builtin(__builtin_expect) || defined(__GNUC__) 222 #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true) 223 #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false) 224 #else 225 #define LLVM_LIKELY(EXPR) (EXPR) 226 #define LLVM_UNLIKELY(EXPR) (EXPR) 227 #endif 228 229 /// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, 230 /// mark a method "not for inlining". 231 #if __has_attribute(noinline) 232 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline)) 233 #elif defined(_MSC_VER) 234 #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline) 235 #else 236 #define LLVM_ATTRIBUTE_NOINLINE 237 #endif 238 239 /// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do 240 /// so, mark a method "always inline" because it is performance sensitive. 241 #if __has_attribute(always_inline) 242 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline)) 243 #elif defined(_MSC_VER) 244 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline 245 #else 246 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline 247 #endif 248 249 /// LLVM_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do 250 /// so, mark a method "no debug" because debug info makes the debugger 251 /// experience worse. 252 #if __has_attribute(nodebug) 253 #define LLVM_ATTRIBUTE_NODEBUG __attribute__((nodebug)) 254 #else 255 #define LLVM_ATTRIBUTE_NODEBUG 256 #endif 257 258 #if __has_attribute(returns_nonnull) 259 #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) 260 #elif defined(_MSC_VER) 261 #define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_ 262 #else 263 #define LLVM_ATTRIBUTE_RETURNS_NONNULL 264 #endif 265 266 /// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a 267 /// pointer that does not alias any other valid pointer. 268 #ifdef __GNUC__ 269 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) 270 #elif defined(_MSC_VER) 271 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict) 272 #else 273 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS 274 #endif 275 276 /// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements. 277 #if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough) 278 #define LLVM_FALLTHROUGH [[fallthrough]] 279 #elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough) 280 #define LLVM_FALLTHROUGH [[gnu::fallthrough]] 281 #elif __has_attribute(fallthrough) 282 #define LLVM_FALLTHROUGH __attribute__((fallthrough)) 283 #elif LLVM_HAS_CPP_ATTRIBUTE(clang::fallthrough) 284 #define LLVM_FALLTHROUGH [[clang::fallthrough]] 285 #else 286 #define LLVM_FALLTHROUGH 287 #endif 288 289 /// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that 290 /// they are constant initialized. 291 #if LLVM_HAS_CPP_ATTRIBUTE(clang::require_constant_initialization) 292 #define LLVM_REQUIRE_CONSTANT_INITIALIZATION \ 293 [[clang::require_constant_initialization]] 294 #else 295 #define LLVM_REQUIRE_CONSTANT_INITIALIZATION 296 #endif 297 298 /// LLVM_GSL_OWNER - Apply this to owning classes like SmallVector to enable 299 /// lifetime warnings. 300 #if LLVM_HAS_CPP_ATTRIBUTE(gsl::Owner) 301 #define LLVM_GSL_OWNER [[gsl::Owner]] 302 #else 303 #define LLVM_GSL_OWNER 304 #endif 305 306 /// LLVM_GSL_POINTER - Apply this to non-owning classes like 307 /// StringRef to enable lifetime warnings. 308 #if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer) 309 #define LLVM_GSL_POINTER [[gsl::Pointer]] 310 #else 311 #define LLVM_GSL_POINTER 312 #endif 313 314 /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress 315 /// pedantic diagnostics. 316 #ifdef __GNUC__ 317 #define LLVM_EXTENSION __extension__ 318 #else 319 #define LLVM_EXTENSION 320 #endif 321 322 // LLVM_ATTRIBUTE_DEPRECATED(decl, "message") 323 // This macro will be removed. 324 // Use C++14's attribute instead: [[deprecated("message")]] 325 #define LLVM_ATTRIBUTE_DEPRECATED(decl, message) [[deprecated(message)]] decl 326 327 /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands 328 /// to an expression which states that it is undefined behavior for the 329 /// compiler to reach this point. Otherwise is not defined. 330 #if __has_builtin(__builtin_unreachable) || defined(__GNUC__) 331 # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable() 332 #elif defined(_MSC_VER) 333 # define LLVM_BUILTIN_UNREACHABLE __assume(false) 334 #else 335 # define LLVM_BUILTIN_UNREACHABLE 336 #endif 337 338 /// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression 339 /// which causes the program to exit abnormally. 340 #if __has_builtin(__builtin_trap) || defined(__GNUC__) 341 # define LLVM_BUILTIN_TRAP __builtin_trap() 342 #elif defined(_MSC_VER) 343 // The __debugbreak intrinsic is supported by MSVC, does not require forward 344 // declarations involving platform-specific typedefs (unlike RaiseException), 345 // results in a call to vectored exception handlers, and encodes to a short 346 // instruction that still causes the trapping behavior we want. 347 # define LLVM_BUILTIN_TRAP __debugbreak() 348 #else 349 # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0 350 #endif 351 352 /// LLVM_BUILTIN_DEBUGTRAP - On compilers which support it, expands to 353 /// an expression which causes the program to break while running 354 /// under a debugger. 355 #if __has_builtin(__builtin_debugtrap) 356 # define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap() 357 #elif defined(_MSC_VER) 358 // The __debugbreak intrinsic is supported by MSVC and breaks while 359 // running under the debugger, and also supports invoking a debugger 360 // when the OS is configured appropriately. 361 # define LLVM_BUILTIN_DEBUGTRAP __debugbreak() 362 #else 363 // Just continue execution when built with compilers that have no 364 // support. This is a debugging aid and not intended to force the 365 // program to abort if encountered. 366 # define LLVM_BUILTIN_DEBUGTRAP 367 #endif 368 369 /// \macro LLVM_ASSUME_ALIGNED 370 /// Returns a pointer with an assumed alignment. 371 #if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__) 372 # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a) 373 #elif defined(LLVM_BUILTIN_UNREACHABLE) 374 # define LLVM_ASSUME_ALIGNED(p, a) \ 375 (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p))) 376 #else 377 # define LLVM_ASSUME_ALIGNED(p, a) (p) 378 #endif 379 380 /// \macro LLVM_PACKED 381 /// Used to specify a packed structure. 382 /// LLVM_PACKED( 383 /// struct A { 384 /// int i; 385 /// int j; 386 /// int k; 387 /// long long l; 388 /// }); 389 /// 390 /// LLVM_PACKED_START 391 /// struct B { 392 /// int i; 393 /// int j; 394 /// int k; 395 /// long long l; 396 /// }; 397 /// LLVM_PACKED_END 398 #ifdef _MSC_VER 399 # define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop)) 400 # define LLVM_PACKED_START __pragma(pack(push, 1)) 401 # define LLVM_PACKED_END __pragma(pack(pop)) 402 #else 403 # define LLVM_PACKED(d) d __attribute__((packed)) 404 # define LLVM_PACKED_START _Pragma("pack(push, 1)") 405 # define LLVM_PACKED_END _Pragma("pack(pop)") 406 #endif 407 408 /// \macro LLVM_PTR_SIZE 409 /// A constant integer equivalent to the value of sizeof(void*). 410 /// Generally used in combination with alignas or when doing computation in the 411 /// preprocessor. 412 #ifdef __SIZEOF_POINTER__ 413 # define LLVM_PTR_SIZE __SIZEOF_POINTER__ 414 #elif defined(_WIN64) 415 # define LLVM_PTR_SIZE 8 416 #elif defined(_WIN32) 417 # define LLVM_PTR_SIZE 4 418 #elif defined(_MSC_VER) 419 # error "could not determine LLVM_PTR_SIZE as a constant int for MSVC" 420 #else 421 # define LLVM_PTR_SIZE sizeof(void *) 422 #endif 423 424 /// \macro LLVM_MEMORY_SANITIZER_BUILD 425 /// Whether LLVM itself is built with MemorySanitizer instrumentation. 426 #if __has_feature(memory_sanitizer) 427 # define LLVM_MEMORY_SANITIZER_BUILD 1 428 # include <sanitizer/msan_interface.h> 429 # define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__((no_sanitize_memory)) 430 #else 431 # define LLVM_MEMORY_SANITIZER_BUILD 0 432 # define __msan_allocated_memory(p, size) 433 # define __msan_unpoison(p, size) 434 # define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE 435 #endif 436 437 /// \macro LLVM_ADDRESS_SANITIZER_BUILD 438 /// Whether LLVM itself is built with AddressSanitizer instrumentation. 439 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) 440 # define LLVM_ADDRESS_SANITIZER_BUILD 1 441 # include <sanitizer/asan_interface.h> 442 #else 443 # define LLVM_ADDRESS_SANITIZER_BUILD 0 444 # define __asan_poison_memory_region(p, size) 445 # define __asan_unpoison_memory_region(p, size) 446 #endif 447 448 /// \macro LLVM_THREAD_SANITIZER_BUILD 449 /// Whether LLVM itself is built with ThreadSanitizer instrumentation. 450 #if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__) 451 # define LLVM_THREAD_SANITIZER_BUILD 1 452 #else 453 # define LLVM_THREAD_SANITIZER_BUILD 0 454 #endif 455 456 #if LLVM_THREAD_SANITIZER_BUILD 457 // Thread Sanitizer is a tool that finds races in code. 458 // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations . 459 // tsan detects these exact functions by name. 460 #ifdef __cplusplus 461 extern "C" { 462 #endif 463 void AnnotateHappensAfter(const char *file, int line, const volatile void *cv); 464 void AnnotateHappensBefore(const char *file, int line, const volatile void *cv); 465 void AnnotateIgnoreWritesBegin(const char *file, int line); 466 void AnnotateIgnoreWritesEnd(const char *file, int line); 467 #ifdef __cplusplus 468 } 469 #endif 470 471 // This marker is used to define a happens-before arc. The race detector will 472 // infer an arc from the begin to the end when they share the same pointer 473 // argument. 474 # define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv) 475 476 // This marker defines the destination of a happens-before arc. 477 # define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv) 478 479 // Ignore any races on writes between here and the next TsanIgnoreWritesEnd. 480 # define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__) 481 482 // Resume checking for racy writes. 483 # define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__) 484 #else 485 # define TsanHappensBefore(cv) 486 # define TsanHappensAfter(cv) 487 # define TsanIgnoreWritesBegin() 488 # define TsanIgnoreWritesEnd() 489 #endif 490 491 /// \macro LLVM_NO_SANITIZE 492 /// Disable a particular sanitizer for a function. 493 #if __has_attribute(no_sanitize) 494 #define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND))) 495 #else 496 #define LLVM_NO_SANITIZE(KIND) 497 #endif 498 499 /// Mark debug helper function definitions like dump() that should not be 500 /// stripped from debug builds. 501 /// Note that you should also surround dump() functions with 502 /// `#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)` so they do always 503 /// get stripped in release builds. 504 // FIXME: Move this to a private config.h as it's not usable in public headers. 505 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 506 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED 507 #else 508 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE 509 #endif 510 511 /// \macro LLVM_PRETTY_FUNCTION 512 /// Gets a user-friendly looking function signature for the current scope 513 /// using the best available method on each platform. The exact format of the 514 /// resulting string is implementation specific and non-portable, so this should 515 /// only be used, for example, for logging or diagnostics. 516 #if defined(_MSC_VER) 517 #define LLVM_PRETTY_FUNCTION __FUNCSIG__ 518 #elif defined(__GNUC__) || defined(__clang__) 519 #define LLVM_PRETTY_FUNCTION __PRETTY_FUNCTION__ 520 #else 521 #define LLVM_PRETTY_FUNCTION __func__ 522 #endif 523 524 /// \macro LLVM_THREAD_LOCAL 525 /// A thread-local storage specifier which can be used with globals, 526 /// extern globals, and static globals. 527 /// 528 /// This is essentially an extremely restricted analog to C++11's thread_local 529 /// support. It uses thread_local if available, falling back on gcc __thread 530 /// if not. __thread doesn't support many of the C++11 thread_local's 531 /// features. You should only use this for PODs that you can statically 532 /// initialize to some constant value. In almost all circumstances this is most 533 /// appropriate for use with a pointer, integer, or small aggregation of 534 /// pointers and integers. 535 #if LLVM_ENABLE_THREADS 536 #if __has_feature(cxx_thread_local) || defined(_MSC_VER) 537 #define LLVM_THREAD_LOCAL thread_local 538 #else 539 // Clang, GCC, and other compatible compilers used __thread prior to C++11 and 540 // we only need the restricted functionality that provides. 541 #define LLVM_THREAD_LOCAL __thread 542 #endif 543 #else // !LLVM_ENABLE_THREADS 544 // If threading is disabled entirely, this compiles to nothing and you get 545 // a normal global variable. 546 #define LLVM_THREAD_LOCAL 547 #endif 548 549 /// \macro LLVM_ENABLE_EXCEPTIONS 550 /// Whether LLVM is built with exception support. 551 #if __has_feature(cxx_exceptions) 552 #define LLVM_ENABLE_EXCEPTIONS 1 553 #elif defined(__GNUC__) && defined(__EXCEPTIONS) 554 #define LLVM_ENABLE_EXCEPTIONS 1 555 #elif defined(_MSC_VER) && defined(_CPPUNWIND) 556 #define LLVM_ENABLE_EXCEPTIONS 1 557 #endif 558 559 /// \macro LLVM_NO_PROFILE_INSTRUMENT_FUNCTION 560 /// Disable the profile instrument for a function. 561 #if __has_attribute(no_profile_instrument_function) 562 #define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION \ 563 __attribute__((no_profile_instrument_function)) 564 #else 565 #define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION 566 #endif 567 568 #endif 569