Compiler.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. #ifndef __has_include
  39. # define __has_include(x) 0
  40. #endif
  41. // Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in
  42. // C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid.
  43. #ifndef LLVM_HAS_CPP_ATTRIBUTE
  44. #if defined(__cplusplus) && defined(__has_cpp_attribute)
  45. # define LLVM_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
  46. #else
  47. # define LLVM_HAS_CPP_ATTRIBUTE(x) 0
  48. #endif
  49. #endif
  50. /// \macro LLVM_GNUC_PREREQ
  51. /// Extend the default __GNUC_PREREQ even if glibc's features.h isn't
  52. /// available.
  53. #ifndef LLVM_GNUC_PREREQ
  54. # if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
  55. # define LLVM_GNUC_PREREQ(maj, min, patch) \
  56. ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
  57. ((maj) << 20) + ((min) << 10) + (patch))
  58. # elif defined(__GNUC__) && defined(__GNUC_MINOR__)
  59. # define LLVM_GNUC_PREREQ(maj, min, patch) \
  60. ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
  61. # else
  62. # define LLVM_GNUC_PREREQ(maj, min, patch) 0
  63. # endif
  64. #endif
  65. /// \macro LLVM_MSC_PREREQ
  66. /// Is the compiler MSVC of at least the specified version?
  67. /// The common \param version values to check for are:
  68. /// * 1910: VS2017, version 15.1 & 15.2
  69. /// * 1911: VS2017, version 15.3 & 15.4
  70. /// * 1912: VS2017, version 15.5
  71. /// * 1913: VS2017, version 15.6
  72. /// * 1914: VS2017, version 15.7
  73. /// * 1915: VS2017, version 15.8
  74. /// * 1916: VS2017, version 15.9
  75. /// * 1920: VS2019, version 16.0
  76. /// * 1921: VS2019, version 16.1
  77. /// * 1922: VS2019, version 16.2
  78. /// * 1923: VS2019, version 16.3
  79. /// * 1924: VS2019, version 16.4
  80. /// * 1925: VS2019, version 16.5
  81. /// * 1926: VS2019, version 16.6
  82. /// * 1927: VS2019, version 16.7
  83. /// * 1928: VS2019, version 16.8 + 16.9
  84. /// * 1929: VS2019, version 16.10 + 16.11
  85. /// * 1930: VS2022, version 17.0
  86. #ifdef _MSC_VER
  87. #define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version))
  88. // We require at least VS 2019.
  89. #if !defined(LLVM_FORCE_USE_OLD_TOOLCHAIN)
  90. #if !LLVM_MSC_PREREQ(1920)
  91. #error LLVM requires at least VS 2019.
  92. #endif
  93. #endif
  94. #else
  95. #define LLVM_MSC_PREREQ(version) 0
  96. #endif
  97. /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
  98. /// into a shared library, then the class should be private to the library and
  99. /// not accessible from outside it. Can also be used to mark variables and
  100. /// functions, making them private to any shared library they are linked into.
  101. /// On PE/COFF targets, library visibility is the default, so this isn't needed.
  102. ///
  103. /// LLVM_EXTERNAL_VISIBILITY - classes, functions, and variables marked with
  104. /// this attribute will be made public and visible outside of any shared library
  105. /// they are linked in to.
  106. #if __has_attribute(visibility) && \
  107. (!(defined(_WIN32) || defined(__CYGWIN__)) || \
  108. (defined(__MINGW32__) && defined(__clang__)))
  109. #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
  110. #if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
  111. #define LLVM_EXTERNAL_VISIBILITY __attribute__((visibility("default")))
  112. #else
  113. #define LLVM_EXTERNAL_VISIBILITY
  114. #endif
  115. #else
  116. #define LLVM_LIBRARY_VISIBILITY
  117. #define LLVM_EXTERNAL_VISIBILITY
  118. #endif
  119. #if defined(__GNUC__)
  120. #define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
  121. #else
  122. #define LLVM_PREFETCH(addr, rw, locality)
  123. #endif
  124. #if __has_attribute(used)
  125. #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
  126. #else
  127. #define LLVM_ATTRIBUTE_USED
  128. #endif
  129. #if defined(__clang__)
  130. #define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
  131. #else
  132. #define LLVM_DEPRECATED(MSG, FIX) [[deprecated(MSG)]]
  133. #endif
  134. // Indicate that a non-static, non-const C++ member function reinitializes
  135. // the entire object to a known state, independent of the previous state of
  136. // the object.
  137. //
  138. // The clang-tidy check bugprone-use-after-move recognizes this attribute as a
  139. // marker that a moved-from object has left the indeterminate state and can be
  140. // reused.
  141. #if LLVM_HAS_CPP_ATTRIBUTE(clang::reinitializes)
  142. #define LLVM_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
  143. #else
  144. #define LLVM_ATTRIBUTE_REINITIALIZES
  145. #endif
  146. // Some compilers warn about unused functions. When a function is sometimes
  147. // used or not depending on build settings (e.g. a function only called from
  148. // within "assert"), this attribute can be used to suppress such warnings.
  149. //
  150. // However, it shouldn't be used for unused *variables*, as those have a much
  151. // more portable solution:
  152. // (void)unused_var_name;
  153. // Prefer cast-to-void wherever it is sufficient.
  154. #if __has_attribute(unused)
  155. #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
  156. #else
  157. #define LLVM_ATTRIBUTE_UNUSED
  158. #endif
  159. // FIXME: Provide this for PE/COFF targets.
  160. #if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \
  161. !defined(_WIN32)
  162. #define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
  163. #else
  164. #define LLVM_ATTRIBUTE_WEAK
  165. #endif
  166. // Prior to clang 3.2, clang did not accept any spelling of
  167. // __has_attribute(const), so assume it is supported.
  168. #if defined(__clang__) || defined(__GNUC__)
  169. // aka 'CONST' but following LLVM Conventions.
  170. #define LLVM_READNONE __attribute__((__const__))
  171. #else
  172. #define LLVM_READNONE
  173. #endif
  174. #if __has_attribute(pure) || defined(__GNUC__)
  175. // aka 'PURE' but following LLVM Conventions.
  176. #define LLVM_READONLY __attribute__((__pure__))
  177. #else
  178. #define LLVM_READONLY
  179. #endif
  180. #if __has_attribute(minsize)
  181. #define LLVM_ATTRIBUTE_MINSIZE __attribute__((minsize))
  182. #else
  183. #define LLVM_ATTRIBUTE_MINSIZE
  184. #endif
  185. #if __has_builtin(__builtin_expect) || defined(__GNUC__)
  186. #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
  187. #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
  188. #else
  189. #define LLVM_LIKELY(EXPR) (EXPR)
  190. #define LLVM_UNLIKELY(EXPR) (EXPR)
  191. #endif
  192. /// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so,
  193. /// mark a method "not for inlining".
  194. #if __has_attribute(noinline)
  195. #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
  196. #elif defined(_MSC_VER)
  197. #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
  198. #else
  199. #define LLVM_ATTRIBUTE_NOINLINE
  200. #endif
  201. /// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do
  202. /// so, mark a method "always inline" because it is performance sensitive.
  203. #if __has_attribute(always_inline)
  204. #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
  205. #elif defined(_MSC_VER)
  206. #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
  207. #else
  208. #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
  209. #endif
  210. /// LLVM_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do
  211. /// so, mark a method "no debug" because debug info makes the debugger
  212. /// experience worse.
  213. #if __has_attribute(nodebug)
  214. #define LLVM_ATTRIBUTE_NODEBUG __attribute__((nodebug))
  215. #else
  216. #define LLVM_ATTRIBUTE_NODEBUG
  217. #endif
  218. #if __has_attribute(returns_nonnull)
  219. #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
  220. #elif defined(_MSC_VER)
  221. #define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_
  222. #else
  223. #define LLVM_ATTRIBUTE_RETURNS_NONNULL
  224. #endif
  225. /// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a
  226. /// pointer that does not alias any other valid pointer.
  227. #ifdef __GNUC__
  228. #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
  229. #elif defined(_MSC_VER)
  230. #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
  231. #else
  232. #define LLVM_ATTRIBUTE_RETURNS_NOALIAS
  233. #endif
  234. /// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
  235. #if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough)
  236. #define LLVM_FALLTHROUGH [[fallthrough]]
  237. #elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
  238. #define LLVM_FALLTHROUGH [[gnu::fallthrough]]
  239. #elif __has_attribute(fallthrough)
  240. #define LLVM_FALLTHROUGH __attribute__((fallthrough))
  241. #elif LLVM_HAS_CPP_ATTRIBUTE(clang::fallthrough)
  242. #define LLVM_FALLTHROUGH [[clang::fallthrough]]
  243. #else
  244. #define LLVM_FALLTHROUGH
  245. #endif
  246. /// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that
  247. /// they are constant initialized.
  248. #if LLVM_HAS_CPP_ATTRIBUTE(clang::require_constant_initialization)
  249. #define LLVM_REQUIRE_CONSTANT_INITIALIZATION \
  250. [[clang::require_constant_initialization]]
  251. #else
  252. #define LLVM_REQUIRE_CONSTANT_INITIALIZATION
  253. #endif
  254. /// LLVM_GSL_OWNER - Apply this to owning classes like SmallVector to enable
  255. /// lifetime warnings.
  256. #if LLVM_HAS_CPP_ATTRIBUTE(gsl::Owner)
  257. #define LLVM_GSL_OWNER [[gsl::Owner]]
  258. #else
  259. #define LLVM_GSL_OWNER
  260. #endif
  261. /// LLVM_GSL_POINTER - Apply this to non-owning classes like
  262. /// StringRef to enable lifetime warnings.
  263. #if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer)
  264. #define LLVM_GSL_POINTER [[gsl::Pointer]]
  265. #else
  266. #define LLVM_GSL_POINTER
  267. #endif
  268. /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
  269. /// pedantic diagnostics.
  270. #ifdef __GNUC__
  271. #define LLVM_EXTENSION __extension__
  272. #else
  273. #define LLVM_EXTENSION
  274. #endif
  275. /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
  276. /// to an expression which states that it is undefined behavior for the
  277. /// compiler to reach this point. Otherwise is not defined.
  278. ///
  279. /// '#else' is intentionally left out so that other macro logic (e.g.,
  280. /// LLVM_ASSUME_ALIGNED and llvm_unreachable()) can detect whether
  281. /// LLVM_BUILTIN_UNREACHABLE has a definition.
  282. #if __has_builtin(__builtin_unreachable) || defined(__GNUC__)
  283. # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
  284. #elif defined(_MSC_VER)
  285. # define LLVM_BUILTIN_UNREACHABLE __assume(false)
  286. #endif
  287. /// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression
  288. /// which causes the program to exit abnormally.
  289. #if __has_builtin(__builtin_trap) || defined(__GNUC__)
  290. # define LLVM_BUILTIN_TRAP __builtin_trap()
  291. #elif defined(_MSC_VER)
  292. // The __debugbreak intrinsic is supported by MSVC, does not require forward
  293. // declarations involving platform-specific typedefs (unlike RaiseException),
  294. // results in a call to vectored exception handlers, and encodes to a short
  295. // instruction that still causes the trapping behavior we want.
  296. # define LLVM_BUILTIN_TRAP __debugbreak()
  297. #else
  298. # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
  299. #endif
  300. /// LLVM_BUILTIN_DEBUGTRAP - On compilers which support it, expands to
  301. /// an expression which causes the program to break while running
  302. /// under a debugger.
  303. #if __has_builtin(__builtin_debugtrap)
  304. # define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap()
  305. #elif defined(_MSC_VER)
  306. // The __debugbreak intrinsic is supported by MSVC and breaks while
  307. // running under the debugger, and also supports invoking a debugger
  308. // when the OS is configured appropriately.
  309. # define LLVM_BUILTIN_DEBUGTRAP __debugbreak()
  310. #else
  311. // Just continue execution when built with compilers that have no
  312. // support. This is a debugging aid and not intended to force the
  313. // program to abort if encountered.
  314. # define LLVM_BUILTIN_DEBUGTRAP
  315. #endif
  316. /// \macro LLVM_ASSUME_ALIGNED
  317. /// Returns a pointer with an assumed alignment.
  318. #if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__)
  319. # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
  320. #elif defined(LLVM_BUILTIN_UNREACHABLE)
  321. # define LLVM_ASSUME_ALIGNED(p, a) \
  322. (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
  323. #else
  324. # define LLVM_ASSUME_ALIGNED(p, a) (p)
  325. #endif
  326. /// \macro LLVM_PACKED
  327. /// Used to specify a packed structure.
  328. /// LLVM_PACKED(
  329. /// struct A {
  330. /// int i;
  331. /// int j;
  332. /// int k;
  333. /// long long l;
  334. /// });
  335. ///
  336. /// LLVM_PACKED_START
  337. /// struct B {
  338. /// int i;
  339. /// int j;
  340. /// int k;
  341. /// long long l;
  342. /// };
  343. /// LLVM_PACKED_END
  344. #ifdef _MSC_VER
  345. # define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))
  346. # define LLVM_PACKED_START __pragma(pack(push, 1))
  347. # define LLVM_PACKED_END __pragma(pack(pop))
  348. #else
  349. # define LLVM_PACKED(d) d __attribute__((packed))
  350. # define LLVM_PACKED_START _Pragma("pack(push, 1)")
  351. # define LLVM_PACKED_END _Pragma("pack(pop)")
  352. #endif
  353. /// \macro LLVM_MEMORY_SANITIZER_BUILD
  354. /// Whether LLVM itself is built with MemorySanitizer instrumentation.
  355. #if __has_feature(memory_sanitizer)
  356. # define LLVM_MEMORY_SANITIZER_BUILD 1
  357. # include <sanitizer/msan_interface.h>
  358. # define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__((no_sanitize_memory))
  359. #else
  360. # define LLVM_MEMORY_SANITIZER_BUILD 0
  361. # define __msan_allocated_memory(p, size)
  362. # define __msan_unpoison(p, size)
  363. # define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE
  364. #endif
  365. /// \macro LLVM_ADDRESS_SANITIZER_BUILD
  366. /// Whether LLVM itself is built with AddressSanitizer instrumentation.
  367. #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
  368. # define LLVM_ADDRESS_SANITIZER_BUILD 1
  369. #if __has_include(<sanitizer/asan_interface.h>)
  370. # include <sanitizer/asan_interface.h>
  371. #else
  372. // These declarations exist to support ASan with MSVC. If MSVC eventually ships
  373. // asan_interface.h in their headers, then we can remove this.
  374. #ifdef __cplusplus
  375. extern "C" {
  376. #endif
  377. void __asan_poison_memory_region(void const volatile *addr, size_t size);
  378. void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
  379. #ifdef __cplusplus
  380. } // extern "C"
  381. #endif
  382. #endif
  383. #else
  384. # define LLVM_ADDRESS_SANITIZER_BUILD 0
  385. # define __asan_poison_memory_region(p, size)
  386. # define __asan_unpoison_memory_region(p, size)
  387. #endif
  388. /// \macro LLVM_HWADDRESS_SANITIZER_BUILD
  389. /// Whether LLVM itself is built with HWAddressSanitizer instrumentation.
  390. #if __has_feature(hwaddress_sanitizer)
  391. #define LLVM_HWADDRESS_SANITIZER_BUILD 1
  392. #else
  393. #define LLVM_HWADDRESS_SANITIZER_BUILD 0
  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. /// \macro LLVM_NO_PROFILE_INSTRUMENT_FUNCTION
  496. /// Disable the profile instrument for a function.
  497. #if __has_attribute(no_profile_instrument_function)
  498. #define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION \
  499. __attribute__((no_profile_instrument_function))
  500. #else
  501. #define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION
  502. #endif
  503. #endif
  504. #ifdef __GNUC__
  505. #pragma GCC diagnostic pop
  506. #endif