mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
306 lines
9.6 KiB
Diff
306 lines
9.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: PJ Reiniger <pj.reiniger@gmail.com>
|
|
Date: Sat, 7 May 2022 22:28:13 -0400
|
|
Subject: [PATCH 05/34] \#ifdef guard safety
|
|
|
|
Prevents redefinition if someone is pulling in real LLVM, since the macros are in global namespace
|
|
---
|
|
llvm/include/llvm/Support/Compiler.h | 42 ++++++++++++++++++++++++++++
|
|
1 file changed, 42 insertions(+)
|
|
|
|
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
|
|
index f2b356ef04be557795afe9c356acc4af53fcdf52..e6cd94157803dea836c13195a4d5f795b5d1c8a6 100644
|
|
--- a/llvm/include/llvm/Support/Compiler.h
|
|
+++ b/llvm/include/llvm/Support/Compiler.h
|
|
@@ -90,6 +90,7 @@
|
|
/// * 1928: VS2019, version 16.8 + 16.9
|
|
/// * 1929: VS2019, version 16.10 + 16.11
|
|
/// * 1930: VS2022, version 17.0
|
|
+#ifndef LLVM_MSC_PREREQ
|
|
#ifdef _MSC_VER
|
|
#define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version))
|
|
|
|
@@ -103,6 +104,7 @@
|
|
#else
|
|
#define LLVM_MSC_PREREQ(version) 0
|
|
#endif
|
|
+#endif
|
|
|
|
/// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
|
|
/// into a shared library, then the class should be private to the library and
|
|
@@ -218,11 +220,13 @@
|
|
#define LLVM_ABI_FOR_TEST LLVM_ABI
|
|
#endif
|
|
|
|
+#ifndef LLVM_PREFETCH
|
|
#if defined(__GNUC__)
|
|
#define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
|
|
#else
|
|
#define LLVM_PREFETCH(addr, rw, locality)
|
|
#endif
|
|
+#endif
|
|
|
|
#if __has_attribute(uninitialized)
|
|
#define LLVM_ATTRIBUTE_UNINITIALIZED __attribute__((uninitialized))
|
|
@@ -230,11 +234,13 @@
|
|
#define LLVM_ATTRIBUTE_UNINITIALIZED
|
|
#endif
|
|
|
|
+#ifndef LLVM_ATTRIBUTE_USED
|
|
#if __has_attribute(used)
|
|
#define LLVM_ATTRIBUTE_USED __attribute__((__used__))
|
|
#else
|
|
#define LLVM_ATTRIBUTE_USED
|
|
#endif
|
|
+#endif
|
|
|
|
// Only enabled for clang:
|
|
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99587
|
|
@@ -292,11 +298,13 @@
|
|
// more portable solution:
|
|
// (void)unused_var_name;
|
|
// Prefer cast-to-void wherever it is sufficient.
|
|
+#ifndef LLVM_ATTRIBUTE_UNUSED
|
|
#if __has_attribute(unused)
|
|
#define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
|
|
#else
|
|
#define LLVM_ATTRIBUTE_UNUSED
|
|
#endif
|
|
+#endif
|
|
|
|
// FIXME: Provide this for PE/COFF targets.
|
|
#if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \
|
|
@@ -306,6 +314,7 @@
|
|
#define LLVM_ATTRIBUTE_WEAK
|
|
#endif
|
|
|
|
+#ifndef LLVM_READNONE
|
|
// Prior to clang 3.2, clang did not accept any spelling of
|
|
// __has_attribute(const), so assume it is supported.
|
|
#if defined(__clang__) || defined(__GNUC__)
|
|
@@ -314,13 +323,16 @@
|
|
#else
|
|
#define LLVM_READNONE
|
|
#endif
|
|
+#endif
|
|
|
|
+#ifndef LLVM_READONLY
|
|
#if __has_attribute(pure) || defined(__GNUC__)
|
|
// aka 'PURE' but following LLVM Conventions.
|
|
#define LLVM_READONLY __attribute__((__pure__))
|
|
#else
|
|
#define LLVM_READONLY
|
|
#endif
|
|
+#endif
|
|
|
|
#if __has_attribute(minsize)
|
|
#define LLVM_ATTRIBUTE_MINSIZE __attribute__((minsize))
|
|
@@ -328,6 +340,7 @@
|
|
#define LLVM_ATTRIBUTE_MINSIZE
|
|
#endif
|
|
|
|
+#ifndef LLVM_LIKELY
|
|
#if __has_builtin(__builtin_expect) || defined(__GNUC__)
|
|
#define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
|
|
#define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
|
|
@@ -335,9 +348,11 @@
|
|
#define LLVM_LIKELY(EXPR) (EXPR)
|
|
#define LLVM_UNLIKELY(EXPR) (EXPR)
|
|
#endif
|
|
+#endif
|
|
|
|
/// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so,
|
|
/// mark a method "not for inlining".
|
|
+#ifndef LLVM_ATTRIBUTE_NOINLINE
|
|
#if __has_attribute(noinline)
|
|
#define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
|
|
#elif defined(_MSC_VER)
|
|
@@ -345,9 +360,11 @@
|
|
#else
|
|
#define LLVM_ATTRIBUTE_NOINLINE
|
|
#endif
|
|
+#endif
|
|
|
|
/// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do
|
|
/// so, mark a method "always inline" because it is performance sensitive.
|
|
+#ifndef LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
#if __has_attribute(always_inline)
|
|
#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
|
|
#elif defined(_MSC_VER)
|
|
@@ -355,6 +372,7 @@
|
|
#else
|
|
#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
|
|
#endif
|
|
+#endif
|
|
|
|
/// LLVM_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do
|
|
/// so, mark a method "no debug" because debug info makes the debugger
|
|
@@ -365,6 +383,7 @@
|
|
#define LLVM_ATTRIBUTE_NODEBUG
|
|
#endif
|
|
|
|
+#ifndef LLVM_ATTRIBUTE_RETURNS_NONNULL
|
|
#if __has_attribute(returns_nonnull)
|
|
#define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
|
|
#elif defined(_MSC_VER)
|
|
@@ -372,6 +391,7 @@
|
|
#else
|
|
#define LLVM_ATTRIBUTE_RETURNS_NONNULL
|
|
#endif
|
|
+#endif
|
|
|
|
/// LLVM_ATTRIBUTE_RESTRICT - Annotates a pointer to tell the compiler that
|
|
/// it is not aliased in the current scope.
|
|
@@ -383,6 +403,7 @@
|
|
|
|
/// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a
|
|
/// pointer that does not alias any other valid pointer.
|
|
+#ifndef LLVM_ATTRIBUTE_RETURNS_NOALIAS
|
|
#ifdef __GNUC__
|
|
#define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
|
|
#elif defined(_MSC_VER)
|
|
@@ -390,8 +411,10 @@
|
|
#else
|
|
#define LLVM_ATTRIBUTE_RETURNS_NOALIAS
|
|
#endif
|
|
+#endif
|
|
|
|
/// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
|
|
+#ifndef LLVM_FALLTHROUGH
|
|
#if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough)
|
|
#define LLVM_FALLTHROUGH [[fallthrough]]
|
|
#elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
|
|
@@ -403,6 +426,7 @@
|
|
#else
|
|
#define LLVM_FALLTHROUGH
|
|
#endif
|
|
+#endif
|
|
|
|
/// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that
|
|
/// they are constant initialized.
|
|
@@ -443,11 +467,13 @@
|
|
|
|
/// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
|
|
/// pedantic diagnostics.
|
|
+#ifndef LLVM_EXTENSION
|
|
#ifdef __GNUC__
|
|
#define LLVM_EXTENSION __extension__
|
|
#else
|
|
#define LLVM_EXTENSION
|
|
#endif
|
|
+#endif
|
|
|
|
/// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
|
|
/// to an expression which states that it is undefined behavior for the
|
|
@@ -456,14 +482,17 @@
|
|
/// '#else' is intentionally left out so that other macro logic (e.g.,
|
|
/// LLVM_ASSUME_ALIGNED and llvm_unreachable()) can detect whether
|
|
/// LLVM_BUILTIN_UNREACHABLE has a definition.
|
|
+#ifndef LLVM_BUILTIN_UNREACHABLE
|
|
#if __has_builtin(__builtin_unreachable) || defined(__GNUC__)
|
|
# define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
|
|
#elif defined(_MSC_VER)
|
|
# define LLVM_BUILTIN_UNREACHABLE __assume(false)
|
|
#endif
|
|
+#endif
|
|
|
|
/// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression
|
|
/// which causes the program to exit abnormally.
|
|
+#ifndef LLVM_BUILTIN_TRAP
|
|
#if __has_builtin(__builtin_trap) || defined(__GNUC__)
|
|
# define LLVM_BUILTIN_TRAP __builtin_trap()
|
|
#elif defined(_MSC_VER)
|
|
@@ -475,10 +504,12 @@
|
|
#else
|
|
# define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
|
|
#endif
|
|
+#endif
|
|
|
|
/// LLVM_BUILTIN_DEBUGTRAP - On compilers which support it, expands to
|
|
/// an expression which causes the program to break while running
|
|
/// under a debugger.
|
|
+#ifndef LLVM_BUILTIN_DEBUGTRAP
|
|
#if __has_builtin(__builtin_debugtrap)
|
|
# define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap()
|
|
#elif defined(_MSC_VER)
|
|
@@ -492,9 +523,11 @@
|
|
// program to abort if encountered.
|
|
# define LLVM_BUILTIN_DEBUGTRAP
|
|
#endif
|
|
+#endif
|
|
|
|
/// \macro LLVM_ASSUME_ALIGNED
|
|
/// Returns a pointer with an assumed alignment.
|
|
+#ifndef LLVM_ASSUME_ALIGNED
|
|
#if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__)
|
|
# define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
|
|
#elif defined(LLVM_BUILTIN_UNREACHABLE)
|
|
@@ -503,6 +536,7 @@
|
|
#else
|
|
# define LLVM_ASSUME_ALIGNED(p, a) (p)
|
|
#endif
|
|
+#endif
|
|
|
|
/// \macro LLVM_PACKED
|
|
/// Used to specify a packed structure.
|
|
@@ -522,6 +556,7 @@
|
|
/// long long l;
|
|
/// };
|
|
/// LLVM_PACKED_END
|
|
+#ifndef LLVM_PACKED
|
|
#ifdef _MSC_VER
|
|
# define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))
|
|
# define LLVM_PACKED_START __pragma(pack(push, 1))
|
|
@@ -531,6 +566,7 @@
|
|
# define LLVM_PACKED_START _Pragma("pack(push, 1)")
|
|
# define LLVM_PACKED_END _Pragma("pack(pop)")
|
|
#endif
|
|
+#endif
|
|
|
|
/// \macro LLVM_MEMORY_SANITIZER_BUILD
|
|
/// Whether LLVM itself is built with MemorySanitizer instrumentation.
|
|
@@ -622,11 +658,13 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
|
|
|
/// \macro LLVM_NO_SANITIZE
|
|
/// Disable a particular sanitizer for a function.
|
|
+#ifndef LLVM_NO_SANITIZE
|
|
#if __has_attribute(no_sanitize)
|
|
#define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND)))
|
|
#else
|
|
#define LLVM_NO_SANITIZE(KIND)
|
|
#endif
|
|
+#endif
|
|
|
|
/// Mark debug helper function definitions like dump() that should not be
|
|
/// stripped from debug builds.
|
|
@@ -634,18 +672,21 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
|
/// `#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)` so they do always
|
|
/// get stripped in release builds.
|
|
// FIXME: Move this to a private config.h as it's not usable in public headers.
|
|
+#ifndef LLVM_DUMP_METHOD
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
|
#define LLVM_DUMP_METHOD \
|
|
LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED LLVM_ATTRIBUTE_RETAIN
|
|
#else
|
|
#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
|
|
#endif
|
|
+#endif
|
|
|
|
/// \macro LLVM_PRETTY_FUNCTION
|
|
/// Gets a user-friendly looking function signature for the current scope
|
|
/// using the best available method on each platform. The exact format of the
|
|
/// resulting string is implementation specific and non-portable, so this should
|
|
/// only be used, for example, for logging or diagnostics.
|
|
+#ifndef LLVM_PRETTY_FUNCTION
|
|
#if defined(_MSC_VER)
|
|
#define LLVM_PRETTY_FUNCTION __FUNCSIG__
|
|
#elif defined(__GNUC__) || defined(__clang__)
|
|
@@ -653,6 +694,7 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
|
#else
|
|
#define LLVM_PRETTY_FUNCTION __func__
|
|
#endif
|
|
+#endif
|
|
|
|
/// \macro LLVM_THREAD_LOCAL
|
|
/// A thread-local storage specifier which can be used with globals,
|