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