James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 2 | From: PJ Reiniger <pj.reiniger@gmail.com> |
| 3 | Date: Sat, 7 May 2022 22:28:13 -0400 |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 4 | Subject: [PATCH 05/31] \#ifdef guard safety |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 5 | |
| 6 | Prevents redefinition if someone is pulling in real LLVM, since the macros are in global namespace |
| 7 | --- |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 8 | llvm/include/llvm/Support/Compiler.h | 42 ++++++++++++++++++++++++++++ |
| 9 | 1 file changed, 42 insertions(+) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 10 | |
| 11 | diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 12 | index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e848519998685b 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 13 | --- a/llvm/include/llvm/Support/Compiler.h |
| 14 | +++ b/llvm/include/llvm/Support/Compiler.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 15 | @@ -90,6 +90,7 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 16 | /// * 1928: VS2019, version 16.8 + 16.9 |
| 17 | /// * 1929: VS2019, version 16.10 + 16.11 |
| 18 | /// * 1930: VS2022, version 17.0 |
| 19 | +#ifndef LLVM_MSC_PREREQ |
| 20 | #ifdef _MSC_VER |
| 21 | #define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version)) |
| 22 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 23 | @@ -103,6 +104,7 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 24 | #else |
| 25 | #define LLVM_MSC_PREREQ(version) 0 |
| 26 | #endif |
| 27 | +#endif |
| 28 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 29 | /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked |
| 30 | /// into a shared library, then the class should be private to the library and |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 31 | @@ -139,17 +141,21 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 32 | #define LLVM_EXTERNAL_VISIBILITY |
| 33 | #endif |
| 34 | |
| 35 | +#ifndef LLVM_PREFETCH |
| 36 | #if defined(__GNUC__) |
| 37 | #define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality) |
| 38 | #else |
| 39 | #define LLVM_PREFETCH(addr, rw, locality) |
| 40 | #endif |
| 41 | +#endif |
| 42 | |
| 43 | +#ifndef LLVM_ATTRIBUTE_USED |
| 44 | #if __has_attribute(used) |
| 45 | #define LLVM_ATTRIBUTE_USED __attribute__((__used__)) |
| 46 | #else |
| 47 | #define LLVM_ATTRIBUTE_USED |
| 48 | #endif |
| 49 | +#endif |
| 50 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 51 | #if defined(__clang__) |
| 52 | #define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX))) |
| 53 | @@ -178,11 +184,13 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 54 | // more portable solution: |
| 55 | // (void)unused_var_name; |
| 56 | // Prefer cast-to-void wherever it is sufficient. |
| 57 | +#ifndef LLVM_ATTRIBUTE_UNUSED |
| 58 | #if __has_attribute(unused) |
| 59 | #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__)) |
| 60 | #else |
| 61 | #define LLVM_ATTRIBUTE_UNUSED |
| 62 | #endif |
| 63 | +#endif |
| 64 | |
| 65 | // FIXME: Provide this for PE/COFF targets. |
| 66 | #if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \ |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 67 | @@ -192,6 +200,7 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 68 | #define LLVM_ATTRIBUTE_WEAK |
| 69 | #endif |
| 70 | |
| 71 | +#ifndef LLVM_READNONE |
| 72 | // Prior to clang 3.2, clang did not accept any spelling of |
| 73 | // __has_attribute(const), so assume it is supported. |
| 74 | #if defined(__clang__) || defined(__GNUC__) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 75 | @@ -200,13 +209,16 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 76 | #else |
| 77 | #define LLVM_READNONE |
| 78 | #endif |
| 79 | +#endif |
| 80 | |
| 81 | +#ifndef LLVM_READONLY |
| 82 | #if __has_attribute(pure) || defined(__GNUC__) |
| 83 | // aka 'PURE' but following LLVM Conventions. |
| 84 | #define LLVM_READONLY __attribute__((__pure__)) |
| 85 | #else |
| 86 | #define LLVM_READONLY |
| 87 | #endif |
| 88 | +#endif |
| 89 | |
| 90 | #if __has_attribute(minsize) |
| 91 | #define LLVM_ATTRIBUTE_MINSIZE __attribute__((minsize)) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 92 | @@ -214,6 +226,7 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 93 | #define LLVM_ATTRIBUTE_MINSIZE |
| 94 | #endif |
| 95 | |
| 96 | +#ifndef LLVM_LIKELY |
| 97 | #if __has_builtin(__builtin_expect) || defined(__GNUC__) |
| 98 | #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true) |
| 99 | #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 100 | @@ -221,9 +234,11 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 101 | #define LLVM_LIKELY(EXPR) (EXPR) |
| 102 | #define LLVM_UNLIKELY(EXPR) (EXPR) |
| 103 | #endif |
| 104 | +#endif |
| 105 | |
| 106 | /// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, |
| 107 | /// mark a method "not for inlining". |
| 108 | +#ifndef LLVM_ATTRIBUTE_NOINLINE |
| 109 | #if __has_attribute(noinline) |
| 110 | #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline)) |
| 111 | #elif defined(_MSC_VER) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 112 | @@ -231,9 +246,11 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 113 | #else |
| 114 | #define LLVM_ATTRIBUTE_NOINLINE |
| 115 | #endif |
| 116 | +#endif |
| 117 | |
| 118 | /// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do |
| 119 | /// so, mark a method "always inline" because it is performance sensitive. |
| 120 | +#ifndef LLVM_ATTRIBUTE_ALWAYS_INLINE |
| 121 | #if __has_attribute(always_inline) |
| 122 | #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline)) |
| 123 | #elif defined(_MSC_VER) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 124 | @@ -241,6 +258,7 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 125 | #else |
| 126 | #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline |
| 127 | #endif |
| 128 | +#endif |
| 129 | |
| 130 | /// LLVM_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do |
| 131 | /// so, mark a method "no debug" because debug info makes the debugger |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 132 | @@ -251,6 +269,7 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 133 | #define LLVM_ATTRIBUTE_NODEBUG |
| 134 | #endif |
| 135 | |
| 136 | +#ifndef LLVM_ATTRIBUTE_RETURNS_NONNULL |
| 137 | #if __has_attribute(returns_nonnull) |
| 138 | #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) |
| 139 | #elif defined(_MSC_VER) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 140 | @@ -258,9 +277,11 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 141 | #else |
| 142 | #define LLVM_ATTRIBUTE_RETURNS_NONNULL |
| 143 | #endif |
| 144 | +#endif |
| 145 | |
| 146 | /// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a |
| 147 | /// pointer that does not alias any other valid pointer. |
| 148 | +#ifndef LLVM_ATTRIBUTE_RETURNS_NOALIAS |
| 149 | #ifdef __GNUC__ |
| 150 | #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) |
| 151 | #elif defined(_MSC_VER) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 152 | @@ -268,8 +289,10 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 153 | #else |
| 154 | #define LLVM_ATTRIBUTE_RETURNS_NOALIAS |
| 155 | #endif |
| 156 | +#endif |
| 157 | |
| 158 | /// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements. |
| 159 | +#ifndef LLVM_FALLTHROUGH |
| 160 | #if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough) |
| 161 | #define LLVM_FALLTHROUGH [[fallthrough]] |
| 162 | #elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 163 | @@ -281,6 +304,7 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 164 | #else |
| 165 | #define LLVM_FALLTHROUGH |
| 166 | #endif |
| 167 | +#endif |
| 168 | |
| 169 | /// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that |
| 170 | /// they are constant initialized. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 171 | @@ -309,11 +333,13 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 172 | |
| 173 | /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress |
| 174 | /// pedantic diagnostics. |
| 175 | +#ifndef LLVM_EXTENSION |
| 176 | #ifdef __GNUC__ |
| 177 | #define LLVM_EXTENSION __extension__ |
| 178 | #else |
| 179 | #define LLVM_EXTENSION |
| 180 | #endif |
| 181 | +#endif |
| 182 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 183 | /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands |
| 184 | /// to an expression which states that it is undefined behavior for the |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 185 | @@ -322,14 +348,17 @@ |
| 186 | /// '#else' is intentionally left out so that other macro logic (e.g., |
| 187 | /// LLVM_ASSUME_ALIGNED and llvm_unreachable()) can detect whether |
| 188 | /// LLVM_BUILTIN_UNREACHABLE has a definition. |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 189 | +#ifndef LLVM_BUILTIN_UNREACHABLE |
| 190 | #if __has_builtin(__builtin_unreachable) || defined(__GNUC__) |
| 191 | # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable() |
| 192 | #elif defined(_MSC_VER) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 193 | # define LLVM_BUILTIN_UNREACHABLE __assume(false) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 194 | #endif |
| 195 | +#endif |
| 196 | |
| 197 | /// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression |
| 198 | /// which causes the program to exit abnormally. |
| 199 | +#ifndef LLVM_BUILTIN_TRAP |
| 200 | #if __has_builtin(__builtin_trap) || defined(__GNUC__) |
| 201 | # define LLVM_BUILTIN_TRAP __builtin_trap() |
| 202 | #elif defined(_MSC_VER) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 203 | @@ -341,10 +370,12 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 204 | #else |
| 205 | # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0 |
| 206 | #endif |
| 207 | +#endif |
| 208 | |
| 209 | /// LLVM_BUILTIN_DEBUGTRAP - On compilers which support it, expands to |
| 210 | /// an expression which causes the program to break while running |
| 211 | /// under a debugger. |
| 212 | +#ifndef LLVM_BUILTIN_DEBUGTRAP |
| 213 | #if __has_builtin(__builtin_debugtrap) |
| 214 | # define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap() |
| 215 | #elif defined(_MSC_VER) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 216 | @@ -358,9 +389,11 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 217 | // program to abort if encountered. |
| 218 | # define LLVM_BUILTIN_DEBUGTRAP |
| 219 | #endif |
| 220 | +#endif |
| 221 | |
| 222 | /// \macro LLVM_ASSUME_ALIGNED |
| 223 | /// Returns a pointer with an assumed alignment. |
| 224 | +#ifndef LLVM_ASSUME_ALIGNED |
| 225 | #if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__) |
| 226 | # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a) |
| 227 | #elif defined(LLVM_BUILTIN_UNREACHABLE) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 228 | @@ -369,6 +402,7 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 229 | #else |
| 230 | # define LLVM_ASSUME_ALIGNED(p, a) (p) |
| 231 | #endif |
| 232 | +#endif |
| 233 | |
| 234 | /// \macro LLVM_PACKED |
| 235 | /// Used to specify a packed structure. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 236 | @@ -388,6 +422,7 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 237 | /// long long l; |
| 238 | /// }; |
| 239 | /// LLVM_PACKED_END |
| 240 | +#ifndef LLVM_PACKED |
| 241 | #ifdef _MSC_VER |
| 242 | # define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop)) |
| 243 | # define LLVM_PACKED_START __pragma(pack(push, 1)) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 244 | @@ -397,6 +432,7 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 245 | # define LLVM_PACKED_START _Pragma("pack(push, 1)") |
| 246 | # define LLVM_PACKED_END _Pragma("pack(pop)") |
| 247 | #endif |
| 248 | +#endif |
| 249 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 250 | /// \macro LLVM_MEMORY_SANITIZER_BUILD |
| 251 | /// Whether LLVM itself is built with MemorySanitizer instrumentation. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 252 | @@ -488,11 +524,13 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 253 | |
| 254 | /// \macro LLVM_NO_SANITIZE |
| 255 | /// Disable a particular sanitizer for a function. |
| 256 | +#ifndef LLVM_NO_SANITIZE |
| 257 | #if __has_attribute(no_sanitize) |
| 258 | #define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND))) |
| 259 | #else |
| 260 | #define LLVM_NO_SANITIZE(KIND) |
| 261 | #endif |
| 262 | +#endif |
| 263 | |
| 264 | /// Mark debug helper function definitions like dump() that should not be |
| 265 | /// stripped from debug builds. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 266 | @@ -500,17 +538,20 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 267 | /// `#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)` so they do always |
| 268 | /// get stripped in release builds. |
| 269 | // FIXME: Move this to a private config.h as it's not usable in public headers. |
| 270 | +#ifndef LLVM_DUMP_METHOD |
| 271 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
| 272 | #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED |
| 273 | #else |
| 274 | #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE |
| 275 | #endif |
| 276 | +#endif |
| 277 | |
| 278 | /// \macro LLVM_PRETTY_FUNCTION |
| 279 | /// Gets a user-friendly looking function signature for the current scope |
| 280 | /// using the best available method on each platform. The exact format of the |
| 281 | /// resulting string is implementation specific and non-portable, so this should |
| 282 | /// only be used, for example, for logging or diagnostics. |
| 283 | +#ifndef LLVM_PRETTY_FUNCTION |
| 284 | #if defined(_MSC_VER) |
| 285 | #define LLVM_PRETTY_FUNCTION __FUNCSIG__ |
| 286 | #elif defined(__GNUC__) || defined(__clang__) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 287 | @@ -518,6 +559,7 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 288 | #else |
| 289 | #define LLVM_PRETTY_FUNCTION __func__ |
| 290 | #endif |
| 291 | +#endif |
| 292 | |
| 293 | /// \macro LLVM_THREAD_LOCAL |
| 294 | /// A thread-local storage specifier which can be used with globals, |