Skip to content

Commit 2682733

Browse files
committed
Remove checks for old gcc versions for LLVM_ATTRIBUTE_*
According to [1] we only support gcc 5.1+. So these checks for older gcc versions are not supported. Some gcc 5.1+ versions still don't support __has_builtin, so just check __GNUC__ in those cases. Add a missing #endif for LLVM_ATTRIBUTE_UNREACHABLE. [1] https://llvm.org/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D111581
1 parent 9e9803b commit 2682733

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

llvm/include/llvm/Support/Compiler.h

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@
9797
/// Sadly, this is separate from just rvalue reference support because GCC
9898
/// and MSVC implemented this later than everything else. This appears to be
9999
/// corrected in MSVC 2019 but not MSVC 2017.
100-
#if __has_feature(cxx_rvalue_references) || LLVM_GNUC_PREREQ(4, 8, 1) || \
101-
LLVM_MSC_PREREQ(1920)
100+
#if __has_feature(cxx_rvalue_references) || LLVM_MSC_PREREQ(1920)
102101
#define LLVM_HAS_RVALUE_REFERENCE_THIS 1
103102
#else
104103
#define LLVM_HAS_RVALUE_REFERENCE_THIS 0
@@ -123,8 +122,8 @@
123122
/// LLVM_EXTERNAL_VISIBILITY - classes, functions, and variables marked with
124123
/// this attribute will be made public and visible outside of any shared library
125124
/// they are linked in to.
126-
#if (__has_attribute(visibility) || LLVM_GNUC_PREREQ(4, 0, 0)) && \
127-
!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32)
125+
#if __has_attribute(visibility) && !defined(__MINGW32__) && \
126+
!defined(__CYGWIN__) && !defined(_WIN32)
128127
#define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
129128
#define LLVM_EXTERNAL_VISIBILITY __attribute__ ((visibility("default")))
130129
#else
@@ -138,7 +137,7 @@
138137
#define LLVM_PREFETCH(addr, rw, locality)
139138
#endif
140139

141-
#if __has_attribute(used) || LLVM_GNUC_PREREQ(3, 1, 0)
140+
#if __has_attribute(used)
142141
#define LLVM_ATTRIBUTE_USED __attribute__((__used__))
143142
#else
144143
#define LLVM_ATTRIBUTE_USED
@@ -182,15 +181,15 @@
182181
// more portable solution:
183182
// (void)unused_var_name;
184183
// Prefer cast-to-void wherever it is sufficient.
185-
#if __has_attribute(unused) || LLVM_GNUC_PREREQ(3, 1, 0)
184+
#if __has_attribute(unused)
186185
#define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
187186
#else
188187
#define LLVM_ATTRIBUTE_UNUSED
189188
#endif
190189

191190
// FIXME: Provide this for PE/COFF targets.
192-
#if (__has_attribute(weak) || LLVM_GNUC_PREREQ(4, 0, 0)) && \
193-
(!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32))
191+
#if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \
192+
!defined(_WIN32)
194193
#define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
195194
#else
196195
#define LLVM_ATTRIBUTE_WEAK
@@ -218,7 +217,7 @@
218217
#define LLVM_ATTRIBUTE_MINSIZE
219218
#endif
220219

221-
#if __has_builtin(__builtin_expect) || LLVM_GNUC_PREREQ(4, 0, 0)
220+
#if __has_builtin(__builtin_expect) || defined(__GNUC__)
222221
#define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
223222
#define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
224223
#else
@@ -228,7 +227,7 @@
228227

229228
/// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so,
230229
/// mark a method "not for inlining".
231-
#if __has_attribute(noinline) || LLVM_GNUC_PREREQ(3, 4, 0)
230+
#if __has_attribute(noinline)
232231
#define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
233232
#elif defined(_MSC_VER)
234233
#define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
@@ -237,10 +236,8 @@
237236
#endif
238237

239238
/// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do
240-
/// so, mark a method "always inline" because it is performance sensitive. GCC
241-
/// 3.4 supported this but is buggy in various cases and produces unimplemented
242-
/// errors, just use it in GCC 4.0 and later.
243-
#if __has_attribute(always_inline) || LLVM_GNUC_PREREQ(4, 0, 0)
239+
/// so, mark a method "always inline" because it is performance sensitive.
240+
#if __has_attribute(always_inline)
244241
#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
245242
#elif defined(_MSC_VER)
246243
#define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
@@ -257,7 +254,7 @@
257254
#define LLVM_ATTRIBUTE_NODEBUG
258255
#endif
259256

260-
#if __has_attribute(returns_nonnull) || LLVM_GNUC_PREREQ(4, 9, 0)
257+
#if __has_attribute(returns_nonnull)
261258
#define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
262259
#elif defined(_MSC_VER)
263260
#define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_
@@ -329,15 +326,17 @@
329326
/// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
330327
/// to an expression which states that it is undefined behavior for the
331328
/// compiler to reach this point. Otherwise is not defined.
332-
#if __has_builtin(__builtin_unreachable) || LLVM_GNUC_PREREQ(4, 5, 0)
329+
#if __has_builtin(__builtin_unreachable) || defined(__GNUC__)
333330
# define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
334331
#elif defined(_MSC_VER)
335332
# define LLVM_BUILTIN_UNREACHABLE __assume(false)
333+
#else
334+
# define LLVM_BUILTIN_UNREACHABLE
336335
#endif
337336

338337
/// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression
339338
/// which causes the program to exit abnormally.
340-
#if __has_builtin(__builtin_trap) || LLVM_GNUC_PREREQ(4, 3, 0)
339+
#if __has_builtin(__builtin_trap) || defined(__GNUC__)
341340
# define LLVM_BUILTIN_TRAP __builtin_trap()
342341
#elif defined(_MSC_VER)
343342
// The __debugbreak intrinsic is supported by MSVC, does not require forward
@@ -368,7 +367,7 @@
368367

369368
/// \macro LLVM_ASSUME_ALIGNED
370369
/// Returns a pointer with an assumed alignment.
371-
#if __has_builtin(__builtin_assume_aligned) || LLVM_GNUC_PREREQ(4, 7, 0)
370+
#if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__)
372371
# define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
373372
#elif defined(LLVM_BUILTIN_UNREACHABLE)
374373
# define LLVM_ASSUME_ALIGNED(p, a) \

0 commit comments

Comments
 (0)