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
43# define __has_include(x) 0
48#ifndef LLVM_HAS_CPP_ATTRIBUTE
49#if defined(__cplusplus) && defined(__has_cpp_attribute)
50# define LLVM_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
52# define LLVM_HAS_CPP_ATTRIBUTE(x) 0
59#ifndef LLVM_GNUC_PREREQ
60# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
61# define LLVM_GNUC_PREREQ(maj, min, patch) \
62 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
63 ((maj) << 20) + ((min) << 10) + (patch))
64# elif defined(__GNUC__) && defined(__GNUC_MINOR__)
65# define LLVM_GNUC_PREREQ(maj, min, patch) \
66 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
68# define LLVM_GNUC_PREREQ(maj, min, patch) 0
94#define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version))
97#if !defined(LLVM_FORCE_USE_OLD_TOOLCHAIN)
98#if !LLVM_MSC_PREREQ(1920)
99#error LLVM requires at least VS 2019.
104#define LLVM_MSC_PREREQ(version) 0
117#if LLVM_HAS_CPP_ATTRIBUTE(gnu::visibility)
118#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN [[gnu::visibility("hidden")]]
119#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT [[gnu::visibility("default")]]
120#elif __has_attribute(visibility)
121#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
122#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT __attribute__((visibility("default")))
124#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
125#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
129#if (!(defined(_WIN32) || defined(__CYGWIN__)) || \
130 (defined(__MINGW32__) && defined(__clang__)))
131#define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
132#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
133#define LLVM_EXTERNAL_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
135#define LLVM_EXTERNAL_VISIBILITY
138#define LLVM_LIBRARY_VISIBILITY
139#define LLVM_EXTERNAL_VISIBILITY
143#define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
145#define LLVM_PREFETCH(addr, rw, locality)
148#if __has_attribute(used)
149#define LLVM_ATTRIBUTE_USED __attribute__((__used__))
151#define LLVM_ATTRIBUTE_USED
154#if defined(__clang__)
155#define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
157#define LLVM_DEPRECATED(MSG, FIX) [[deprecated(MSG)]]
161#if defined(__clang__) || defined(__GNUC__)
162#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \
163 _Pragma("GCC diagnostic push") \
164 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
165#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP \
166 _Pragma("GCC diagnostic pop")
167#elif defined(_MSC_VER)
168#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \
169 _Pragma("warning(push)") \
170 _Pragma("warning(disable : 4996)")
171#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP \
172 _Pragma("warning(pop)")
174#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
175#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
186#if LLVM_HAS_CPP_ATTRIBUTE(clang::reinitializes)
187#define LLVM_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
189#define LLVM_ATTRIBUTE_REINITIALIZES
200#if __has_attribute(unused)
201#define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
203#define LLVM_ATTRIBUTE_UNUSED
207#if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \
209#define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
211#define LLVM_ATTRIBUTE_WEAK
216#if defined(__clang__) || defined(__GNUC__)
218#define LLVM_READNONE __attribute__((__const__))
223#if __has_attribute(pure) || defined(__GNUC__)
225#define LLVM_READONLY __attribute__((__pure__))
230#if __has_attribute(minsize)
231#define LLVM_ATTRIBUTE_MINSIZE __attribute__((minsize))
233#define LLVM_ATTRIBUTE_MINSIZE
236#if __has_builtin(__builtin_expect) || defined(__GNUC__)
237#define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
238#define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
240#define LLVM_LIKELY(EXPR) (EXPR)
241#define LLVM_UNLIKELY(EXPR) (EXPR)
246#if __has_attribute(noinline)
247#define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
248#elif defined(_MSC_VER)
249#define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
251#define LLVM_ATTRIBUTE_NOINLINE
256#if __has_attribute(always_inline)
257#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
258#elif defined(_MSC_VER)
259#define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
261#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
267#if __has_attribute(nodebug)
268#define LLVM_ATTRIBUTE_NODEBUG __attribute__((nodebug))
270#define LLVM_ATTRIBUTE_NODEBUG
273#if __has_attribute(returns_nonnull)
274#define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
275#elif defined(_MSC_VER)
276#define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_
278#define LLVM_ATTRIBUTE_RETURNS_NONNULL
283#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
284#define LLVM_ATTRIBUTE_RESTRICT __restrict
286#define LLVM_ATTRIBUTE_RESTRICT
292#define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
293#elif defined(_MSC_VER)
294#define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
296#define LLVM_ATTRIBUTE_RETURNS_NOALIAS
300#if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough)
301#define LLVM_FALLTHROUGH [[fallthrough]]
302#elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
303#define LLVM_FALLTHROUGH [[gnu::fallthrough]]
304#elif __has_attribute(fallthrough)
305#define LLVM_FALLTHROUGH __attribute__((fallthrough))
306#elif LLVM_HAS_CPP_ATTRIBUTE(clang::fallthrough)
307#define LLVM_FALLTHROUGH [[clang::fallthrough]]
309#define LLVM_FALLTHROUGH
314#if LLVM_HAS_CPP_ATTRIBUTE(clang::require_constant_initialization)
315#define LLVM_REQUIRE_CONSTANT_INITIALIZATION \
316 [[clang::require_constant_initialization]]
318#define LLVM_REQUIRE_CONSTANT_INITIALIZATION
323#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Owner)
324#define LLVM_GSL_OWNER [[gsl::Owner]]
326#define LLVM_GSL_OWNER
331#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer)
332#define LLVM_GSL_POINTER [[gsl::Pointer]]
334#define LLVM_GSL_POINTER
337#if LLVM_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L
338#define LLVM_CTOR_NODISCARD [[nodiscard]]
340#define LLVM_CTOR_NODISCARD
346#define LLVM_EXTENSION __extension__
348#define LLVM_EXTENSION
358#if __has_builtin(__builtin_unreachable) || defined(__GNUC__)
359# define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
360#elif defined(_MSC_VER)
361# define LLVM_BUILTIN_UNREACHABLE __assume(false)
366#if __has_builtin(__builtin_trap) || defined(__GNUC__)
367# define LLVM_BUILTIN_TRAP __builtin_trap()
368#elif defined(_MSC_VER)
373# define LLVM_BUILTIN_TRAP __debugbreak()
375# define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
381#if __has_builtin(__builtin_debugtrap)
382# define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap()
383#elif defined(_MSC_VER)
387# define LLVM_BUILTIN_DEBUGTRAP __debugbreak()
392# define LLVM_BUILTIN_DEBUGTRAP
397#if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__)
398# define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
399#elif defined(LLVM_BUILTIN_UNREACHABLE)
400# define LLVM_ASSUME_ALIGNED(p, a) \
401 (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
403# define LLVM_ASSUME_ALIGNED(p, a) (p)
425# define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))
426# define LLVM_PACKED_START __pragma(pack(push, 1))
427# define LLVM_PACKED_END __pragma(pack(pop))
429# define LLVM_PACKED(d) d __attribute__((packed))
430# define LLVM_PACKED_START _Pragma("pack(push, 1)")
431# define LLVM_PACKED_END _Pragma("pack(pop)")
436#if __has_feature(memory_sanitizer)
437# define LLVM_MEMORY_SANITIZER_BUILD 1
438# include <sanitizer/msan_interface.h>
439# define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__((no_sanitize_memory))
441# define LLVM_MEMORY_SANITIZER_BUILD 0
442# define __msan_allocated_memory(p, size)
443# define __msan_unpoison(p, size)
444# define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE
449#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
450# define LLVM_ADDRESS_SANITIZER_BUILD 1
451#if __has_include(<sanitizer/asan_interface.h>)
452# include <sanitizer/asan_interface.h>
466# define LLVM_ADDRESS_SANITIZER_BUILD 0
467# define __asan_poison_memory_region(p, size)
468# define __asan_unpoison_memory_region(p, size)
473#if __has_feature(hwaddress_sanitizer)
474#define LLVM_HWADDRESS_SANITIZER_BUILD 1
476#define LLVM_HWADDRESS_SANITIZER_BUILD 0
481#if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
482# define LLVM_THREAD_SANITIZER_BUILD 1
484# define LLVM_THREAD_SANITIZER_BUILD 0
487#if LLVM_THREAD_SANITIZER_BUILD
494void AnnotateHappensAfter(
const char *
file,
int line,
const volatile void *cv);
495void AnnotateHappensBefore(
const char *
file,
int line,
const volatile void *cv);
496void AnnotateIgnoreWritesBegin(
const char *
file,
int line);
497void AnnotateIgnoreWritesEnd(
const char *
file,
int line);
505# define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv)
508# define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv)
511# define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
514# define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
516# define TsanHappensBefore(cv)
517# define TsanHappensAfter(cv)
518# define TsanIgnoreWritesBegin()
519# define TsanIgnoreWritesEnd()
524#if __has_attribute(no_sanitize)
525#define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND)))
527#define LLVM_NO_SANITIZE(KIND)
536#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
537#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
539#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
548#define LLVM_PRETTY_FUNCTION __FUNCSIG__
549#elif defined(__GNUC__) || defined(__clang__)
550#define LLVM_PRETTY_FUNCTION __PRETTY_FUNCTION__
552#define LLVM_PRETTY_FUNCTION __func__
566#if LLVM_ENABLE_THREADS
567#if __has_feature(cxx_thread_local) || defined(_MSC_VER)
568#define LLVM_THREAD_LOCAL thread_local
572#define LLVM_THREAD_LOCAL __thread
577#define LLVM_THREAD_LOCAL
582#if __has_feature(cxx_exceptions)
583#define LLVM_ENABLE_EXCEPTIONS 1
584#elif defined(__GNUC__) && defined(__EXCEPTIONS)
585#define LLVM_ENABLE_EXCEPTIONS 1
586#elif defined(_MSC_VER) && defined(_CPPUNWIND)
587#define LLVM_ENABLE_EXCEPTIONS 1
592#if __has_attribute(no_profile_instrument_function)
593#define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION \
594 __attribute__((no_profile_instrument_function))
596#define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION
601#if __has_attribute(preferred_type)
602#define LLVM_PREFERRED_TYPE(T) __attribute__((preferred_type(T)))
604#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)"