| From 008e921f77933f475174d74a6b70309c6fbe0771 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 06/28] \#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 | 50 ++++++++++++++++++++++++++++ |
| 1 file changed, 50 insertions(+) |
| |
| diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h |
| index ede1cb172..8b8260b50 100644 |
| --- a/llvm/include/llvm/Support/Compiler.h |
| +++ b/llvm/include/llvm/Support/Compiler.h |
| @@ -86,6 +86,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)) |
| |
| @@ -99,6 +100,7 @@ |
| #else |
| #define LLVM_MSC_PREREQ(version) 0 |
| #endif |
| +#endif |
| |
| /// Does the compiler support ref-qualifiers for *this? |
| /// |
| @@ -112,11 +114,13 @@ |
| /// |
| /// This can be used to provide lvalue/rvalue overrides of member functions. |
| /// The rvalue override should be guarded by LLVM_HAS_RVALUE_REFERENCE_THIS |
| +#ifndef LLVM_LVALUE_FUNCTION |
| #if LLVM_HAS_RVALUE_REFERENCE_THIS |
| #define LLVM_LVALUE_FUNCTION & |
| #else |
| #define LLVM_LVALUE_FUNCTION |
| #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 |
| @@ -140,21 +144,26 @@ |
| #define LLVM_EXTERNAL_VISIBILITY |
| #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 |
| |
| +#ifndef LLVM_ATTRIBUTE_USED |
| #if __has_attribute(used) |
| #define LLVM_ATTRIBUTE_USED __attribute__((__used__)) |
| #else |
| #define LLVM_ATTRIBUTE_USED |
| #endif |
| +#endif |
| |
| /// LLVM_NODISCARD - Warn if a type or return value is discarded. |
| |
| // Use the 'nodiscard' attribute in C++17 or newer mode. |
| +#ifndef LLVM_NODISCARD |
| #if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(nodiscard) |
| #define LLVM_NODISCARD [[nodiscard]] |
| #elif LLVM_HAS_CPP_ATTRIBUTE(clang::warn_unused_result) |
| @@ -168,6 +177,7 @@ |
| #else |
| #define LLVM_NODISCARD |
| #endif |
| +#endif |
| |
| // Indicate that a non-static, non-const C++ member function reinitializes |
| // the entire object to a known state, independent of the previous state of |
| @@ -190,11 +200,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__) && \ |
| @@ -204,6 +216,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__) |
| @@ -212,13 +225,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)) |
| @@ -226,6 +242,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) |
| @@ -233,9 +250,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) |
| @@ -243,9 +262,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) |
| @@ -253,6 +274,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 |
| @@ -263,6 +285,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) |
| @@ -270,9 +293,11 @@ |
| #else |
| #define LLVM_ATTRIBUTE_RETURNS_NONNULL |
| #endif |
| +#endif |
| |
| /// \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) |
| @@ -280,8 +305,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) |
| @@ -293,6 +320,7 @@ |
| #else |
| #define LLVM_FALLTHROUGH |
| #endif |
| +#endif |
| |
| /// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that |
| /// they are constant initialized. |
| @@ -321,20 +349,25 @@ |
| |
| /// 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_ATTRIBUTE_DEPRECATED(decl, "message") |
| // This macro will be removed. |
| // Use C++14's attribute instead: [[deprecated("message")]] |
| +#ifndef LLVM_ATTRIBUTE_DEPRECATED |
| #define LLVM_ATTRIBUTE_DEPRECATED(decl, message) [[deprecated(message)]] decl |
| +#endif |
| |
| /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands |
| /// to an expression which states that it is undefined behavior for the |
| /// compiler to reach this point. Otherwise is not defined. |
| +#ifndef LLVM_BUILTIN_UNREACHABLE |
| #if __has_builtin(__builtin_unreachable) || defined(__GNUC__) |
| # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable() |
| #elif defined(_MSC_VER) |
| @@ -342,9 +375,11 @@ |
| #else |
| # define LLVM_BUILTIN_UNREACHABLE |
| #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) |
| @@ -356,10 +391,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) |
| @@ -373,9 +410,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) |
| @@ -384,6 +423,7 @@ |
| #else |
| # define LLVM_ASSUME_ALIGNED(p, a) (p) |
| #endif |
| +#endif |
| |
| /// \macro LLVM_PACKED |
| /// Used to specify a packed structure. |
| @@ -403,6 +443,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)) |
| @@ -412,11 +453,13 @@ |
| # define LLVM_PACKED_START _Pragma("pack(push, 1)") |
| # define LLVM_PACKED_END _Pragma("pack(pop)") |
| #endif |
| +#endif |
| |
| /// \macro LLVM_PTR_SIZE |
| /// A constant integer equivalent to the value of sizeof(void*). |
| /// Generally used in combination with alignas or when doing computation in the |
| /// preprocessor. |
| +#ifndef LLVM_PTR_SIZE |
| #ifdef __SIZEOF_POINTER__ |
| # define LLVM_PTR_SIZE __SIZEOF_POINTER__ |
| #elif defined(_WIN64) |
| @@ -428,6 +471,7 @@ |
| #else |
| # define LLVM_PTR_SIZE sizeof(void *) |
| #endif |
| +#endif |
| |
| /// \macro LLVM_MEMORY_SANITIZER_BUILD |
| /// Whether LLVM itself is built with MemorySanitizer instrumentation. |
| @@ -498,11 +542,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. |
| @@ -510,17 +556,20 @@ 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 |
| #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__) |
| @@ -528,6 +577,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, |