Go to the documentation of this file.
15 #ifndef LLVM_SUPPORT_COMPILER_H
16 #define LLVM_SUPPORT_COMPILER_H
18 #include "llvm/Config/llvm-config.h"
21 # define __has_feature(x) 0
24 #ifndef __has_extension
25 # define __has_extension(x) 0
28 #ifndef __has_attribute
29 # define __has_attribute(x) 0
33 # define __has_builtin(x) 0
39 #ifndef LLVM_GNUC_PREREQ
40 # if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
41 # define LLVM_GNUC_PREREQ(maj, min, patch) \
42 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
43 ((maj) << 20) + ((min) << 10) + (patch))
44 # elif defined(__GNUC__) && defined(__GNUC_MINOR__)
45 # define LLVM_GNUC_PREREQ(maj, min, patch) \
46 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
48 # define LLVM_GNUC_PREREQ(maj, min, patch) 0
58 #define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version))
61 #if !LLVM_MSC_PREREQ(1800)
62 #error LLVM requires at least MSVC 2013.
66 #define LLVM_MSC_PREREQ(version) 0
69 #if !defined(_MSC_VER) || defined(__clang__) || LLVM_MSC_PREREQ(1900)
70 #define LLVM_NOEXCEPT noexcept
79 #if __has_feature(cxx_rvalue_references) || LLVM_GNUC_PREREQ(4, 8, 1)
80 #define LLVM_HAS_RVALUE_REFERENCE_THIS 1
82 #define LLVM_HAS_RVALUE_REFERENCE_THIS 0
89 #if LLVM_HAS_RVALUE_REFERENCE_THIS
90 #define LLVM_LVALUE_FUNCTION &
92 #define LLVM_LVALUE_FUNCTION
95 #if __has_feature(cxx_constexpr) || defined(__GXX_EXPERIMENTAL_CXX0X__)
96 # define LLVM_CONSTEXPR constexpr
98 # define LLVM_CONSTEXPR
106 #if (__has_attribute(visibility) || LLVM_GNUC_PREREQ(4, 0, 0)) && \
107 !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(LLVM_ON_WIN32)
108 #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
110 #define LLVM_LIBRARY_VISIBILITY
113 #if __has_attribute(sentinel) || LLVM_GNUC_PREREQ(3, 0, 0)
114 #define LLVM_END_WITH_NULL __attribute__((sentinel))
116 #define LLVM_END_WITH_NULL
119 #if __has_attribute(used) || LLVM_GNUC_PREREQ(3, 1, 0)
120 #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
122 #define LLVM_ATTRIBUTE_USED
125 #if __has_attribute(warn_unused_result) || LLVM_GNUC_PREREQ(3, 4, 0)
126 #define LLVM_ATTRIBUTE_UNUSED_RESULT __attribute__((__warn_unused_result__))
128 #define LLVM_ATTRIBUTE_UNUSED_RESULT
139 #if __has_attribute(unused) || LLVM_GNUC_PREREQ(3, 1, 0)
140 #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
142 #define LLVM_ATTRIBUTE_UNUSED
146 #if (__has_attribute(weak) || LLVM_GNUC_PREREQ(4, 0, 0)) && \
147 (!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(LLVM_ON_WIN32))
148 #define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
150 #define LLVM_ATTRIBUTE_WEAK
155 #if defined(__clang__) || defined(__GNUC__)
157 #define LLVM_READNONE __attribute__((__const__))
159 #define LLVM_READNONE
162 #if __has_attribute(pure) || defined(__GNUC__)
164 #define LLVM_READONLY __attribute__((__pure__))
166 #define LLVM_READONLY
169 #if __has_builtin(__builtin_expect) || LLVM_GNUC_PREREQ(4, 0, 0)
170 #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
171 #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
173 #define LLVM_LIKELY(EXPR) (EXPR)
174 #define LLVM_UNLIKELY(EXPR) (EXPR)
179 #if __has_attribute(noinline) || LLVM_GNUC_PREREQ(3, 4, 0)
180 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
181 #elif defined(_MSC_VER)
182 #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
184 #define LLVM_ATTRIBUTE_NOINLINE
191 #if __has_attribute(always_inline) || LLVM_GNUC_PREREQ(4, 0, 0)
192 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
193 #elif defined(_MSC_VER)
194 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
196 #define LLVM_ATTRIBUTE_ALWAYS_INLINE
200 #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn))
201 #elif defined(_MSC_VER)
202 #define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn)
204 #define LLVM_ATTRIBUTE_NORETURN
207 #if __has_attribute(returns_nonnull) || LLVM_GNUC_PREREQ(4, 9, 0)
208 #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
210 #define LLVM_ATTRIBUTE_RETURNS_NONNULL
216 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
217 #elif defined(_MSC_VER)
218 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
220 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS
226 #define LLVM_EXTENSION __extension__
228 #define LLVM_EXTENSION
232 #if __has_feature(attribute_deprecated_with_message)
233 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
234 decl __attribute__((deprecated(message)))
235 #elif defined(__GNUC__)
236 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
237 decl __attribute__((deprecated))
238 #elif defined(_MSC_VER)
239 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
240 __declspec(deprecated(message)) decl
242 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
249 #if __has_builtin(__builtin_unreachable) || LLVM_GNUC_PREREQ(4, 5, 0)
250 # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
251 #elif defined(_MSC_VER)
252 # define LLVM_BUILTIN_UNREACHABLE __assume(false)
257 #if __has_builtin(__builtin_trap) || LLVM_GNUC_PREREQ(4, 3, 0)
258 # define LLVM_BUILTIN_TRAP __builtin_trap()
259 #elif defined(_MSC_VER)
264 # define LLVM_BUILTIN_TRAP __debugbreak()
266 # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
271 #if __has_builtin(__builtin_assume_aligned) || LLVM_GNUC_PREREQ(4, 7, 0)
272 # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
273 #elif defined(LLVM_BUILTIN_UNREACHABLE)
275 # define LLVM_ASSUME_ALIGNED(p, a) \
276 (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
278 # define LLVM_ASSUME_ALIGNED(p, a) (p)
289 # define LLVM_ALIGNAS(x) __declspec(align(x))
290 #elif __GNUC__ && !__has_feature(cxx_alignas) && !LLVM_GNUC_PREREQ(4, 8, 0)
291 # define LLVM_ALIGNAS(x) __attribute__((aligned(x)))
293 # define LLVM_ALIGNAS(x) alignas(x)
300 #ifdef __SIZEOF_POINTER__
301 # define LLVM_PTR_SIZE __SIZEOF_POINTER__
302 #elif defined(_WIN64)
303 # define LLVM_PTR_SIZE 8
304 #elif defined(_WIN32)
305 # define LLVM_PTR_SIZE 4
306 #elif defined(_MSC_VER)
307 # error "could not determine LLVM_PTR_SIZE as a constant int for MSVC"
309 # define LLVM_PTR_SIZE sizeof(void *)
315 #if defined(_MSC_VER)
316 # define LLVM_FUNCTION_NAME __FUNCTION__
318 # define LLVM_FUNCTION_NAME __func__
323 #if __has_feature(memory_sanitizer)
324 # define LLVM_MEMORY_SANITIZER_BUILD 1
325 # include <sanitizer/msan_interface.h>
327 # define LLVM_MEMORY_SANITIZER_BUILD 0
328 # define __msan_allocated_memory(p, size)
329 # define __msan_unpoison(p, size)
334 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
335 # define LLVM_ADDRESS_SANITIZER_BUILD 1
337 # define LLVM_ADDRESS_SANITIZER_BUILD 0
343 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
344 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
346 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
361 #if LLVM_ENABLE_THREADS
362 #if __has_feature(cxx_thread_local)
363 #define LLVM_THREAD_LOCAL thread_local
364 #elif defined(_MSC_VER)
366 #define LLVM_THREAD_LOCAL __declspec(thread)
370 #define LLVM_THREAD_LOCAL __thread
372 #else // !LLVM_ENABLE_THREADS
375 #define LLVM_THREAD_LOCAL