blob: e74cf17593e8a6eb7f200bbade621e1477117031 [file] [log] [blame]
James Kuszmaulb13e13f2023-11-22 20:44:04 -08001From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
James Kuszmaulcf324122023-01-14 14:07:17 -08002From: PJ Reiniger <pj.reiniger@gmail.com>
3Date: Sat, 7 May 2022 22:28:13 -0400
James Kuszmaulb13e13f2023-11-22 20:44:04 -08004Subject: [PATCH 05/31] \#ifdef guard safety
James Kuszmaulcf324122023-01-14 14:07:17 -08005
6Prevents redefinition if someone is pulling in real LLVM, since the macros are in global namespace
7---
James Kuszmaulb13e13f2023-11-22 20:44:04 -08008 llvm/include/llvm/Support/Compiler.h | 42 ++++++++++++++++++++++++++++
9 1 file changed, 42 insertions(+)
James Kuszmaulcf324122023-01-14 14:07:17 -080010
11diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
James Kuszmaulb13e13f2023-11-22 20:44:04 -080012index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e848519998685b 100644
James Kuszmaulcf324122023-01-14 14:07:17 -080013--- a/llvm/include/llvm/Support/Compiler.h
14+++ b/llvm/include/llvm/Support/Compiler.h
James Kuszmaulb13e13f2023-11-22 20:44:04 -080015@@ -90,6 +90,7 @@
James Kuszmaulcf324122023-01-14 14:07:17 -080016 /// * 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 Kuszmaulb13e13f2023-11-22 20:44:04 -080023@@ -103,6 +104,7 @@
James Kuszmaulcf324122023-01-14 14:07:17 -080024 #else
25 #define LLVM_MSC_PREREQ(version) 0
26 #endif
27+#endif
28
James Kuszmaulcf324122023-01-14 14:07:17 -080029 /// 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 Kuszmaulb13e13f2023-11-22 20:44:04 -080031@@ -139,17 +141,21 @@
James Kuszmaulcf324122023-01-14 14:07:17 -080032 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -080051 #if defined(__clang__)
52 #define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
53@@ -178,11 +184,13 @@
James Kuszmaulcf324122023-01-14 14:07:17 -080054 // 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 Kuszmaulb13e13f2023-11-22 20:44:04 -080067@@ -192,6 +200,7 @@
James Kuszmaulcf324122023-01-14 14:07:17 -080068 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -080075@@ -200,13 +209,16 @@
James Kuszmaulcf324122023-01-14 14:07:17 -080076 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -080092@@ -214,6 +226,7 @@
James Kuszmaulcf324122023-01-14 14:07:17 -080093 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800100@@ -221,9 +234,11 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800101 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800112@@ -231,9 +246,11 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800113 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800124@@ -241,6 +258,7 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800125 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800132@@ -251,6 +269,7 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800133 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800140@@ -258,9 +277,11 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800141 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800152@@ -268,8 +289,10 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800153 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800163@@ -281,6 +304,7 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800164 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800171@@ -309,11 +333,13 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800172
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 Kuszmaulcf324122023-01-14 14:07:17 -0800183 /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
184 /// to an expression which states that it is undefined behavior for the
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800185@@ -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 Kuszmaulcf324122023-01-14 14:07:17 -0800189+#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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800193 # define LLVM_BUILTIN_UNREACHABLE __assume(false)
James Kuszmaulcf324122023-01-14 14:07:17 -0800194 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800203@@ -341,10 +370,12 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800204 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800216@@ -358,9 +389,11 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800217 // 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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800228@@ -369,6 +402,7 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800229 #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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800236@@ -388,6 +422,7 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800237 /// 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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800244@@ -397,6 +432,7 @@
James Kuszmaulcf324122023-01-14 14:07:17 -0800245 # define LLVM_PACKED_START _Pragma("pack(push, 1)")
246 # define LLVM_PACKED_END _Pragma("pack(pop)")
247 #endif
248+#endif
249
James Kuszmaulcf324122023-01-14 14:07:17 -0800250 /// \macro LLVM_MEMORY_SANITIZER_BUILD
251 /// Whether LLVM itself is built with MemorySanitizer instrumentation.
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800252@@ -488,11 +524,13 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
James Kuszmaulcf324122023-01-14 14:07:17 -0800253
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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800266@@ -500,17 +538,20 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
James Kuszmaulcf324122023-01-14 14:07:17 -0800267 /// `#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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800287@@ -518,6 +559,7 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
James Kuszmaulcf324122023-01-14 14:07:17 -0800288 #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,