15#ifndef LLVM_SUPPORT_COMPILER_H
16#define LLVM_SUPPORT_COMPILER_H
18#include "llvm/Config/llvm-config.h"
27# define __has_feature(x) 0
30#ifndef __has_extension
31# define __has_extension(x) 0
34#ifndef __has_attribute
35# define __has_attribute(x) 0
39# define __has_builtin(x) 0
44#ifndef LLVM_HAS_CPP_ATTRIBUTE
45#if defined(__cplusplus) && defined(__has_cpp_attribute)
46# define LLVM_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
48# define LLVM_HAS_CPP_ATTRIBUTE(x) 0
55#ifndef LLVM_GNUC_PREREQ
56# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
57# define LLVM_GNUC_PREREQ(maj, min, patch) \
58 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
59 ((maj) << 20) + ((min) << 10) + (patch))
60# elif defined(__GNUC__) && defined(__GNUC_MINOR__)
61# define LLVM_GNUC_PREREQ(maj, min, patch) \
62 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
64# define LLVM_GNUC_PREREQ(maj, min, patch) 0
90#define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version))
93#if !defined(LLVM_FORCE_USE_OLD_TOOLCHAIN)
94#if !LLVM_MSC_PREREQ(1920)
95#error LLVM requires at least VS 2019.
100#define LLVM_MSC_PREREQ(version) 0
113#if LLVM_HAS_CPP_ATTRIBUTE(gnu::visibility)
114#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN [[gnu::visibility("hidden")]]
115#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT [[gnu::visibility("default")]]
116#elif __has_attribute(visibility)
117#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
118#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT __attribute__((visibility("default")))
120#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
121#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
125#if (!(defined(_WIN32) || defined(__CYGWIN__)) || \
126 (defined(__MINGW32__) && defined(__clang__)))
127#define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
128#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
129#define LLVM_EXTERNAL_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
131#define LLVM_EXTERNAL_VISIBILITY
134#define LLVM_LIBRARY_VISIBILITY
135#define LLVM_EXTERNAL_VISIBILITY
139#define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
141#define LLVM_PREFETCH(addr, rw, locality)
144#if __has_attribute(used)
145#define LLVM_ATTRIBUTE_USED __attribute__((__used__))
147#define LLVM_ATTRIBUTE_USED
150#if defined(__clang__)
151#define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
153#define LLVM_DEPRECATED(MSG, FIX) [[deprecated(MSG)]]
157#if defined(__clang__) || defined(__GNUC__)
158#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \
159 _Pragma("GCC diagnostic push") \
160 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
161#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP \
162 _Pragma("GCC diagnostic pop")
163#elif defined(_MSC_VER)
164#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \
165 _Pragma("warning(push)") \
166 _Pragma("warning(disable : 4996)")
167#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP \
168 _Pragma("warning(pop)")
170#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
171#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
182#if LLVM_HAS_CPP_ATTRIBUTE(clang::reinitializes)
183#define LLVM_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
185#define LLVM_ATTRIBUTE_REINITIALIZES
196#if __has_attribute(unused)
197#define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
199#define LLVM_ATTRIBUTE_UNUSED
203#if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \
205#define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
207#define LLVM_ATTRIBUTE_WEAK
212#if defined(__clang__) || defined(__GNUC__)
214#define LLVM_READNONE __attribute__((__const__))
219#if __has_attribute(pure) || defined(__GNUC__)
221#define LLVM_READONLY __attribute__((__pure__))
226#if __has_attribute(minsize)
227#define LLVM_ATTRIBUTE_MINSIZE __attribute__((minsize))
229#define LLVM_ATTRIBUTE_MINSIZE
232#if __has_builtin(__builtin_expect) || defined(__GNUC__)
233#define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
234#define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
236#define LLVM_LIKELY(EXPR) (EXPR)
237#define LLVM_UNLIKELY(EXPR) (EXPR)
242#if __has_attribute(noinline)
243#define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
244#elif defined(_MSC_VER)
245#define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
247#define LLVM_ATTRIBUTE_NOINLINE
252#if __has_attribute(always_inline)
253#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
254#elif defined(_MSC_VER)
255#define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
257#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
263#if __has_attribute(nodebug)
264#define LLVM_ATTRIBUTE_NODEBUG __attribute__((nodebug))
266#define LLVM_ATTRIBUTE_NODEBUG
269#if __has_attribute(returns_nonnull)
270#define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
271#elif defined(_MSC_VER)
272#define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_
274#define LLVM_ATTRIBUTE_RETURNS_NONNULL
279#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
280#define LLVM_ATTRIBUTE_RESTRICT __restrict
282#define LLVM_ATTRIBUTE_RESTRICT
288#define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
289#elif defined(_MSC_VER)
290#define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
292#define LLVM_ATTRIBUTE_RETURNS_NOALIAS
296#if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough)
297#define LLVM_FALLTHROUGH [[fallthrough]]
298#elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
299#define LLVM_FALLTHROUGH [[gnu::fallthrough]]
300#elif __has_attribute(fallthrough)
301#define LLVM_FALLTHROUGH __attribute__((fallthrough))
302#elif LLVM_HAS_CPP_ATTRIBUTE(clang::fallthrough)
303#define LLVM_FALLTHROUGH [[clang::fallthrough]]
305#define LLVM_FALLTHROUGH
310#if LLVM_HAS_CPP_ATTRIBUTE(clang::require_constant_initialization)
311#define LLVM_REQUIRE_CONSTANT_INITIALIZATION \
312 [[clang::require_constant_initialization]]
314#define LLVM_REQUIRE_CONSTANT_INITIALIZATION
319#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Owner)
320#define LLVM_GSL_OWNER [[gsl::Owner]]
322#define LLVM_GSL_OWNER
327#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer)
328#define LLVM_GSL_POINTER [[gsl::Pointer]]
330#define LLVM_GSL_POINTER
333#if LLVM_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L
334#define LLVM_CTOR_NODISCARD [[nodiscard]]
336#define LLVM_CTOR_NODISCARD
342#define LLVM_EXTENSION __extension__
344#define LLVM_EXTENSION
354#if __has_builtin(__builtin_unreachable) || defined(__GNUC__)
355# define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
356#elif defined(_MSC_VER)
357# define LLVM_BUILTIN_UNREACHABLE __assume(false)
362#if __has_builtin(__builtin_trap) || defined(__GNUC__)
363# define LLVM_BUILTIN_TRAP __builtin_trap()
364#elif defined(_MSC_VER)
369# define LLVM_BUILTIN_TRAP __debugbreak()
371# define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
377#if __has_builtin(__builtin_debugtrap)
378# define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap()
379#elif defined(_MSC_VER)
383# define LLVM_BUILTIN_DEBUGTRAP __debugbreak()
388# define LLVM_BUILTIN_DEBUGTRAP
393#if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__)
394# define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
395#elif defined(LLVM_BUILTIN_UNREACHABLE)
396# define LLVM_ASSUME_ALIGNED(p, a) \
397 (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
399# define LLVM_ASSUME_ALIGNED(p, a) (p)
421# define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))
422# define LLVM_PACKED_START __pragma(pack(push, 1))
423# define LLVM_PACKED_END __pragma(pack(pop))
425# define LLVM_PACKED(d) d __attribute__((packed))
426# define LLVM_PACKED_START _Pragma("pack(push, 1)")
427# define LLVM_PACKED_END _Pragma("pack(pop)")
432#if __has_feature(memory_sanitizer)
433# define LLVM_MEMORY_SANITIZER_BUILD 1
434# include <sanitizer/msan_interface.h>
435# define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__((no_sanitize_memory))
437# define LLVM_MEMORY_SANITIZER_BUILD 0
438# define __msan_allocated_memory(p, size)
439# define __msan_unpoison(p, size)
440# define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE
445#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
446# define LLVM_ADDRESS_SANITIZER_BUILD 1
447#if __has_include(<sanitizer/asan_interface.h>)
448# include <sanitizer/asan_interface.h>
462# define LLVM_ADDRESS_SANITIZER_BUILD 0
463# define __asan_poison_memory_region(p, size)
464# define __asan_unpoison_memory_region(p, size)
469#if __has_feature(hwaddress_sanitizer)
470#define LLVM_HWADDRESS_SANITIZER_BUILD 1
472#define LLVM_HWADDRESS_SANITIZER_BUILD 0
477#if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
478# define LLVM_THREAD_SANITIZER_BUILD 1
480# define LLVM_THREAD_SANITIZER_BUILD 0
483#if LLVM_THREAD_SANITIZER_BUILD
490void AnnotateHappensAfter(
const char *
file,
int line,
const volatile void *cv);
491void AnnotateHappensBefore(
const char *
file,
int line,
const volatile void *cv);
492void AnnotateIgnoreWritesBegin(
const char *
file,
int line);
493void AnnotateIgnoreWritesEnd(
const char *
file,
int line);
501# define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv)
504# define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv)
507# define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
510# define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
512# define TsanHappensBefore(cv)
513# define TsanHappensAfter(cv)
514# define TsanIgnoreWritesBegin()
515# define TsanIgnoreWritesEnd()
520#if __has_attribute(no_sanitize)
521#define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND)))
523#define LLVM_NO_SANITIZE(KIND)
532#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
533#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
535#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
544#define LLVM_PRETTY_FUNCTION __FUNCSIG__
545#elif defined(__GNUC__) || defined(__clang__)
546#define LLVM_PRETTY_FUNCTION __PRETTY_FUNCTION__
548#define LLVM_PRETTY_FUNCTION __func__
562#if LLVM_ENABLE_THREADS
563#if __has_feature(cxx_thread_local) || defined(_MSC_VER)
564#define LLVM_THREAD_LOCAL thread_local
568#define LLVM_THREAD_LOCAL __thread
573#define LLVM_THREAD_LOCAL
578#if __has_feature(cxx_exceptions)
579#define LLVM_ENABLE_EXCEPTIONS 1
580#elif defined(__GNUC__) && defined(__EXCEPTIONS)
581#define LLVM_ENABLE_EXCEPTIONS 1
582#elif defined(_MSC_VER) && defined(_CPPUNWIND)
583#define LLVM_ENABLE_EXCEPTIONS 1
588#if __has_attribute(no_profile_instrument_function)
589#define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION \
590 __attribute__((no_profile_instrument_function))
592#define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION
597#if __has_attribute(preferred_type)
598#define LLVM_PREFERRED_TYPE(T) __attribute__((preferred_type(T)))
600#define LLVM_PREFERRED_TYPE(T)
#define __asan_poison_memory_region(p, size)
#define __asan_unpoison_memory_region(p, size)
dot regions Print regions of function to dot file(with no function bodies)"