Compiler.h 20 KB

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