Skip to content

Commit 506251a

Browse files
committed
[libc] Remove obsolete LIBC_HAS_BUILTIN macro
1 parent 3e3f0c3 commit 506251a

File tree

19 files changed

+44
-66
lines changed

19 files changed

+44
-66
lines changed

libc/docs/dev/code_style.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ We define two kinds of macros:
5555
* ``src/__support/macros/config.h`` - Important compiler and platform
5656
features. Such macros can be used to produce portable code by
5757
parameterizing compilation based on the presence or lack of a given
58-
feature. e.g., ``LIBC_HAS_BUILTIN``
58+
feature. e.g., ``LIBC_HAS_FEATURE``
5959
* ``src/__support/macros/attributes.h`` - Attributes for functions, types,
6060
and variables. e.g., ``LIBC_UNUSED``
6161
* ``src/__support/macros/optimization.h`` - Portable macros for performance

libc/src/__support/CPP/atomic.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ template <typename T> struct Atomic {
7171

7272
T load(MemoryOrder mem_ord = MemoryOrder::SEQ_CST,
7373
[[maybe_unused]] MemoryScope mem_scope = MemoryScope::DEVICE) {
74-
if constexpr (LIBC_HAS_BUILTIN(__scoped_atomic_load_n))
75-
return __scoped_atomic_load_n(&val, int(mem_ord), (int)(mem_scope));
76-
else
77-
return __atomic_load_n(&val, int(mem_ord));
74+
#if __has_builtin(__scoped_atomic_load_n)
75+
return __scoped_atomic_load_n(&val, int(mem_ord), (int)(mem_scope));
76+
#else
77+
return __atomic_load_n(&val, int(mem_ord));
78+
#endif
7879
}
7980

8081
// Atomic store.
@@ -85,7 +86,7 @@ template <typename T> struct Atomic {
8586

8687
void store(T rhs, MemoryOrder mem_ord = MemoryOrder::SEQ_CST,
8788
[[maybe_unused]] MemoryScope mem_scope = MemoryScope::DEVICE) {
88-
if constexpr (LIBC_HAS_BUILTIN(__scoped_atomic_store_n))
89+
if constexpr (__has_builtin(__scoped_atomic_store_n))
8990
__scoped_atomic_store_n(&val, rhs, int(mem_ord), (int)(mem_scope));
9091
else
9192
__atomic_store_n(&val, rhs, int(mem_ord));
@@ -101,7 +102,7 @@ template <typename T> struct Atomic {
101102

102103
T exchange(T desired, MemoryOrder mem_ord = MemoryOrder::SEQ_CST,
103104
[[maybe_unused]] MemoryScope mem_scope = MemoryScope::DEVICE) {
104-
if constexpr (LIBC_HAS_BUILTIN(__scoped_atomic_exchange_n))
105+
if constexpr (__has_builtin(__scoped_atomic_exchange_n))
105106
return __scoped_atomic_exchange_n(&val, desired, int(mem_ord),
106107
(int)(mem_scope));
107108
else
@@ -110,7 +111,7 @@ template <typename T> struct Atomic {
110111

111112
T fetch_add(T increment, MemoryOrder mem_ord = MemoryOrder::SEQ_CST,
112113
[[maybe_unused]] MemoryScope mem_scope = MemoryScope::DEVICE) {
113-
if constexpr (LIBC_HAS_BUILTIN(__scoped_atomic_fetch_add))
114+
if constexpr (__has_builtin(__scoped_atomic_fetch_add))
114115
return __scoped_atomic_fetch_add(&val, increment, int(mem_ord),
115116
(int)(mem_scope));
116117
else
@@ -119,7 +120,7 @@ template <typename T> struct Atomic {
119120

120121
T fetch_or(T mask, MemoryOrder mem_ord = MemoryOrder::SEQ_CST,
121122
[[maybe_unused]] MemoryScope mem_scope = MemoryScope::DEVICE) {
122-
if constexpr (LIBC_HAS_BUILTIN(__scoped_atomic_fetch_or))
123+
if constexpr (__has_builtin(__scoped_atomic_fetch_or))
123124
return __scoped_atomic_fetch_or(&val, mask, int(mem_ord),
124125
(int)(mem_scope));
125126
else
@@ -128,7 +129,7 @@ template <typename T> struct Atomic {
128129

129130
T fetch_and(T mask, MemoryOrder mem_ord = MemoryOrder::SEQ_CST,
130131
[[maybe_unused]] MemoryScope mem_scope = MemoryScope::DEVICE) {
131-
if constexpr (LIBC_HAS_BUILTIN(__scoped_atomic_fetch_and))
132+
if constexpr (__has_builtin(__scoped_atomic_fetch_and))
132133
return __scoped_atomic_fetch_and(&val, mask, int(mem_ord),
133134
(int)(mem_scope));
134135
else
@@ -137,7 +138,7 @@ template <typename T> struct Atomic {
137138

138139
T fetch_sub(T decrement, MemoryOrder mem_ord = MemoryOrder::SEQ_CST,
139140
[[maybe_unused]] MemoryScope mem_scope = MemoryScope::DEVICE) {
140-
if constexpr (LIBC_HAS_BUILTIN(__scoped_atomic_fetch_sub))
141+
if constexpr (__has_builtin(__scoped_atomic_fetch_sub))
141142
return __scoped_atomic_fetch_sub(&val, decrement, int(mem_ord),
142143
(int)(mem_scope));
143144
else
@@ -166,7 +167,7 @@ LIBC_INLINE void atomic_thread_fence([[maybe_unused]] MemoryOrder mem_ord) {
166167
// except no instructions for memory ordering are issued. Only reordering of
167168
// the instructions by the compiler is suppressed as order instructs.
168169
LIBC_INLINE void atomic_signal_fence([[maybe_unused]] MemoryOrder mem_ord) {
169-
#if LIBC_HAS_BUILTIN(__atomic_signal_fence)
170+
#if __has_builtin(__atomic_signal_fence)
170171
__atomic_signal_fence(static_cast<int>(mem_ord));
171172
#else
172173
// if the builtin is not ready, use asm as a full compiler barrier.

libc/src/__support/CPP/bit.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
#include "src/__support/CPP/limits.h" // numeric_limits
1515
#include "src/__support/CPP/type_traits.h"
1616
#include "src/__support/macros/attributes.h"
17-
#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN
1817
#include "src/__support/macros/sanitizer.h"
1918

2019
#include <stdint.h>
2120

2221
namespace LIBC_NAMESPACE::cpp {
2322

24-
#if LIBC_HAS_BUILTIN(__builtin_memcpy_inline)
23+
#if __has_builtin(__builtin_memcpy_inline)
2524
#define LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE
2625
#endif
2726

@@ -36,20 +35,20 @@ LIBC_INLINE constexpr cpp::enable_if_t<
3635
To>
3736
bit_cast(const From &from) {
3837
MSAN_UNPOISON(&from, sizeof(From));
39-
#if LIBC_HAS_BUILTIN(__builtin_bit_cast)
38+
#if __has_builtin(__builtin_bit_cast)
4039
return __builtin_bit_cast(To, from);
4140
#else
4241
To to;
4342
char *dst = reinterpret_cast<char *>(&to);
4443
const char *src = reinterpret_cast<const char *>(&from);
45-
#if LIBC_HAS_BUILTIN(__builtin_memcpy_inline)
44+
#if __has_builtin(__builtin_memcpy_inline)
4645
__builtin_memcpy_inline(dst, src, sizeof(To));
4746
#else
4847
for (unsigned i = 0; i < sizeof(To); ++i)
4948
dst[i] = src[i];
50-
#endif // LIBC_HAS_BUILTIN(__builtin_memcpy_inline)
49+
#endif // __has_builtin(__builtin_memcpy_inline)
5150
return to;
52-
#endif // LIBC_HAS_BUILTIN(__builtin_bit_cast)
51+
#endif // __has_builtin(__builtin_bit_cast)
5352
}
5453

5554
template <typename T>
@@ -94,7 +93,7 @@ countr_zero(T value) {
9493
}
9594
return zero_bits;
9695
}
97-
#if LIBC_HAS_BUILTIN(__builtin_ctzs)
96+
#if __has_builtin(__builtin_ctzs)
9897
ADD_SPECIALIZATION(countr_zero, unsigned short, __builtin_ctzs)
9998
#endif
10099
ADD_SPECIALIZATION(countr_zero, unsigned int, __builtin_ctz)
@@ -124,7 +123,7 @@ countl_zero(T value) {
124123
}
125124
return zero_bits;
126125
}
127-
#if LIBC_HAS_BUILTIN(__builtin_clzs)
126+
#if __has_builtin(__builtin_clzs)
128127
ADD_SPECIALIZATION(countl_zero, unsigned short, __builtin_clzs)
129128
#endif
130129
ADD_SPECIALIZATION(countl_zero, unsigned int, __builtin_clz)

libc/src/__support/CPP/type_traits/is_destructible.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace LIBC_NAMESPACE::cpp {
2222

2323
// is_destructible
24-
#if LIBC_HAS_BUILTIN(__is_destructible)
24+
#if __has_builtin(__is_destructible)
2525
template <typename T>
2626
struct is_destructible : bool_constant<__is_destructible(T)> {};
2727
#else

libc/src/__support/CPP/type_traits/is_function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace LIBC_NAMESPACE::cpp {
1818

1919
// is_function
20-
#if LIBC_HAS_BUILTIN(__is_function)
20+
#if __has_builtin(__is_function)
2121
template <typename T>
2222
struct is_function : integral_constant<bool, __is_function(T)> {};
2323
#else

libc/src/__support/CPP/type_traits/is_lvalue_reference.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace LIBC_NAMESPACE::cpp {
1818

1919
// is_lvalue_reference
20-
#if LIBC_HAS_BUILTIN(__is_lvalue_reference)
20+
#if __has_builtin(__is_lvalue_reference)
2121
template <typename T>
2222
struct is_lvalue_reference : bool_constant<__is_lvalue_reference(T)> {};
2323
#else

libc/src/__support/CPP/type_traits/is_reference.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace LIBC_NAMESPACE::cpp {
1818

1919
// is_reference
20-
#if LIBC_HAS_BUILTIN(__is_reference)
20+
#if __has_builtin(__is_reference)
2121
template <typename T> struct is_reference : bool_constant<__is_reference(T)> {};
2222
#else
2323
template <typename T> struct is_reference : public false_type {};

libc/src/__support/CPP/type_traits/is_rvalue_reference.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace LIBC_NAMESPACE::cpp {
1818

1919
// is_rvalue_reference
20-
#if LIBC_HAS_BUILTIN(__is_rvalue_reference)
20+
#if __has_builtin(__is_rvalue_reference)
2121
template <typename T>
2222
struct is_rvalue_reference : bool_constant<__is_rvalue_reference(T)> {};
2323
#else

libc/src/__support/CPP/type_traits/is_trivially_destructible.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace LIBC_NAMESPACE::cpp {
1717

1818
// is_trivially_destructible
19-
#if LIBC_HAS_BUILTIN(__is_trivially_destructible)
19+
#if __has_builtin(__is_trivially_destructible)
2020
template <typename T>
2121
struct is_trivially_destructible
2222
: public bool_constant<__is_trivially_destructible(T)> {};
@@ -25,7 +25,7 @@ template <typename T>
2525
struct is_trivially_destructible
2626
: public bool_constant<cpp::is_destructible_v<T> &&__has_trivial_destructor(
2727
T)> {};
28-
#endif // LIBC_HAS_BUILTIN(__is_trivially_destructible)
28+
#endif // __has_builtin(__is_trivially_destructible)
2929
template <typename T>
3030
LIBC_INLINE_VAR constexpr bool is_trivially_destructible_v =
3131
is_trivially_destructible<T>::value;

libc/src/__support/CPP/type_traits/remove_all_extents.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace LIBC_NAMESPACE::cpp {
1717

1818
// remove_all_extents
19-
#if LIBC_HAS_BUILTIN(__remove_all_extents)
19+
#if __has_builtin(__remove_all_extents)
2020
template <typename T> using remove_all_extents_t = __remove_all_extents(T);
2121
template <typename T>
2222
struct remove_all_extents : cpp::type_identity<remove_all_extents_t<T>> {};

libc/src/__support/FPUtil/FEnvImpl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "include/llvm-libc-macros/math-macros.h"
1313
#include "src/__support/macros/attributes.h" // LIBC_INLINE
14-
#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN
1514
#include "src/__support/macros/properties/architectures.h"
1615
#include "src/errno/libc_errno.h"
1716
#include <fenv.h>

libc/src/__support/FPUtil/gpu/FMA.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
#include "src/__support/CPP/type_traits.h"
1313
#include "src/__support/macros/config.h"
1414

15-
// These intrinsics map to the FMA instrunctions in the target ISA for the GPU.
15+
// These intrinsics map to the FMA instructions in the target ISA for the GPU.
1616
// The default rounding mode generated from these will be to the nearest even.
17-
static_assert(LIBC_HAS_BUILTIN(__builtin_fma), "FMA builtins must be defined");
18-
static_assert(LIBC_HAS_BUILTIN(__builtin_fmaf), "FMA builtins must be defined");
17+
#if !__has_builtin(__builtin_fma) || !__has_builtin(__builtin_fmaf)
18+
#error "FMA builtins must be defined");
19+
#endif
1920

2021
namespace LIBC_NAMESPACE {
2122
namespace fputil {

libc/src/__support/macros/config.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,6 @@
1313
#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H
1414
#define LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H
1515

16-
// LIBC_HAS_BUILTIN()
17-
//
18-
// Checks whether the compiler supports a Clang Feature Checking Macro, and if
19-
// so, checks whether it supports the provided builtin function "x" where x
20-
// is one of the functions noted in
21-
// https://clang.llvm.org/docs/LanguageExtensions.html
22-
//
23-
// Note: Use this macro to avoid an extra level of #ifdef __has_builtin check.
24-
// http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html
25-
26-
// Compiler builtin-detection.
27-
// clang.llvm.org/docs/LanguageExtensions.html#has-builtin
28-
#ifdef __has_builtin
29-
#define LIBC_HAS_BUILTIN(x) __has_builtin(x)
30-
#else
31-
#define LIBC_HAS_BUILTIN(x) 0
32-
#endif
33-
3416
// Compiler feature-detection.
3517
// clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension
3618
#ifdef __has_feature

libc/src/__support/macros/optimization.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#define LLVM_LIBC_SRC___SUPPORT_MACROS_OPTIMIZATION_H
1212

1313
#include "src/__support/macros/attributes.h" // LIBC_INLINE
14-
#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN
1514
#include "src/__support/macros/properties/compiler.h" // LIBC_COMPILER_IS_CLANG
1615

1716
// We use a template to implement likely/unlikely to make sure that we don't

libc/src/__support/macros/sanitizer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
// Functions to unpoison memory
4848
//-----------------------------------------------------------------------------
4949

50-
#if defined(LIBC_HAVE_MEMORY_SANITIZER) && \
51-
LIBC_HAS_BUILTIN(__builtin_constant_p)
50+
#if defined(LIBC_HAVE_MEMORY_SANITIZER) && __has_builtin(__builtin_constant_p)
5251
// Only perform MSAN unpoison in non-constexpr context.
5352
#include <sanitizer/msan_interface.h>
5453
#define MSAN_UNPOISON(addr, size) \

libc/src/__support/math_extras.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "src/__support/CPP/limits.h" // CHAR_BIT, numeric_limits
1515
#include "src/__support/CPP/type_traits.h" // is_unsigned_v
1616
#include "src/__support/macros/attributes.h" // LIBC_INLINE
17-
#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN
1817

1918
namespace LIBC_NAMESPACE {
2019

@@ -61,7 +60,7 @@ add_with_carry(T a, T b, T carry_in) {
6160
return add_with_carry_const<T>(a, b, carry_in);
6261
}
6362

64-
#if LIBC_HAS_BUILTIN(__builtin_addc)
63+
#if __has_builtin(__builtin_addc)
6564
// https://clang.llvm.org/docs/LanguageExtensions.html#multiprecision-arithmetic-builtins
6665

6766
template <>
@@ -129,7 +128,7 @@ add_with_carry<unsigned long long>(unsigned long long a, unsigned long long b,
129128
}
130129
}
131130

132-
#endif // LIBC_HAS_BUILTIN(__builtin_addc)
131+
#endif // __has_builtin(__builtin_addc)
133132

134133
// Subtract with borrow
135134
template <typename T> struct DiffBorrow {
@@ -157,7 +156,7 @@ sub_with_borrow(T a, T b, T borrow_in) {
157156
return sub_with_borrow_const<T>(a, b, borrow_in);
158157
}
159158

160-
#if LIBC_HAS_BUILTIN(__builtin_subc)
159+
#if __has_builtin(__builtin_subc)
161160
// https://clang.llvm.org/docs/LanguageExtensions.html#multiprecision-arithmetic-builtins
162161

163162
template <>
@@ -225,7 +224,7 @@ sub_with_borrow<unsigned long long>(unsigned long long a, unsigned long long b,
225224
}
226225
}
227226

228-
#endif // LIBC_HAS_BUILTIN(__builtin_subc)
227+
#endif // __has_builtin(__builtin_subc)
229228

230229
template <typename T>
231230
[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>

libc/src/__support/memory_size.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace LIBC_NAMESPACE {
2020
namespace internal {
2121
template <class T> LIBC_INLINE bool mul_overflow(T a, T b, T *res) {
22-
#if LIBC_HAS_BUILTIN(__builtin_mul_overflow)
22+
#if __has_builtin(__builtin_mul_overflow)
2323
return __builtin_mul_overflow(a, b, res);
2424
#else
2525
T max = cpp::numeric_limits<T>::max();

libc/src/string/memory_utils/generic/builtin.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_BUILTIN_H
1111

1212
#include "src/__support/macros/attributes.h" // LIBC_INLINE
13-
#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN
1413
#include "src/string/memory_utils/utils.h" // Ptr, CPtr
1514

1615
#include <stddef.h> // size_t
1716

1817
namespace LIBC_NAMESPACE {
1918

20-
static_assert(LIBC_HAS_BUILTIN(__builtin_memcpy), "Builtin not defined");
21-
static_assert(LIBC_HAS_BUILTIN(__builtin_memset), "Builtin not defined");
22-
static_assert(LIBC_HAS_BUILTIN(__builtin_memmove), "Builtin not defined");
19+
#if !__has_builtin(__builtin_memcpy) || !__has_builtin(__builtin_memset) || \
20+
!__has_builtin(__builtin_memmove)
21+
#error "Builtin not defined");
22+
#endif
2323

2424
[[maybe_unused]] LIBC_INLINE void
2525
inline_memcpy_builtin(Ptr dst, CPtr src, size_t count, size_t offset = 0) {

libc/src/string/memory_utils/utils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "src/__support/CPP/type_traits.h"
1515
#include "src/__support/endian.h"
1616
#include "src/__support/macros/attributes.h" // LIBC_INLINE
17-
#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN
1817
#include "src/__support/macros/properties/architectures.h"
1918

2019
#include <stddef.h> // size_t
@@ -71,11 +70,11 @@ LIBC_INLINE bool is_disjoint(const void *p1, const void *p2, size_t size) {
7170
return sdiff >= 0 ? size <= udiff : size <= neg_udiff;
7271
}
7372

74-
#if LIBC_HAS_BUILTIN(__builtin_memcpy_inline)
73+
#if __has_builtin(__builtin_memcpy_inline)
7574
#define LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE
7675
#endif
7776

78-
#if LIBC_HAS_BUILTIN(__builtin_memset_inline)
77+
#if __has_builtin(__builtin_memset_inline)
7978
#define LLVM_LIBC_HAS_BUILTIN_MEMSET_INLINE
8079
#endif
8180

0 commit comments

Comments
 (0)