WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
Compiler.h
Go to the documentation of this file.
1//===-- llvm/Support/Compiler.h - Compiler abstraction support --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines several macros, based on the current compiler. This allows
10// use of compiler-specific features in a way that remains portable. This header
11// can be included from either C or C++.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef WPIUTIL_WPI_COMPILER_H
16#define WPIUTIL_WPI_COMPILER_H
17
18
19#include <stddef.h>
20
21#if defined(_MSC_VER)
22#include <sal.h>
23#endif
24
25#ifndef __has_feature
26# define __has_feature(x) 0
27#endif
28
29#ifndef __has_extension
30# define __has_extension(x) 0
31#endif
32
33#ifndef __has_attribute
34# define __has_attribute(x) 0
35#endif
36
37#ifndef __has_builtin
38# define __has_builtin(x) 0
39#endif
40
41// Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in
42// C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid.
43#ifndef LLVM_HAS_CPP_ATTRIBUTE
44#if defined(__cplusplus) && defined(__has_cpp_attribute)
45# define LLVM_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
46#else
47# define LLVM_HAS_CPP_ATTRIBUTE(x) 0
48#endif
49#endif
50
51/// \macro LLVM_GNUC_PREREQ
52/// Extend the default __GNUC_PREREQ even if glibc's features.h isn't
53/// available.
54#ifndef LLVM_GNUC_PREREQ
55# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
56# define LLVM_GNUC_PREREQ(maj, min, patch) \
57 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
58 ((maj) << 20) + ((min) << 10) + (patch))
59# elif defined(__GNUC__) && defined(__GNUC_MINOR__)
60# define LLVM_GNUC_PREREQ(maj, min, patch) \
61 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
62# else
63# define LLVM_GNUC_PREREQ(maj, min, patch) 0
64# endif
65#endif
66
67/// \macro LLVM_MSC_PREREQ
68/// Is the compiler MSVC of at least the specified version?
69/// The common \param version values to check for are:
70/// * 1910: VS2017, version 15.1 & 15.2
71/// * 1911: VS2017, version 15.3 & 15.4
72/// * 1912: VS2017, version 15.5
73/// * 1913: VS2017, version 15.6
74/// * 1914: VS2017, version 15.7
75/// * 1915: VS2017, version 15.8
76/// * 1916: VS2017, version 15.9
77/// * 1920: VS2019, version 16.0
78/// * 1921: VS2019, version 16.1
79/// * 1922: VS2019, version 16.2
80/// * 1923: VS2019, version 16.3
81/// * 1924: VS2019, version 16.4
82/// * 1925: VS2019, version 16.5
83/// * 1926: VS2019, version 16.6
84/// * 1927: VS2019, version 16.7
85/// * 1928: VS2019, version 16.8 + 16.9
86/// * 1929: VS2019, version 16.10 + 16.11
87/// * 1930: VS2022, version 17.0
88#ifndef LLVM_MSC_PREREQ
89#ifdef _MSC_VER
90#define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version))
91
92// We require at least VS 2019.
93#if !defined(LLVM_FORCE_USE_OLD_TOOLCHAIN)
94#if !LLVM_MSC_PREREQ(1920)
95#error LLVM requires at least VS 2019.
96#endif
97#endif
98
99#else
100#define LLVM_MSC_PREREQ(version) 0
101#endif
102#endif
103
104/// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
105/// into a shared library, then the class should be private to the library and
106/// not accessible from outside it. Can also be used to mark variables and
107/// functions, making them private to any shared library they are linked into.
108/// On PE/COFF targets, library visibility is the default, so this isn't needed.
109///
110/// LLVM_EXTERNAL_VISIBILITY - classes, functions, and variables marked with
111/// this attribute will be made public and visible outside of any shared library
112/// they are linked in to.
113
114#if LLVM_HAS_CPP_ATTRIBUTE(gnu::visibility) && defined(__GNUC__) && \
115 !defined(__clang__)
116#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN [[gnu::visibility("hidden")]]
117#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT [[gnu::visibility("default")]]
118#elif __has_attribute(visibility)
119#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
120#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT __attribute__((visibility("default")))
121#else
122#define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
123#define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
124#endif
125
126#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
127#define LLVM_EXTERNAL_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
128#else
129#define LLVM_EXTERNAL_VISIBILITY
130#endif
131
132#if (!(defined(_WIN32) || defined(__CYGWIN__)) || \
133 (defined(__MINGW32__) && defined(__clang__)))
134#define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
135// Clang compilers older then 15 do not support gnu style attributes on
136// namespaces.
137#if defined(__clang__) && __clang_major__ < 15
138#define LLVM_LIBRARY_VISIBILITY_NAMESPACE [[gnu::visibility("hidden")]]
139#else
140#define LLVM_LIBRARY_VISIBILITY_NAMESPACE LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
141#endif
142#define LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
143#elif defined(_WIN32)
144#define LLVM_ALWAYS_EXPORT __declspec(dllexport)
145#define LLVM_LIBRARY_VISIBILITY
146#define LLVM_LIBRARY_VISIBILITY_NAMESPACE
147#else
148#define LLVM_LIBRARY_VISIBILITY
149#define LLVM_ALWAYS_EXPORT
150#define LLVM_LIBRARY_VISIBILITY_NAMESPACE
151#endif
152
153/// LLVM_ABI is the main export/visibility macro to mark something as explicitly
154/// exported when llvm is built as a shared library with everything else that is
155/// unannotated will have internal visibility.
156///
157/// LLVM_ABI_EXPORT is for the special case for things like plugin symbol
158/// declarations or definitions where we don't want the macro to be switching
159/// between dllexport and dllimport on windows based on what codebase is being
160/// built, it will only be dllexport. For non windows platforms this macro
161/// behaves the same as LLVM_ABI.
162///
163/// LLVM_EXPORT_TEMPLATE is used on explicit template instantiations in source
164/// files that were declared extern in a header. This macro is only set as a
165/// compiler export attribute on windows, on other platforms it does nothing.
166///
167/// LLVM_TEMPLATE_ABI is for annotating extern template declarations in headers
168/// for both functions and classes. On windows its turned in to dllimport for
169/// library consumers, for other platforms its a default visibility attribute.
170///
171/// LLVM_C_ABI is used to annotated functions and data that need to be exported
172/// for the libllvm-c API. This used both for the llvm-c headers and for the
173/// functions declared in the different Target's c++ source files that don't
174/// include the header forward declaring them.
175#ifndef LLVM_ABI_GENERATING_ANNOTATIONS
176// Marker to add to classes or functions in public headers that should not have
177// export macros added to them by the clang tool
178#define LLVM_ABI_NOT_EXPORTED
179#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS) || \
180 defined(LLVM_ENABLE_PLUGINS)
181// Some libraries like those for tablegen are linked in to tools that used
182// in the build so can't depend on the llvm shared library. If export macros
183// were left enabled when building these we would get duplicate or
184// missing symbol linker errors on windows.
185#if defined(LLVM_BUILD_STATIC)
186#define LLVM_ABI
187#define LLVM_TEMPLATE_ABI
188#define LLVM_EXPORT_TEMPLATE
189#define LLVM_ABI_EXPORT
190#elif defined(_WIN32) && !defined(__MINGW32__)
191#if defined(LLVM_EXPORTS)
192#define LLVM_ABI __declspec(dllexport)
193#define LLVM_TEMPLATE_ABI
194#define LLVM_EXPORT_TEMPLATE __declspec(dllexport)
195#else
196#define LLVM_ABI __declspec(dllimport)
197#define LLVM_TEMPLATE_ABI __declspec(dllimport)
198#define LLVM_EXPORT_TEMPLATE
199#endif
200#define LLVM_ABI_EXPORT __declspec(dllexport)
201#elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \
202 defined(__MVS__)
203#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
204#define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
205#define LLVM_EXPORT_TEMPLATE
206#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
207#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)
208#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
209#define LLVM_TEMPLATE_ABI
210#define LLVM_EXPORT_TEMPLATE
211#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
212#endif
213#else
214#define LLVM_ABI
215#define LLVM_TEMPLATE_ABI
216#define LLVM_EXPORT_TEMPLATE
217#define LLVM_ABI_EXPORT
218#endif
219#define LLVM_C_ABI LLVM_ABI
220#endif
221
222#ifndef LLVM_PREFETCH
223#if defined(__GNUC__)
224#define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
225#else
226#define LLVM_PREFETCH(addr, rw, locality)
227#endif
228#endif
229
230#ifndef LLVM_ATTRIBUTE_USED
231#if __has_attribute(used)
232#define LLVM_ATTRIBUTE_USED __attribute__((__used__))
233#else
234#define LLVM_ATTRIBUTE_USED
235#endif
236#endif
237
238#if defined(__clang__)
239#define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
240#else
241#define LLVM_DEPRECATED(MSG, FIX) [[deprecated(MSG)]]
242#endif
243
244// clang-format off
245#if defined(__clang__) || defined(__GNUC__)
246#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \
247 _Pragma("GCC diagnostic push") \
248 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
249#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP \
250 _Pragma("GCC diagnostic pop")
251#elif defined(_MSC_VER)
252#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH \
253 _Pragma("warning(push)") \
254 _Pragma("warning(disable : 4996)")
255#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP \
256 _Pragma("warning(pop)")
257#else
258#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
259#define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
260#endif
261// clang-format on
262
263// Indicate that a non-static, non-const C++ member function reinitializes
264// the entire object to a known state, independent of the previous state of
265// the object.
266//
267// The clang-tidy check bugprone-use-after-move recognizes this attribute as a
268// marker that a moved-from object has left the indeterminate state and can be
269// reused.
270#if LLVM_HAS_CPP_ATTRIBUTE(clang::reinitializes)
271#define LLVM_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
272#else
273#define LLVM_ATTRIBUTE_REINITIALIZES
274#endif
275
276// Some compilers warn about unused functions. When a function is sometimes
277// used or not depending on build settings (e.g. a function only called from
278// within "assert"), this attribute can be used to suppress such warnings.
279//
280// However, it shouldn't be used for unused *variables*, as those have a much
281// more portable solution:
282// (void)unused_var_name;
283// Prefer cast-to-void wherever it is sufficient.
284#ifndef LLVM_ATTRIBUTE_UNUSED
285#if __has_attribute(unused)
286#define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
287#else
288#define LLVM_ATTRIBUTE_UNUSED
289#endif
290#endif
291
292// FIXME: Provide this for PE/COFF targets.
293#if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \
294 !defined(_WIN32)
295#define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
296#else
297#define LLVM_ATTRIBUTE_WEAK
298#endif
299
300#ifndef LLVM_READNONE
301// Prior to clang 3.2, clang did not accept any spelling of
302// __has_attribute(const), so assume it is supported.
303#if defined(__clang__) || defined(__GNUC__)
304// aka 'CONST' but following LLVM Conventions.
305#define LLVM_READNONE __attribute__((__const__))
306#else
307#define LLVM_READNONE
308#endif
309#endif
310
311#ifndef LLVM_READONLY
312#if __has_attribute(pure) || defined(__GNUC__)
313// aka 'PURE' but following LLVM Conventions.
314#define LLVM_READONLY __attribute__((__pure__))
315#else
316#define LLVM_READONLY
317#endif
318#endif
319
320#if __has_attribute(minsize)
321#define LLVM_ATTRIBUTE_MINSIZE __attribute__((minsize))
322#else
323#define LLVM_ATTRIBUTE_MINSIZE
324#endif
325
326#ifndef LLVM_LIKELY
327#if __has_builtin(__builtin_expect) || defined(__GNUC__)
328#define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
329#define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
330#else
331#define LLVM_LIKELY(EXPR) (EXPR)
332#define LLVM_UNLIKELY(EXPR) (EXPR)
333#endif
334#endif
335
336/// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so,
337/// mark a method "not for inlining".
338#ifndef LLVM_ATTRIBUTE_NOINLINE
339#if __has_attribute(noinline)
340#define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
341#elif defined(_MSC_VER)
342#define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
343#else
344#define LLVM_ATTRIBUTE_NOINLINE
345#endif
346#endif
347
348/// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do
349/// so, mark a method "always inline" because it is performance sensitive.
350#ifndef LLVM_ATTRIBUTE_ALWAYS_INLINE
351#if __has_attribute(always_inline)
352#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
353#elif defined(_MSC_VER)
354#define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
355#else
356#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
357#endif
358#endif
359
360/// LLVM_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do
361/// so, mark a method "no debug" because debug info makes the debugger
362/// experience worse.
363#if __has_attribute(nodebug)
364#define LLVM_ATTRIBUTE_NODEBUG __attribute__((nodebug))
365#else
366#define LLVM_ATTRIBUTE_NODEBUG
367#endif
368
369#ifndef LLVM_ATTRIBUTE_RETURNS_NONNULL
370#if __has_attribute(returns_nonnull)
371#define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
372#elif defined(_MSC_VER)
373#define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_
374#else
375#define LLVM_ATTRIBUTE_RETURNS_NONNULL
376#endif
377#endif
378
379/// LLVM_ATTRIBUTE_RESTRICT - Annotates a pointer to tell the compiler that
380/// it is not aliased in the current scope.
381#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
382#define LLVM_ATTRIBUTE_RESTRICT __restrict
383#else
384#define LLVM_ATTRIBUTE_RESTRICT
385#endif
386
387/// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a
388/// pointer that does not alias any other valid pointer.
389#ifndef LLVM_ATTRIBUTE_RETURNS_NOALIAS
390#ifdef __GNUC__
391#define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
392#elif defined(_MSC_VER)
393#define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
394#else
395#define LLVM_ATTRIBUTE_RETURNS_NOALIAS
396#endif
397#endif
398
399/// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
400#ifndef LLVM_FALLTHROUGH
401#if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough)
402#define LLVM_FALLTHROUGH [[fallthrough]]
403#elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
404#define LLVM_FALLTHROUGH [[gnu::fallthrough]]
405#elif __has_attribute(fallthrough)
406#define LLVM_FALLTHROUGH __attribute__((fallthrough))
407#elif LLVM_HAS_CPP_ATTRIBUTE(clang::fallthrough)
408#define LLVM_FALLTHROUGH [[clang::fallthrough]]
409#else
410#define LLVM_FALLTHROUGH
411#endif
412#endif
413
414/// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that
415/// they are constant initialized.
416#if LLVM_HAS_CPP_ATTRIBUTE(clang::require_constant_initialization)
417#define LLVM_REQUIRE_CONSTANT_INITIALIZATION \
418 [[clang::require_constant_initialization]]
419#else
420#define LLVM_REQUIRE_CONSTANT_INITIALIZATION
421#endif
422
423/// LLVM_GSL_OWNER - Apply this to owning classes like SmallVector to enable
424/// lifetime warnings.
425#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Owner)
426#define LLVM_GSL_OWNER [[gsl::Owner]]
427#else
428#define LLVM_GSL_OWNER
429#endif
430
431/// LLVM_GSL_POINTER - Apply this to non-owning classes like
432/// std::string_view to enable lifetime warnings.
433#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer)
434#define LLVM_GSL_POINTER [[gsl::Pointer]]
435#else
436#define LLVM_GSL_POINTER
437#endif
438
439#if LLVM_HAS_CPP_ATTRIBUTE(clang::lifetimebound)
440#define LLVM_LIFETIME_BOUND [[clang::lifetimebound]]
441#else
442#define LLVM_LIFETIME_BOUND
443#endif
444
445#if LLVM_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L
446#define LLVM_CTOR_NODISCARD [[nodiscard]]
447#else
448#define LLVM_CTOR_NODISCARD
449#endif
450
451/// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
452/// pedantic diagnostics.
453#ifndef LLVM_EXTENSION
454#ifdef __GNUC__
455#define LLVM_EXTENSION __extension__
456#else
457#define LLVM_EXTENSION
458#endif
459#endif
460
461/// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
462/// to an expression which states that it is undefined behavior for the
463/// compiler to reach this point. Otherwise is not defined.
464///
465/// '#else' is intentionally left out so that other macro logic (e.g.,
466/// LLVM_ASSUME_ALIGNED and wpi_unreachable()) can detect whether
467/// LLVM_BUILTIN_UNREACHABLE has a definition.
468#ifndef LLVM_BUILTIN_UNREACHABLE
469#if __has_builtin(__builtin_unreachable) || defined(__GNUC__)
470# define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
471#elif defined(_MSC_VER)
472# define LLVM_BUILTIN_UNREACHABLE __assume(false)
473#endif
474#endif
475
476/// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression
477/// which causes the program to exit abnormally.
478#ifndef LLVM_BUILTIN_TRAP
479#if __has_builtin(__builtin_trap) || defined(__GNUC__)
480# define LLVM_BUILTIN_TRAP __builtin_trap()
481#elif defined(_MSC_VER)
482// The __debugbreak intrinsic is supported by MSVC, does not require forward
483// declarations involving platform-specific typedefs (unlike RaiseException),
484// results in a call to vectored exception handlers, and encodes to a short
485// instruction that still causes the trapping behavior we want.
486# define LLVM_BUILTIN_TRAP __debugbreak()
487#else
488# define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
489#endif
490#endif
491
492/// LLVM_BUILTIN_DEBUGTRAP - On compilers which support it, expands to
493/// an expression which causes the program to break while running
494/// under a debugger.
495#ifndef LLVM_BUILTIN_DEBUGTRAP
496#if __has_builtin(__builtin_debugtrap)
497# define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap()
498#elif defined(_MSC_VER)
499// The __debugbreak intrinsic is supported by MSVC and breaks while
500// running under the debugger, and also supports invoking a debugger
501// when the OS is configured appropriately.
502# define LLVM_BUILTIN_DEBUGTRAP __debugbreak()
503#else
504// Just continue execution when built with compilers that have no
505// support. This is a debugging aid and not intended to force the
506// program to abort if encountered.
507# define LLVM_BUILTIN_DEBUGTRAP
508#endif
509#endif
510
511/// \macro LLVM_ASSUME_ALIGNED
512/// Returns a pointer with an assumed alignment.
513#ifndef LLVM_ASSUME_ALIGNED
514#if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__)
515# define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
516#elif defined(LLVM_BUILTIN_UNREACHABLE)
517# define LLVM_ASSUME_ALIGNED(p, a) \
518 (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
519#else
520# define LLVM_ASSUME_ALIGNED(p, a) (p)
521#endif
522#endif
523
524/// \macro LLVM_PACKED
525/// Used to specify a packed structure.
526/// LLVM_PACKED(
527/// struct A {
528/// int i;
529/// int j;
530/// int k;
531/// long long l;
532/// });
533///
534/// LLVM_PACKED_START
535/// struct B {
536/// int i;
537/// int j;
538/// int k;
539/// long long l;
540/// };
541/// LLVM_PACKED_END
542#ifndef LLVM_PACKED
543#ifdef _MSC_VER
544# define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))
545# define LLVM_PACKED_START __pragma(pack(push, 1))
546# define LLVM_PACKED_END __pragma(pack(pop))
547#else
548# define LLVM_PACKED(d) d __attribute__((packed))
549# define LLVM_PACKED_START _Pragma("pack(push, 1)")
550# define LLVM_PACKED_END _Pragma("pack(pop)")
551#endif
552#endif
553
554/// \macro LLVM_MEMORY_SANITIZER_BUILD
555/// Whether LLVM itself is built with MemorySanitizer instrumentation.
556#if __has_feature(memory_sanitizer)
557# define LLVM_MEMORY_SANITIZER_BUILD 1
558# include <sanitizer/msan_interface.h>
559# define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__((no_sanitize_memory))
560#else
561# define LLVM_MEMORY_SANITIZER_BUILD 0
562# define __msan_allocated_memory(p, size)
563# define __msan_unpoison(p, size)
564# define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE
565#endif
566
567/// \macro LLVM_ADDRESS_SANITIZER_BUILD
568/// Whether LLVM itself is built with AddressSanitizer instrumentation.
569#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
570# define LLVM_ADDRESS_SANITIZER_BUILD 1
571#if __has_include(<sanitizer/asan_interface.h>)
572# include <sanitizer/asan_interface.h>
573#else
574// These declarations exist to support ASan with MSVC. If MSVC eventually ships
575// asan_interface.h in their headers, then we can remove this.
576#ifdef __cplusplus
577extern "C" {
578#endif
579void __asan_poison_memory_region(void const volatile *addr, size_t size);
580void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
581#ifdef __cplusplus
582} // extern "C"
583#endif
584#endif
585#else
586# define LLVM_ADDRESS_SANITIZER_BUILD 0
587# define __asan_poison_memory_region(p, size)
588# define __asan_unpoison_memory_region(p, size)
589#endif
590
591/// \macro LLVM_HWADDRESS_SANITIZER_BUILD
592/// Whether LLVM itself is built with HWAddressSanitizer instrumentation.
593#if __has_feature(hwaddress_sanitizer)
594#define LLVM_HWADDRESS_SANITIZER_BUILD 1
595#else
596#define LLVM_HWADDRESS_SANITIZER_BUILD 0
597#endif
598
599/// \macro LLVM_THREAD_SANITIZER_BUILD
600/// Whether LLVM itself is built with ThreadSanitizer instrumentation.
601#if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
602# define LLVM_THREAD_SANITIZER_BUILD 1
603#else
604# define LLVM_THREAD_SANITIZER_BUILD 0
605#endif
606
607#if LLVM_THREAD_SANITIZER_BUILD
608// Thread Sanitizer is a tool that finds races in code.
609// See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
610// tsan detects these exact functions by name.
611#ifdef __cplusplus
612extern "C" {
613#endif
614void AnnotateHappensAfter(const char *file, int line, const volatile void *cv);
615void AnnotateHappensBefore(const char *file, int line, const volatile void *cv);
616void AnnotateIgnoreWritesBegin(const char *file, int line);
617void AnnotateIgnoreWritesEnd(const char *file, int line);
618#ifdef __cplusplus
619}
620#endif
621
622// This marker is used to define a happens-before arc. The race detector will
623// infer an arc from the begin to the end when they share the same pointer
624// argument.
625# define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv)
626
627// This marker defines the destination of a happens-before arc.
628# define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv)
629
630// Ignore any races on writes between here and the next TsanIgnoreWritesEnd.
631# define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
632
633// Resume checking for racy writes.
634# define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
635#else
636# define TsanHappensBefore(cv)
637# define TsanHappensAfter(cv)
638# define TsanIgnoreWritesBegin()
639# define TsanIgnoreWritesEnd()
640#endif
641
642/// \macro LLVM_NO_SANITIZE
643/// Disable a particular sanitizer for a function.
644#ifndef LLVM_NO_SANITIZE
645#if __has_attribute(no_sanitize)
646#define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND)))
647#else
648#define LLVM_NO_SANITIZE(KIND)
649#endif
650#endif
651
652/// Mark debug helper function definitions like dump() that should not be
653/// stripped from debug builds.
654/// Note that you should also surround dump() functions with
655/// `#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)` so they do always
656/// get stripped in release builds.
657// FIXME: Move this to a private config.h as it's not usable in public headers.
658#ifndef LLVM_DUMP_METHOD
659#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
660#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
661#else
662#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
663#endif
664#endif
665
666/// \macro LLVM_PRETTY_FUNCTION
667/// Gets a user-friendly looking function signature for the current scope
668/// using the best available method on each platform. The exact format of the
669/// resulting string is implementation specific and non-portable, so this should
670/// only be used, for example, for logging or diagnostics.
671#ifndef LLVM_PRETTY_FUNCTION
672#if defined(_MSC_VER)
673#define LLVM_PRETTY_FUNCTION __FUNCSIG__
674#elif defined(__GNUC__) || defined(__clang__)
675#define LLVM_PRETTY_FUNCTION __PRETTY_FUNCTION__
676#else
677#define LLVM_PRETTY_FUNCTION __func__
678#endif
679#endif
680
681/// \macro LLVM_THREAD_LOCAL
682/// A thread-local storage specifier which can be used with globals,
683/// extern globals, and static globals.
684///
685/// This is essentially an extremely restricted analog to C++11's thread_local
686/// support. It uses thread_local if available, falling back on gcc __thread
687/// if not. __thread doesn't support many of the C++11 thread_local's
688/// features. You should only use this for PODs that you can statically
689/// initialize to some constant value. In almost all circumstances this is most
690/// appropriate for use with a pointer, integer, or small aggregation of
691/// pointers and integers.
692#if __has_feature(cxx_thread_local) || defined(_MSC_VER)
693#define LLVM_THREAD_LOCAL thread_local
694#else
695// Clang, GCC, and other compatible compilers used __thread prior to C++11 and
696// we only need the restricted functionality that provides.
697#define LLVM_THREAD_LOCAL __thread
698#endif
699
700/// \macro LLVM_ENABLE_EXCEPTIONS
701/// Whether LLVM is built with exception support.
702#if __has_feature(cxx_exceptions)
703#define LLVM_ENABLE_EXCEPTIONS 1
704#elif defined(__GNUC__) && defined(__EXCEPTIONS)
705#define LLVM_ENABLE_EXCEPTIONS 1
706#elif defined(_MSC_VER) && defined(_CPPUNWIND)
707#define LLVM_ENABLE_EXCEPTIONS 1
708#endif
709
710/// \macro LLVM_NO_PROFILE_INSTRUMENT_FUNCTION
711/// Disable the profile instrument for a function.
712#if __has_attribute(no_profile_instrument_function)
713#define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION \
714 __attribute__((no_profile_instrument_function))
715#else
716#define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION
717#endif
718
719/// \macro LLVM_PREFERRED_TYPE
720/// Adjust type of bit-field in debug info.
721#if __has_attribute(preferred_type)
722#define LLVM_PREFERRED_TYPE(T) __attribute__((preferred_type(T)))
723#else
724#define LLVM_PREFERRED_TYPE(T)
725#endif
726
727#endif
#define __asan_poison_memory_region(p, size)
Definition Compiler.h:587
#define __asan_unpoison_memory_region(p, size)
Definition Compiler.h:588
Definition VisionPipeline.h:7