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) && defined(__GNUC__) && \
115#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN [[gnu::visibility("hidden")]]
116#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT [[gnu::visibility("default")]]
117#elif __has_attribute(visibility)
118#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
119#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT __attribute__((visibility("default")))
121#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
122#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
125#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
126#define LLVM_EXTERNAL_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
128#define LLVM_EXTERNAL_VISIBILITY
131#if (!(defined(_WIN32) || defined(__CYGWIN__)) || \
132 (defined(__MINGW32__) && defined(__clang__)))
133#define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
136#if defined(__clang__) && __clang_major__ < 15
137#define LLVM_LIBRARY_VISIBILITY_NAMESPACE [[gnu::visibility("hidden")]]
139#define LLVM_LIBRARY_VISIBILITY_NAMESPACE LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
141#define LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
143#define LLVM_ALWAYS_EXPORT __declspec(dllexport)
144#define LLVM_LIBRARY_VISIBILITY
145#define LLVM_LIBRARY_VISIBILITY_NAMESPACE
147#define LLVM_LIBRARY_VISIBILITY
148#define LLVM_ALWAYS_EXPORT
149#define LLVM_LIBRARY_VISIBILITY_NAMESPACE
174#ifndef LLVM_ABI_GENERATING_ANNOTATIONS
177#define LLVM_ABI_NOT_EXPORTED
178#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS) || \
179 defined(LLVM_ENABLE_PLUGINS)
184#if defined(LLVM_BUILD_STATIC)
186#define LLVM_TEMPLATE_ABI
187#define LLVM_EXPORT_TEMPLATE
188#define LLVM_ABI_EXPORT
189#elif defined(_WIN32) && !defined(__MINGW32__)
190#if defined(LLVM_EXPORTS)
191#define LLVM_ABI __declspec(dllexport)
192#define LLVM_TEMPLATE_ABI
193#define LLVM_EXPORT_TEMPLATE __declspec(dllexport)
195#define LLVM_ABI __declspec(dllimport)
196#define LLVM_TEMPLATE_ABI __declspec(dllimport)
197#define LLVM_EXPORT_TEMPLATE
199#define LLVM_ABI_EXPORT __declspec(dllexport)
200#elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \
202#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
203#define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
204#define LLVM_EXPORT_TEMPLATE
205#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
206#elif defined(__MACH__) || defined(__WASM__)
207#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
208#define LLVM_TEMPLATE_ABI
209#define LLVM_EXPORT_TEMPLATE
210#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
214#define LLVM_TEMPLATE_ABI
215#define LLVM_EXPORT_TEMPLATE
216#define LLVM_ABI_EXPORT
218#define LLVM_C_ABI LLVM_ABI
222#define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
224#define LLVM_PREFETCH(addr, rw, locality)
227#if __has_attribute(used)
228#define LLVM_ATTRIBUTE_USED __attribute__((__used__))
230#define LLVM_ATTRIBUTE_USED
233#if defined(__clang__)
234#define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
236#define LLVM_DEPRECATED(MSG, FIX) [[deprecated(MSG)]]
240#if defined(__clang__) || defined(__GNUC__)
241#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \
242 _Pragma("GCC diagnostic push") \
243 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
244#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP \
245 _Pragma("GCC diagnostic pop")
246#elif defined(_MSC_VER)
247#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \
248 _Pragma("warning(push)") \
249 _Pragma("warning(disable : 4996)")
250#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP \
251 _Pragma("warning(pop)")
253#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
254#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
265#if LLVM_HAS_CPP_ATTRIBUTE(clang::reinitializes)
266#define LLVM_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
268#define LLVM_ATTRIBUTE_REINITIALIZES
279#if __has_attribute(unused)
280#define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
282#define LLVM_ATTRIBUTE_UNUSED
286#if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \
288#define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
290#define LLVM_ATTRIBUTE_WEAK
295#if defined(__clang__) || defined(__GNUC__)
297#define LLVM_READNONE __attribute__((__const__))
302#if __has_attribute(pure) || defined(__GNUC__)
304#define LLVM_READONLY __attribute__((__pure__))
309#if __has_attribute(minsize)
310#define LLVM_ATTRIBUTE_MINSIZE __attribute__((minsize))
312#define LLVM_ATTRIBUTE_MINSIZE
315#if __has_builtin(__builtin_expect) || defined(__GNUC__)
316#define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
317#define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
319#define LLVM_LIKELY(EXPR) (EXPR)
320#define LLVM_UNLIKELY(EXPR) (EXPR)
325#if __has_attribute(noinline)
326#define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
327#elif defined(_MSC_VER)
328#define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
330#define LLVM_ATTRIBUTE_NOINLINE
335#if __has_attribute(always_inline)
336#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
337#elif defined(_MSC_VER)
338#define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
340#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
346#if __has_attribute(nodebug)
347#define LLVM_ATTRIBUTE_NODEBUG __attribute__((nodebug))
349#define LLVM_ATTRIBUTE_NODEBUG
352#if __has_attribute(returns_nonnull)
353#define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
354#elif defined(_MSC_VER)
355#define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_
357#define LLVM_ATTRIBUTE_RETURNS_NONNULL
362#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
363#define LLVM_ATTRIBUTE_RESTRICT __restrict
365#define LLVM_ATTRIBUTE_RESTRICT
371#define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
372#elif defined(_MSC_VER)
373#define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
375#define LLVM_ATTRIBUTE_RETURNS_NOALIAS
379#if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough)
380#define LLVM_FALLTHROUGH [[fallthrough]]
381#elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
382#define LLVM_FALLTHROUGH [[gnu::fallthrough]]
383#elif __has_attribute(fallthrough)
384#define LLVM_FALLTHROUGH __attribute__((fallthrough))
385#elif LLVM_HAS_CPP_ATTRIBUTE(clang::fallthrough)
386#define LLVM_FALLTHROUGH [[clang::fallthrough]]
388#define LLVM_FALLTHROUGH
393#if LLVM_HAS_CPP_ATTRIBUTE(clang::require_constant_initialization)
394#define LLVM_REQUIRE_CONSTANT_INITIALIZATION \
395 [[clang::require_constant_initialization]]
397#define LLVM_REQUIRE_CONSTANT_INITIALIZATION
402#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Owner)
403#define LLVM_GSL_OWNER [[gsl::Owner]]
405#define LLVM_GSL_OWNER
410#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer)
411#define LLVM_GSL_POINTER [[gsl::Pointer]]
413#define LLVM_GSL_POINTER
416#if LLVM_HAS_CPP_ATTRIBUTE(clang::lifetimebound)
417#define LLVM_LIFETIME_BOUND [[clang::lifetimebound]]
419#define LLVM_LIFETIME_BOUND
422#if LLVM_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L
423#define LLVM_CTOR_NODISCARD [[nodiscard]]
425#define LLVM_CTOR_NODISCARD
431#define LLVM_EXTENSION __extension__
433#define LLVM_EXTENSION
443#if __has_builtin(__builtin_unreachable) || defined(__GNUC__)
444# define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
445#elif defined(_MSC_VER)
446# define LLVM_BUILTIN_UNREACHABLE __assume(false)
451#if __has_builtin(__builtin_trap) || defined(__GNUC__)
452# define LLVM_BUILTIN_TRAP __builtin_trap()
453#elif defined(_MSC_VER)
458# define LLVM_BUILTIN_TRAP __debugbreak()
460# define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
466#if __has_builtin(__builtin_debugtrap)
467# define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap()
468#elif defined(_MSC_VER)
472# define LLVM_BUILTIN_DEBUGTRAP __debugbreak()
477# define LLVM_BUILTIN_DEBUGTRAP
482#if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__)
483# define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
484#elif defined(LLVM_BUILTIN_UNREACHABLE)
485# define LLVM_ASSUME_ALIGNED(p, a) \
486 (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
488# define LLVM_ASSUME_ALIGNED(p, a) (p)
510# define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))
511# define LLVM_PACKED_START __pragma(pack(push, 1))
512# define LLVM_PACKED_END __pragma(pack(pop))
514# define LLVM_PACKED(d) d __attribute__((packed))
515# define LLVM_PACKED_START _Pragma("pack(push, 1)")
516# define LLVM_PACKED_END _Pragma("pack(pop)")
521#if __has_feature(memory_sanitizer)
522# define LLVM_MEMORY_SANITIZER_BUILD 1
523# include <sanitizer/msan_interface.h>
524# define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__((no_sanitize_memory))
526# define LLVM_MEMORY_SANITIZER_BUILD 0
527# define __msan_allocated_memory(p, size)
528# define __msan_unpoison(p, size)
529# define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE
534#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
535# define LLVM_ADDRESS_SANITIZER_BUILD 1
536#if __has_include(<sanitizer/asan_interface.h>)
537# include <sanitizer/asan_interface.h>
551# define LLVM_ADDRESS_SANITIZER_BUILD 0
552# define __asan_poison_memory_region(p, size)
553# define __asan_unpoison_memory_region(p, size)
558#if __has_feature(hwaddress_sanitizer)
559#define LLVM_HWADDRESS_SANITIZER_BUILD 1
561#define LLVM_HWADDRESS_SANITIZER_BUILD 0
566#if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
567# define LLVM_THREAD_SANITIZER_BUILD 1
569# define LLVM_THREAD_SANITIZER_BUILD 0
572#if LLVM_THREAD_SANITIZER_BUILD
579void AnnotateHappensAfter(
const char *
file,
int line,
const volatile void *cv);
580void AnnotateHappensBefore(
const char *
file,
int line,
const volatile void *cv);
581void AnnotateIgnoreWritesBegin(
const char *
file,
int line);
582void AnnotateIgnoreWritesEnd(
const char *
file,
int line);
590# define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv)
593# define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv)
596# define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
599# define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
601# define TsanHappensBefore(cv)
602# define TsanHappensAfter(cv)
603# define TsanIgnoreWritesBegin()
604# define TsanIgnoreWritesEnd()
609#if __has_attribute(no_sanitize)
610#define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND)))
612#define LLVM_NO_SANITIZE(KIND)
621#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
622#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
624#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
633#define LLVM_PRETTY_FUNCTION __FUNCSIG__
634#elif defined(__GNUC__) || defined(__clang__)
635#define LLVM_PRETTY_FUNCTION __PRETTY_FUNCTION__
637#define LLVM_PRETTY_FUNCTION __func__
651#if LLVM_ENABLE_THREADS
652#if __has_feature(cxx_thread_local) || defined(_MSC_VER)
653#define LLVM_THREAD_LOCAL thread_local
657#define LLVM_THREAD_LOCAL __thread
662#define LLVM_THREAD_LOCAL
667#if __has_feature(cxx_exceptions)
668#define LLVM_ENABLE_EXCEPTIONS 1
669#elif defined(__GNUC__) && defined(__EXCEPTIONS)
670#define LLVM_ENABLE_EXCEPTIONS 1
671#elif defined(_MSC_VER) && defined(_CPPUNWIND)
672#define LLVM_ENABLE_EXCEPTIONS 1
677#if __has_attribute(no_profile_instrument_function)
678#define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION \
679 __attribute__((no_profile_instrument_function))
681#define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION
686#if __has_attribute(preferred_type)
687#define LLVM_PREFERRED_TYPE(T) __attribute__((preferred_type(T)))
689#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)"