Skip to content

Commit 7484133

Browse files
committed
[libc++] Inline __has_feature and __has_extension uses
1 parent abf9c1a commit 7484133

File tree

10 files changed

+43
-68
lines changed

10 files changed

+43
-68
lines changed

libcxx/include/__config

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -319,37 +319,12 @@ typedef __char32_t char32_t;
319319

320320
# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
321321

322-
// Objective-C++ features (opt-in)
323-
# if __has_feature(objc_arc)
324-
# define _LIBCPP_HAS_OBJC_ARC 1
325-
# else
326-
# define _LIBCPP_HAS_OBJC_ARC 0
327-
# endif
328-
329-
# if __has_feature(objc_arc_weak)
330-
# define _LIBCPP_HAS_OBJC_ARC_WEAK 1
331-
# else
332-
# define _LIBCPP_HAS_OBJC_ARC_WEAK 0
333-
# endif
334-
335-
# if __has_extension(blocks)
336-
# define _LIBCPP_HAS_EXTENSION_BLOCKS 1
337-
# else
338-
# define _LIBCPP_HAS_EXTENSION_BLOCKS 0
339-
# endif
340-
341-
# if _LIBCPP_HAS_EXTENSION_BLOCKS && defined(__APPLE__)
322+
# if __has_extension(blocks) && defined(__APPLE__)
342323
# define _LIBCPP_HAS_BLOCKS_RUNTIME 1
343324
# else
344325
# define _LIBCPP_HAS_BLOCKS_RUNTIME 0
345326
# endif
346327

347-
# if __has_feature(address_sanitizer)
348-
# define _LIBCPP_HAS_ASAN 1
349-
# else
350-
# define _LIBCPP_HAS_ASAN 0
351-
# endif
352-
353328
# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
354329

355330
# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__

libcxx/include/__debug_utils/sanitizers.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# pragma GCC system_header
1818
#endif
1919

20-
#if _LIBCPP_HAS_ASAN
20+
#if __has_feature(address_sanitizer)
2121

2222
extern "C" {
2323
_LIBCPP_EXPORTED_FROM_ABI void
@@ -28,12 +28,12 @@ _LIBCPP_EXPORTED_FROM_ABI int
2828
__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*);
2929
}
3030

31-
#endif // _LIBCPP_HAS_ASAN
31+
#endif // __has_feature(address_sanitizer)
3232

3333
_LIBCPP_BEGIN_NAMESPACE_STD
3434

3535
// ASan choices
36-
#if _LIBCPP_HAS_ASAN
36+
#if __has_feature(address_sanitizer)
3737
# define _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS 1
3838
#endif
3939

@@ -57,7 +57,7 @@ _LIBCPP_HIDE_FROM_ABI void __annotate_double_ended_contiguous_container(
5757
const void* __last_old_contained,
5858
const void* __first_new_contained,
5959
const void* __last_new_contained) {
60-
#if !_LIBCPP_HAS_ASAN
60+
#if !__has_feature(address_sanitizer)
6161
(void)__first_storage;
6262
(void)__last_storage;
6363
(void)__first_old_contained;
@@ -86,7 +86,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __annotate_contiguous_c
8686
const void* __last_storage,
8787
const void* __old_last_contained,
8888
const void* __new_last_contained) {
89-
#if !_LIBCPP_HAS_ASAN
89+
#if !__has_feature(address_sanitizer)
9090
(void)__first_storage;
9191
(void)__last_storage;
9292
(void)__old_last_contained;

libcxx/include/__functional/function.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ _LIBCPP_HIDE_FROM_ABI bool __not_null(function<_Fp> const& __f) {
122122
return !!__f;
123123
}
124124

125-
# if _LIBCPP_HAS_EXTENSION_BLOCKS
125+
# if __has_extension(blocks)
126126
template <class _Rp, class... _Args>
127127
_LIBCPP_HIDE_FROM_ABI bool __not_null(_Rp (^__p)(_Args...)) {
128128
return __p;
@@ -757,7 +757,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base
757757

758758
public:
759759
_LIBCPP_HIDE_FROM_ABI explicit __func(__block_type const& __f)
760-
# if _LIBCPP_HAS_OBJC_ARC
760+
# if __has_feature(objc_arc)
761761
: __f_(__f)
762762
# else
763763
: __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
@@ -768,7 +768,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base
768768
// [TODO] add && to save on a retain
769769

770770
_LIBCPP_HIDE_FROM_ABI explicit __func(__block_type __f, const _Alloc& /* unused */)
771-
# if _LIBCPP_HAS_OBJC_ARC
771+
# if __has_feature(objc_arc)
772772
: __f_(__f)
773773
# else
774774
: __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
@@ -790,7 +790,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base
790790
}
791791

792792
_LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy() _NOEXCEPT {
793-
# if !_LIBCPP_HAS_OBJC_ARC
793+
# if !__has_feature(objc_arc)
794794
if (__f_)
795795
_Block_release(__f_);
796796
# endif
@@ -822,7 +822,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base
822822
# endif // _LIBCPP_HAS_RTTI
823823
};
824824

825-
# endif // _LIBCPP_HAS_EXTENSION_BLOCKS
825+
# endif // _LIBCPP_HAS_BLOCKS_RUNTIME
826826

827827
} // namespace __function
828828

libcxx/include/__memory/addressof.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_NO_CFI _LIBCPP_HIDE_FROM_ABI _Tp* a
2323
return __builtin_addressof(__x);
2424
}
2525

26-
#if _LIBCPP_HAS_OBJC_ARC
26+
#if __has_feature(objc_arc)
2727
// Objective-C++ Automatic Reference Counting uses qualified pointers
2828
// that require special addressof() signatures.
2929
template <class _Tp>
3030
inline _LIBCPP_HIDE_FROM_ABI __strong _Tp* addressof(__strong _Tp& __x) _NOEXCEPT {
3131
return &__x;
3232
}
3333

34-
# if _LIBCPP_HAS_OBJC_ARC_WEAK
34+
# if __has_feature(objc_arc_weak)
3535
template <class _Tp>
3636
inline _LIBCPP_HIDE_FROM_ABI __weak _Tp* addressof(__weak _Tp& __x) _NOEXCEPT {
3737
return &__x;

libcxx/include/__type_traits/is_pointer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ template <class _Tp>
4040
struct __libcpp_remove_objc_qualifiers {
4141
typedef _Tp type;
4242
};
43-
# if _LIBCPP_HAS_OBJC_ARC
43+
# if __has_feature(objc_arc)
4444
// clang-format off
4545
template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __strong> { typedef _Tp type; };
4646
template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __weak> { typedef _Tp type; };

libcxx/include/__type_traits/is_scalar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_scalar_v = __is_scalar(_Tp);
3737

3838
template <class _Tp>
3939
struct __is_block : false_type {};
40-
# if _LIBCPP_HAS_EXTENSION_BLOCKS
40+
# if __has_extension(blocks)
4141
template <class _Rp, class... _Args>
4242
struct __is_block<_Rp (^)(_Args...)> : true_type {};
4343
# endif

libcxx/include/__vector/vector.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,42 +717,42 @@ class _LIBCPP_TEMPLATE_VIS vector {
717717

718718
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_new(size_type __current_size) const _NOEXCEPT {
719719
(void)__current_size;
720-
#if _LIBCPP_HAS_ASAN
720+
#if __has_feature(address_sanitizer)
721721
__annotate_contiguous_container(data() + capacity(), data() + __current_size);
722722
#endif
723723
}
724724

725725
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {
726-
#if _LIBCPP_HAS_ASAN
726+
#if __has_feature(address_sanitizer)
727727
__annotate_contiguous_container(data() + size(), data() + capacity());
728728
#endif
729729
}
730730

731731
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_increase(size_type __n) const _NOEXCEPT {
732732
(void)__n;
733-
#if _LIBCPP_HAS_ASAN
733+
#if __has_feature(address_sanitizer)
734734
__annotate_contiguous_container(data() + size(), data() + size() + __n);
735735
#endif
736736
}
737737

738738
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink(size_type __old_size) const _NOEXCEPT {
739739
(void)__old_size;
740-
#if _LIBCPP_HAS_ASAN
740+
#if __has_feature(address_sanitizer)
741741
__annotate_contiguous_container(data() + __old_size, data() + size());
742742
#endif
743743
}
744744

745745
struct _ConstructTransaction {
746746
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit _ConstructTransaction(vector& __v, size_type __n)
747747
: __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
748-
#if _LIBCPP_HAS_ASAN
748+
#if __has_feature(address_sanitizer)
749749
__v_.__annotate_increase(__n);
750750
#endif
751751
}
752752

753753
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() {
754754
__v_.__end_ = __pos_;
755-
#if _LIBCPP_HAS_ASAN
755+
#if __has_feature(address_sanitizer)
756756
if (__pos_ != __new_end_) {
757757
__v_.__annotate_shrink(__new_end_ - __v_.__begin_);
758758
}

libcxx/include/deque

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ private:
925925
(void)__end;
926926
(void)__annotation_type;
927927
(void)__place;
928-
# if _LIBCPP_HAS_ASAN
928+
# if __has_feature(address_sanitizer)
929929
// __beg - index of the first item to annotate
930930
// __end - index behind the last item to annotate (so last item + 1)
931931
// __annotation_type - __asan_unposion or __asan_poison
@@ -1018,23 +1018,23 @@ private:
10181018
std::__annotate_double_ended_contiguous_container<_Allocator>(
10191019
__mem_beg, __mem_end, __old_beg, __old_end, __new_beg, __new_end);
10201020
}
1021-
# endif // _LIBCPP_HAS_ASAN
1021+
# endif // __has_feature(address_sanitizer)
10221022
}
10231023

10241024
_LIBCPP_HIDE_FROM_ABI void __annotate_new(size_type __current_size) const _NOEXCEPT {
10251025
(void)__current_size;
1026-
# if _LIBCPP_HAS_ASAN
1026+
# if __has_feature(address_sanitizer)
10271027
if (__current_size == 0)
10281028
__annotate_from_to(0, __map_.size() * __block_size, __asan_poison, __asan_back_moved);
10291029
else {
10301030
__annotate_from_to(0, __start_, __asan_poison, __asan_front_moved);
10311031
__annotate_from_to(__start_ + __current_size, __map_.size() * __block_size, __asan_poison, __asan_back_moved);
10321032
}
1033-
# endif // _LIBCPP_HAS_ASAN
1033+
# endif // __has_feature(address_sanitizer)
10341034
}
10351035

10361036
_LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {
1037-
# if _LIBCPP_HAS_ASAN
1037+
# if __has_feature(address_sanitizer)
10381038
if (empty()) {
10391039
for (size_t __i = 0; __i < __map_.size(); ++__i) {
10401040
__annotate_whole_block(__i, __asan_unposion);
@@ -1043,35 +1043,35 @@ private:
10431043
__annotate_from_to(0, __start_, __asan_unposion, __asan_front_moved);
10441044
__annotate_from_to(__start_ + size(), __map_.size() * __block_size, __asan_unposion, __asan_back_moved);
10451045
}
1046-
# endif // _LIBCPP_HAS_ASAN
1046+
# endif // __has_feature(address_sanitizer)
10471047
}
10481048

10491049
_LIBCPP_HIDE_FROM_ABI void __annotate_increase_front(size_type __n) const _NOEXCEPT {
10501050
(void)__n;
1051-
# if _LIBCPP_HAS_ASAN
1051+
# if __has_feature(address_sanitizer)
10521052
__annotate_from_to(__start_ - __n, __start_, __asan_unposion, __asan_front_moved);
10531053
# endif
10541054
}
10551055

10561056
_LIBCPP_HIDE_FROM_ABI void __annotate_increase_back(size_type __n) const _NOEXCEPT {
10571057
(void)__n;
1058-
# if _LIBCPP_HAS_ASAN
1058+
# if __has_feature(address_sanitizer)
10591059
__annotate_from_to(__start_ + size(), __start_ + size() + __n, __asan_unposion, __asan_back_moved);
10601060
# endif
10611061
}
10621062

10631063
_LIBCPP_HIDE_FROM_ABI void __annotate_shrink_front(size_type __old_size, size_type __old_start) const _NOEXCEPT {
10641064
(void)__old_size;
10651065
(void)__old_start;
1066-
# if _LIBCPP_HAS_ASAN
1066+
# if __has_feature(address_sanitizer)
10671067
__annotate_from_to(__old_start, __old_start + (__old_size - size()), __asan_poison, __asan_front_moved);
10681068
# endif
10691069
}
10701070

10711071
_LIBCPP_HIDE_FROM_ABI void __annotate_shrink_back(size_type __old_size, size_type __old_start) const _NOEXCEPT {
10721072
(void)__old_size;
10731073
(void)__old_start;
1074-
# if _LIBCPP_HAS_ASAN
1074+
# if __has_feature(address_sanitizer)
10751075
__annotate_from_to(__old_start + size(), __old_start + __old_size, __asan_poison, __asan_back_moved);
10761076
# endif
10771077
}
@@ -1084,7 +1084,7 @@ private:
10841084
__annotate_whole_block(size_t __block_index, __asan_annotation_type __annotation_type) const _NOEXCEPT {
10851085
(void)__block_index;
10861086
(void)__annotation_type;
1087-
# if _LIBCPP_HAS_ASAN
1087+
# if __has_feature(address_sanitizer)
10881088
__map_const_iterator __block_it = __map_.begin() + __block_index;
10891089
const void* __block_start = std::__to_address(*__block_it);
10901090
const void* __block_end = std::__to_address(*__block_it + __block_size);
@@ -1097,7 +1097,7 @@ private:
10971097
}
10981098
# endif
10991099
}
1100-
# if _LIBCPP_HAS_ASAN
1100+
# if __has_feature(address_sanitizer)
11011101

11021102
public:
11031103
_LIBCPP_HIDE_FROM_ABI bool __verify_asan_annotations() const _NOEXCEPT {
@@ -1159,7 +1159,7 @@ public:
11591159
}
11601160

11611161
private:
1162-
# endif // _LIBCPP_HAS_ASAN
1162+
# endif // __has_feature(address_sanitizer)
11631163
_LIBCPP_HIDE_FROM_ABI bool __maybe_remove_front_spare(bool __keep_one = true) {
11641164
if (__front_spare_blocks() >= 2 || (!__keep_one && __front_spare_blocks())) {
11651165
__annotate_whole_block(0, __asan_unposion);

libcxx/include/string

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ basic_string<char32_t> operator""s( const char32_t *str, size_t len );
676676
_LIBCPP_PUSH_MACROS
677677
# include <__undef_macros>
678678

679-
# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
679+
# if __has_feature(address_sanitizer) && _LIBCPP_INSTRUMENTED_WITH_ASAN
680680
# define _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS __attribute__((__no_sanitize__("address")))
681681
// This macro disables AddressSanitizer (ASan) instrumentation for a specific function,
682682
// allowing memory accesses that would normally trigger ASan errors to proceed without crashing.
@@ -747,7 +747,7 @@ public:
747747
//
748748
// This string implementation doesn't contain any references into itself. It only contains a bit that says whether
749749
// it is in small or large string mode, so the entire structure is trivially relocatable if its members are.
750-
# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
750+
# if __has_feature(address_sanitizer) && _LIBCPP_INSTRUMENTED_WITH_ASAN
751751
// When compiling with AddressSanitizer (ASan), basic_string cannot be trivially
752752
// relocatable. Because the object's memory might be poisoned when its content
753753
// is kept inside objects memory (short string optimization), instead of in allocated
@@ -762,7 +762,7 @@ public:
762762
void>;
763763
# endif
764764

765-
# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
765+
# if __has_feature(address_sanitizer) && _LIBCPP_INSTRUMENTED_WITH_ASAN
766766
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pointer __asan_volatile_wrapper(pointer const& __ptr) const {
767767
if (__libcpp_is_constant_evaluated())
768768
return __ptr;
@@ -2153,7 +2153,7 @@ private:
21532153
__annotate_contiguous_container(const void* __old_mid, const void* __new_mid) const {
21542154
(void)__old_mid;
21552155
(void)__new_mid;
2156-
# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
2156+
# if __has_feature(address_sanitizer) && _LIBCPP_INSTRUMENTED_WITH_ASAN
21572157
# if defined(__APPLE__)
21582158
// TODO: remove after addressing issue #96099 (https://github.com/llvm/llvm-project/issues/96099)
21592159
if (!__is_long())
@@ -2165,30 +2165,30 @@ private:
21652165

21662166
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_new(size_type __current_size) const _NOEXCEPT {
21672167
(void)__current_size;
2168-
# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
2168+
# if __has_feature(address_sanitizer) && _LIBCPP_INSTRUMENTED_WITH_ASAN
21692169
if (!__libcpp_is_constant_evaluated())
21702170
__annotate_contiguous_container(data() + capacity() + 1, data() + __current_size + 1);
21712171
# endif
21722172
}
21732173

21742174
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_delete() const _NOEXCEPT {
2175-
# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
2175+
# if __has_feature(address_sanitizer) && _LIBCPP_INSTRUMENTED_WITH_ASAN
21762176
if (!__libcpp_is_constant_evaluated())
21772177
__annotate_contiguous_container(data() + size() + 1, data() + capacity() + 1);
21782178
# endif
21792179
}
21802180

21812181
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_increase(size_type __n) const _NOEXCEPT {
21822182
(void)__n;
2183-
# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
2183+
# if __has_feature(address_sanitizer) && _LIBCPP_INSTRUMENTED_WITH_ASAN
21842184
if (!__libcpp_is_constant_evaluated())
21852185
__annotate_contiguous_container(data() + size() + 1, data() + size() + 1 + __n);
21862186
# endif
21872187
}
21882188

21892189
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_shrink(size_type __old_size) const _NOEXCEPT {
21902190
(void)__old_size;
2191-
# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
2191+
# if __has_feature(address_sanitizer) && _LIBCPP_INSTRUMENTED_WITH_ASAN
21922192
if (!__libcpp_is_constant_evaluated())
21932193
__annotate_contiguous_container(data() + __old_size + 1, data() + size() + 1);
21942194
# endif

libcxx/test/libcxx/type_traits/is_trivially_relocatable.compile.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static_assert(!std::__libcpp_is_trivially_relocatable<std::array<NotTriviallyCop
8787
static_assert(std::__libcpp_is_trivially_relocatable<std::array<std::unique_ptr<int>, 1> >::value, "");
8888

8989
// basic_string
90-
#if !_LIBCPP_HAS_ASAN || !_LIBCPP_INSTRUMENTED_WITH_ASAN
90+
#if !__has_feature(address_sanitizer) || !_LIBCPP_INSTRUMENTED_WITH_ASAN
9191
struct MyChar {
9292
char c;
9393
};

0 commit comments

Comments
 (0)