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