blob: bcb4950d453bdb2801c65c9076c0b692e25c84fd [file] [log] [blame]
James Kuszmaulcf324122023-01-14 14:07:17 -08001From 008e921f77933f475174d74a6b70309c6fbe0771 Mon Sep 17 00:00:00 2001
2From: PJ Reiniger <pj.reiniger@gmail.com>
3Date: Sat, 7 May 2022 22:28:13 -0400
4Subject: [PATCH 06/28] \#ifdef guard safety
5
6Prevents redefinition if someone is pulling in real LLVM, since the macros are in global namespace
7---
8 llvm/include/llvm/Support/Compiler.h | 50 ++++++++++++++++++++++++++++
9 1 file changed, 50 insertions(+)
10
11diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
12index ede1cb172..8b8260b50 100644
13--- a/llvm/include/llvm/Support/Compiler.h
14+++ b/llvm/include/llvm/Support/Compiler.h
15@@ -86,6 +86,7 @@
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
23@@ -99,6 +100,7 @@
24 #else
25 #define LLVM_MSC_PREREQ(version) 0
26 #endif
27+#endif
28
29 /// Does the compiler support ref-qualifiers for *this?
30 ///
31@@ -112,11 +114,13 @@
32 ///
33 /// This can be used to provide lvalue/rvalue overrides of member functions.
34 /// The rvalue override should be guarded by LLVM_HAS_RVALUE_REFERENCE_THIS
35+#ifndef LLVM_LVALUE_FUNCTION
36 #if LLVM_HAS_RVALUE_REFERENCE_THIS
37 #define LLVM_LVALUE_FUNCTION &
38 #else
39 #define LLVM_LVALUE_FUNCTION
40 #endif
41+#endif
42
43 /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
44 /// into a shared library, then the class should be private to the library and
45@@ -140,21 +144,26 @@
46 #define LLVM_EXTERNAL_VISIBILITY
47 #endif
48
49+#ifndef LLVM_PREFETCH
50 #if defined(__GNUC__)
51 #define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
52 #else
53 #define LLVM_PREFETCH(addr, rw, locality)
54 #endif
55+#endif
56
57+#ifndef LLVM_ATTRIBUTE_USED
58 #if __has_attribute(used)
59 #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
60 #else
61 #define LLVM_ATTRIBUTE_USED
62 #endif
63+#endif
64
65 /// LLVM_NODISCARD - Warn if a type or return value is discarded.
66
67 // Use the 'nodiscard' attribute in C++17 or newer mode.
68+#ifndef LLVM_NODISCARD
69 #if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(nodiscard)
70 #define LLVM_NODISCARD [[nodiscard]]
71 #elif LLVM_HAS_CPP_ATTRIBUTE(clang::warn_unused_result)
72@@ -168,6 +177,7 @@
73 #else
74 #define LLVM_NODISCARD
75 #endif
76+#endif
77
78 // Indicate that a non-static, non-const C++ member function reinitializes
79 // the entire object to a known state, independent of the previous state of
80@@ -190,11 +200,13 @@
81 // more portable solution:
82 // (void)unused_var_name;
83 // Prefer cast-to-void wherever it is sufficient.
84+#ifndef LLVM_ATTRIBUTE_UNUSED
85 #if __has_attribute(unused)
86 #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
87 #else
88 #define LLVM_ATTRIBUTE_UNUSED
89 #endif
90+#endif
91
92 // FIXME: Provide this for PE/COFF targets.
93 #if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \
94@@ -204,6 +216,7 @@
95 #define LLVM_ATTRIBUTE_WEAK
96 #endif
97
98+#ifndef LLVM_READNONE
99 // Prior to clang 3.2, clang did not accept any spelling of
100 // __has_attribute(const), so assume it is supported.
101 #if defined(__clang__) || defined(__GNUC__)
102@@ -212,13 +225,16 @@
103 #else
104 #define LLVM_READNONE
105 #endif
106+#endif
107
108+#ifndef LLVM_READONLY
109 #if __has_attribute(pure) || defined(__GNUC__)
110 // aka 'PURE' but following LLVM Conventions.
111 #define LLVM_READONLY __attribute__((__pure__))
112 #else
113 #define LLVM_READONLY
114 #endif
115+#endif
116
117 #if __has_attribute(minsize)
118 #define LLVM_ATTRIBUTE_MINSIZE __attribute__((minsize))
119@@ -226,6 +242,7 @@
120 #define LLVM_ATTRIBUTE_MINSIZE
121 #endif
122
123+#ifndef LLVM_LIKELY
124 #if __has_builtin(__builtin_expect) || defined(__GNUC__)
125 #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
126 #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
127@@ -233,9 +250,11 @@
128 #define LLVM_LIKELY(EXPR) (EXPR)
129 #define LLVM_UNLIKELY(EXPR) (EXPR)
130 #endif
131+#endif
132
133 /// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so,
134 /// mark a method "not for inlining".
135+#ifndef LLVM_ATTRIBUTE_NOINLINE
136 #if __has_attribute(noinline)
137 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
138 #elif defined(_MSC_VER)
139@@ -243,9 +262,11 @@
140 #else
141 #define LLVM_ATTRIBUTE_NOINLINE
142 #endif
143+#endif
144
145 /// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do
146 /// so, mark a method "always inline" because it is performance sensitive.
147+#ifndef LLVM_ATTRIBUTE_ALWAYS_INLINE
148 #if __has_attribute(always_inline)
149 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
150 #elif defined(_MSC_VER)
151@@ -253,6 +274,7 @@
152 #else
153 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
154 #endif
155+#endif
156
157 /// LLVM_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do
158 /// so, mark a method "no debug" because debug info makes the debugger
159@@ -263,6 +285,7 @@
160 #define LLVM_ATTRIBUTE_NODEBUG
161 #endif
162
163+#ifndef LLVM_ATTRIBUTE_RETURNS_NONNULL
164 #if __has_attribute(returns_nonnull)
165 #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
166 #elif defined(_MSC_VER)
167@@ -270,9 +293,11 @@
168 #else
169 #define LLVM_ATTRIBUTE_RETURNS_NONNULL
170 #endif
171+#endif
172
173 /// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a
174 /// pointer that does not alias any other valid pointer.
175+#ifndef LLVM_ATTRIBUTE_RETURNS_NOALIAS
176 #ifdef __GNUC__
177 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
178 #elif defined(_MSC_VER)
179@@ -280,8 +305,10 @@
180 #else
181 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS
182 #endif
183+#endif
184
185 /// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
186+#ifndef LLVM_FALLTHROUGH
187 #if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough)
188 #define LLVM_FALLTHROUGH [[fallthrough]]
189 #elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
190@@ -293,6 +320,7 @@
191 #else
192 #define LLVM_FALLTHROUGH
193 #endif
194+#endif
195
196 /// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that
197 /// they are constant initialized.
198@@ -321,20 +349,25 @@
199
200 /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
201 /// pedantic diagnostics.
202+#ifndef LLVM_EXTENSION
203 #ifdef __GNUC__
204 #define LLVM_EXTENSION __extension__
205 #else
206 #define LLVM_EXTENSION
207 #endif
208+#endif
209
210 // LLVM_ATTRIBUTE_DEPRECATED(decl, "message")
211 // This macro will be removed.
212 // Use C++14's attribute instead: [[deprecated("message")]]
213+#ifndef LLVM_ATTRIBUTE_DEPRECATED
214 #define LLVM_ATTRIBUTE_DEPRECATED(decl, message) [[deprecated(message)]] decl
215+#endif
216
217 /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
218 /// to an expression which states that it is undefined behavior for the
219 /// compiler to reach this point. Otherwise is not defined.
220+#ifndef LLVM_BUILTIN_UNREACHABLE
221 #if __has_builtin(__builtin_unreachable) || defined(__GNUC__)
222 # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
223 #elif defined(_MSC_VER)
224@@ -342,9 +375,11 @@
225 #else
226 # define LLVM_BUILTIN_UNREACHABLE
227 #endif
228+#endif
229
230 /// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression
231 /// which causes the program to exit abnormally.
232+#ifndef LLVM_BUILTIN_TRAP
233 #if __has_builtin(__builtin_trap) || defined(__GNUC__)
234 # define LLVM_BUILTIN_TRAP __builtin_trap()
235 #elif defined(_MSC_VER)
236@@ -356,10 +391,12 @@
237 #else
238 # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
239 #endif
240+#endif
241
242 /// LLVM_BUILTIN_DEBUGTRAP - On compilers which support it, expands to
243 /// an expression which causes the program to break while running
244 /// under a debugger.
245+#ifndef LLVM_BUILTIN_DEBUGTRAP
246 #if __has_builtin(__builtin_debugtrap)
247 # define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap()
248 #elif defined(_MSC_VER)
249@@ -373,9 +410,11 @@
250 // program to abort if encountered.
251 # define LLVM_BUILTIN_DEBUGTRAP
252 #endif
253+#endif
254
255 /// \macro LLVM_ASSUME_ALIGNED
256 /// Returns a pointer with an assumed alignment.
257+#ifndef LLVM_ASSUME_ALIGNED
258 #if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__)
259 # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
260 #elif defined(LLVM_BUILTIN_UNREACHABLE)
261@@ -384,6 +423,7 @@
262 #else
263 # define LLVM_ASSUME_ALIGNED(p, a) (p)
264 #endif
265+#endif
266
267 /// \macro LLVM_PACKED
268 /// Used to specify a packed structure.
269@@ -403,6 +443,7 @@
270 /// long long l;
271 /// };
272 /// LLVM_PACKED_END
273+#ifndef LLVM_PACKED
274 #ifdef _MSC_VER
275 # define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))
276 # define LLVM_PACKED_START __pragma(pack(push, 1))
277@@ -412,11 +453,13 @@
278 # define LLVM_PACKED_START _Pragma("pack(push, 1)")
279 # define LLVM_PACKED_END _Pragma("pack(pop)")
280 #endif
281+#endif
282
283 /// \macro LLVM_PTR_SIZE
284 /// A constant integer equivalent to the value of sizeof(void*).
285 /// Generally used in combination with alignas or when doing computation in the
286 /// preprocessor.
287+#ifndef LLVM_PTR_SIZE
288 #ifdef __SIZEOF_POINTER__
289 # define LLVM_PTR_SIZE __SIZEOF_POINTER__
290 #elif defined(_WIN64)
291@@ -428,6 +471,7 @@
292 #else
293 # define LLVM_PTR_SIZE sizeof(void *)
294 #endif
295+#endif
296
297 /// \macro LLVM_MEMORY_SANITIZER_BUILD
298 /// Whether LLVM itself is built with MemorySanitizer instrumentation.
299@@ -498,11 +542,13 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
300
301 /// \macro LLVM_NO_SANITIZE
302 /// Disable a particular sanitizer for a function.
303+#ifndef LLVM_NO_SANITIZE
304 #if __has_attribute(no_sanitize)
305 #define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND)))
306 #else
307 #define LLVM_NO_SANITIZE(KIND)
308 #endif
309+#endif
310
311 /// Mark debug helper function definitions like dump() that should not be
312 /// stripped from debug builds.
313@@ -510,17 +556,20 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
314 /// `#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)` so they do always
315 /// get stripped in release builds.
316 // FIXME: Move this to a private config.h as it's not usable in public headers.
317+#ifndef LLVM_DUMP_METHOD
318 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
319 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
320 #else
321 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
322 #endif
323+#endif
324
325 /// \macro LLVM_PRETTY_FUNCTION
326 /// Gets a user-friendly looking function signature for the current scope
327 /// using the best available method on each platform. The exact format of the
328 /// resulting string is implementation specific and non-portable, so this should
329 /// only be used, for example, for logging or diagnostics.
330+#ifndef LLVM_PRETTY_FUNCTION
331 #if defined(_MSC_VER)
332 #define LLVM_PRETTY_FUNCTION __FUNCSIG__
333 #elif defined(__GNUC__) || defined(__clang__)
334@@ -528,6 +577,7 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
335 #else
336 #define LLVM_PRETTY_FUNCTION __func__
337 #endif
338+#endif
339
340 /// \macro LLVM_THREAD_LOCAL
341 /// A thread-local storage specifier which can be used with globals,