Compiler.h 19 KB

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