Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

364 lines
12 KiB

  1. //===-- llvm/Support/Compiler.h - Compiler abstraction support --*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines several macros, based on the current compiler. This allows
  11. // use of compiler-specific features in a way that remains portable.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_SUPPORT_COMPILER_H
  15. #define LLVM_SUPPORT_COMPILER_H
  16. #include "llvm/Config/llvm-config.h"
  17. #ifndef __has_feature
  18. # define __has_feature(x) 0
  19. #endif
  20. /// \brief Does the compiler support r-value references?
  21. /// This implies that <utility> provides the one-argument std::move; it
  22. /// does not imply the existence of any other C++ library features.
  23. #if (__has_feature(cxx_rvalue_references) \
  24. || defined(__GXX_EXPERIMENTAL_CXX0X__) \
  25. || (defined(_MSC_VER) && _MSC_VER >= 1600))
  26. #define LLVM_HAS_RVALUE_REFERENCES 1
  27. #else
  28. #define LLVM_HAS_RVALUE_REFERENCES 0
  29. #endif
  30. /// \brief Does the compiler support r-value reference *this?
  31. ///
  32. /// Sadly, this is separate from just r-value reference support because GCC
  33. /// implemented everything but this thus far. No release of GCC yet has support
  34. /// for this feature so it is enabled with Clang only.
  35. /// FIXME: This should change to a version check when GCC grows support for it.
  36. #if __has_feature(cxx_rvalue_references)
  37. #define LLVM_HAS_RVALUE_REFERENCE_THIS 1
  38. #else
  39. #define LLVM_HAS_RVALUE_REFERENCE_THIS 0
  40. #endif
  41. /// \macro LLVM_HAS_CXX11_TYPETRAITS
  42. /// \brief Does the compiler have the C++11 type traits.
  43. ///
  44. /// #include <type_traits>
  45. ///
  46. /// * enable_if
  47. /// * {true,false}_type
  48. /// * is_constructible
  49. /// * etc...
  50. #if defined(__GXX_EXPERIMENTAL_CXX0X__) \
  51. || (defined(_MSC_VER) && _MSC_VER >= 1700)
  52. #define LLVM_HAS_CXX11_TYPETRAITS 1
  53. #else
  54. #define LLVM_HAS_CXX11_TYPETRAITS 0
  55. #endif
  56. /// \macro LLVM_HAS_CXX11_STDLIB
  57. /// \brief Does the compiler have the C++11 standard library.
  58. ///
  59. /// Implies LLVM_HAS_RVALUE_REFERENCES, LLVM_HAS_CXX11_TYPETRAITS
  60. #if defined(__GXX_EXPERIMENTAL_CXX0X__) \
  61. || (defined(_MSC_VER) && _MSC_VER >= 1700)
  62. #define LLVM_HAS_CXX11_STDLIB 1
  63. #else
  64. #define LLVM_HAS_CXX11_STDLIB 0
  65. #endif
  66. /// \macro LLVM_HAS_VARIADIC_TEMPLATES
  67. /// \brief Does this compiler support variadic templates.
  68. ///
  69. /// Implies LLVM_HAS_RVALUE_REFERENCES and the existence of std::forward.
  70. #if __has_feature(cxx_variadic_templates)
  71. # define LLVM_HAS_VARIADIC_TEMPLATES 1
  72. #else
  73. # define LLVM_HAS_VARIADIC_TEMPLATES 0
  74. #endif
  75. /// llvm_move - Expands to ::std::move if the compiler supports
  76. /// r-value references; otherwise, expands to the argument.
  77. #if LLVM_HAS_RVALUE_REFERENCES
  78. #define llvm_move(value) (::std::move(value))
  79. #else
  80. #define llvm_move(value) (value)
  81. #endif
  82. /// Expands to '&' if r-value references are supported.
  83. ///
  84. /// This can be used to provide l-value/r-value overrides of member functions.
  85. /// The r-value override should be guarded by LLVM_HAS_RVALUE_REFERENCE_THIS
  86. #if LLVM_HAS_RVALUE_REFERENCE_THIS
  87. #define LLVM_LVALUE_FUNCTION &
  88. #else
  89. #define LLVM_LVALUE_FUNCTION
  90. #endif
  91. /// LLVM_DELETED_FUNCTION - Expands to = delete if the compiler supports it.
  92. /// Use to mark functions as uncallable. Member functions with this should
  93. /// be declared private so that some behavior is kept in C++03 mode.
  94. ///
  95. /// class DontCopy {
  96. /// private:
  97. /// DontCopy(const DontCopy&) LLVM_DELETED_FUNCTION;
  98. /// DontCopy &operator =(const DontCopy&) LLVM_DELETED_FUNCTION;
  99. /// public:
  100. /// ...
  101. /// };
  102. #if (__has_feature(cxx_deleted_functions) \
  103. || defined(__GXX_EXPERIMENTAL_CXX0X__))
  104. // No version of MSVC currently supports this.
  105. #define LLVM_DELETED_FUNCTION = delete
  106. #else
  107. #define LLVM_DELETED_FUNCTION
  108. #endif
  109. /// LLVM_FINAL - Expands to 'final' if the compiler supports it.
  110. /// Use to mark classes or virtual methods as final.
  111. #if __has_feature(cxx_override_control) \
  112. || (defined(_MSC_VER) && _MSC_VER >= 1700)
  113. #define LLVM_FINAL final
  114. #else
  115. #define LLVM_FINAL
  116. #endif
  117. /// LLVM_OVERRIDE - Expands to 'override' if the compiler supports it.
  118. /// Use to mark virtual methods as overriding a base class method.
  119. #if __has_feature(cxx_override_control) \
  120. || (defined(_MSC_VER) && _MSC_VER >= 1700)
  121. #define LLVM_OVERRIDE override
  122. #else
  123. #define LLVM_OVERRIDE
  124. #endif
  125. #if __has_feature(cxx_constexpr) || defined(__GXX_EXPERIMENTAL_CXX0X__)
  126. # define LLVM_CONSTEXPR constexpr
  127. #else
  128. # define LLVM_CONSTEXPR
  129. #endif
  130. /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
  131. /// into a shared library, then the class should be private to the library and
  132. /// not accessible from outside it. Can also be used to mark variables and
  133. /// functions, making them private to any shared library they are linked into.
  134. #if (__GNUC__ >= 4) && !defined(__MINGW32__) && !defined(__CYGWIN__)
  135. #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
  136. #else
  137. #define LLVM_LIBRARY_VISIBILITY
  138. #endif
  139. #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
  140. #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
  141. #else
  142. #define LLVM_ATTRIBUTE_USED
  143. #endif
  144. // Some compilers warn about unused functions. When a function is sometimes
  145. // used or not depending on build settings (e.g. a function only called from
  146. // within "assert"), this attribute can be used to suppress such warnings.
  147. //
  148. // However, it shouldn't be used for unused *variables*, as those have a much
  149. // more portable solution:
  150. // (void)unused_var_name;
  151. // Prefer cast-to-void wherever it is sufficient.
  152. #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
  153. #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
  154. #else
  155. #define LLVM_ATTRIBUTE_UNUSED
  156. #endif
  157. #if (__GNUC__ >= 4) && !defined(__MINGW32__) && !defined(__CYGWIN__)
  158. #define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
  159. #else
  160. #define LLVM_ATTRIBUTE_WEAK
  161. #endif
  162. #ifdef __GNUC__ // aka 'CONST' but following LLVM Conventions.
  163. #define LLVM_READNONE __attribute__((__const__))
  164. #else
  165. #define LLVM_READNONE
  166. #endif
  167. #ifdef __GNUC__ // aka 'PURE' but following LLVM Conventions.
  168. #define LLVM_READONLY __attribute__((__pure__))
  169. #else
  170. #define LLVM_READONLY
  171. #endif
  172. #if (__GNUC__ >= 4)
  173. #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
  174. #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
  175. #else
  176. #define LLVM_LIKELY(EXPR) (EXPR)
  177. #define LLVM_UNLIKELY(EXPR) (EXPR)
  178. #endif
  179. // C++ doesn't support 'extern template' of template specializations. GCC does,
  180. // but requires __extension__ before it. In the header, use this:
  181. // EXTERN_TEMPLATE_INSTANTIATION(class foo<bar>);
  182. // in the .cpp file, use this:
  183. // TEMPLATE_INSTANTIATION(class foo<bar>);
  184. #ifdef __GNUC__
  185. #define EXTERN_TEMPLATE_INSTANTIATION(X) __extension__ extern template X
  186. #define TEMPLATE_INSTANTIATION(X) template X
  187. #else
  188. #define EXTERN_TEMPLATE_INSTANTIATION(X)
  189. #define TEMPLATE_INSTANTIATION(X)
  190. #endif
  191. /// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so,
  192. /// mark a method "not for inlining".
  193. #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
  194. #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
  195. #elif defined(_MSC_VER)
  196. #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
  197. #else
  198. #define LLVM_ATTRIBUTE_NOINLINE
  199. #endif
  200. /// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do
  201. /// so, mark a method "always inline" because it is performance sensitive. GCC
  202. /// 3.4 supported this but is buggy in various cases and produces unimplemented
  203. /// errors, just use it in GCC 4.0 and later.
  204. #if __GNUC__ > 3
  205. #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
  206. #elif defined(_MSC_VER)
  207. #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
  208. #else
  209. #define LLVM_ATTRIBUTE_ALWAYS_INLINE
  210. #endif
  211. #ifdef __GNUC__
  212. #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn))
  213. #elif defined(_MSC_VER)
  214. #define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn)
  215. #else
  216. #define LLVM_ATTRIBUTE_NORETURN
  217. #endif
  218. /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
  219. /// pedantic diagnostics.
  220. #ifdef __GNUC__
  221. #define LLVM_EXTENSION __extension__
  222. #else
  223. #define LLVM_EXTENSION
  224. #endif
  225. // LLVM_ATTRIBUTE_DEPRECATED(decl, "message")
  226. #if __has_feature(attribute_deprecated_with_message)
  227. # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
  228. decl __attribute__((deprecated(message)))
  229. #elif defined(__GNUC__)
  230. # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
  231. decl __attribute__((deprecated))
  232. #elif defined(_MSC_VER)
  233. # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
  234. __declspec(deprecated(message)) decl
  235. #else
  236. # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
  237. decl
  238. #endif
  239. /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
  240. /// to an expression which states that it is undefined behavior for the
  241. /// compiler to reach this point. Otherwise is not defined.
  242. #if defined(__clang__) || (__GNUC__ > 4) \
  243. || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
  244. # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
  245. #elif defined(_MSC_VER)
  246. # define LLVM_BUILTIN_UNREACHABLE __assume(false)
  247. #endif
  248. /// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression
  249. /// which causes the program to exit abnormally.
  250. #if defined(__clang__) || (__GNUC__ > 4) \
  251. || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
  252. # define LLVM_BUILTIN_TRAP __builtin_trap()
  253. #else
  254. # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
  255. #endif
  256. /// \macro LLVM_ASSUME_ALIGNED
  257. /// \brief Returns a pointer with an assumed alignment.
  258. #if !defined(__clang__) && ((__GNUC__ > 4) \
  259. || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
  260. // FIXME: Enable on clang when it supports it.
  261. # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
  262. #elif defined(LLVM_BUILTIN_UNREACHABLE)
  263. # define LLVM_ASSUME_ALIGNED(p, a) \
  264. (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
  265. #else
  266. # define LLVM_ASSUME_ALIGNED(p, a) (p)
  267. #endif
  268. /// \macro LLVM_FUNCTION_NAME
  269. /// \brief Expands to __func__ on compilers which support it. Otherwise,
  270. /// expands to a compiler-dependent replacement.
  271. #if defined(_MSC_VER)
  272. # define LLVM_FUNCTION_NAME __FUNCTION__
  273. #else
  274. # define LLVM_FUNCTION_NAME __func__
  275. #endif
  276. #if defined(HAVE_SANITIZER_MSAN_INTERFACE_H)
  277. # include <sanitizer/msan_interface.h>
  278. #else
  279. # define __msan_allocated_memory(p, size)
  280. # define __msan_unpoison(p, size)
  281. #endif
  282. /// \macro LLVM_MEMORY_SANITIZER_BUILD
  283. /// \brief Whether LLVM itself is built with MemorySanitizer instrumentation.
  284. #if __has_feature(memory_sanitizer)
  285. # define LLVM_MEMORY_SANITIZER_BUILD 1
  286. #else
  287. # define LLVM_MEMORY_SANITIZER_BUILD 0
  288. #endif
  289. /// \macro LLVM_ADDRESS_SANITIZER_BUILD
  290. /// \brief Whether LLVM itself is built with AddressSanitizer instrumentation.
  291. #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
  292. # define LLVM_ADDRESS_SANITIZER_BUILD 1
  293. #else
  294. # define LLVM_ADDRESS_SANITIZER_BUILD 0
  295. #endif
  296. /// \macro LLVM_IS_UNALIGNED_ACCESS_FAST
  297. /// \brief Is unaligned memory access fast on the host machine.
  298. ///
  299. /// Don't specialize on alignment for platforms where unaligned memory accesses
  300. /// generates the same code as aligned memory accesses for common types.
  301. #if defined(_M_AMD64) || defined(_M_IX86) || defined(__amd64) || \
  302. defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || \
  303. defined(_X86_) || defined(__i386) || defined(__i386__)
  304. # define LLVM_IS_UNALIGNED_ACCESS_FAST 1
  305. #else
  306. # define LLVM_IS_UNALIGNED_ACCESS_FAST 0
  307. #endif
  308. /// \macro LLVM_EXPLICIT
  309. /// \brief Expands to explicit on compilers which support explicit conversion
  310. /// operators. Otherwise expands to nothing.
  311. #if (__has_feature(cxx_explicit_conversions) \
  312. || defined(__GXX_EXPERIMENTAL_CXX0X__))
  313. #define LLVM_EXPLICIT explicit
  314. #else
  315. #define LLVM_EXPLICIT
  316. #endif
  317. /// \macro LLVM_STATIC_ASSERT
  318. /// \brief Expands to C/C++'s static_assert on compilers which support it.
  319. #if __has_feature(cxx_static_assert)
  320. # define LLVM_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
  321. #elif __has_feature(c_static_assert)
  322. # define LLVM_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg)
  323. #else
  324. # define LLVM_STATIC_ASSERT(expr, msg)
  325. #endif
  326. #endif