Skip to content

Commit 7c81024

Browse files
committed
[libc++] Remove workarounds for missing __builtin_addressof
All supported compilers implement __builtin_addressof. Even MSVC implements addressof as a simple call to __builtin_addressof, so it would work if we were to port libc++ to that compiler. Differential Revision: https://reviews.llvm.org/D107905
1 parent 2c1789b commit 7c81024

File tree

9 files changed

+31
-221
lines changed

9 files changed

+31
-221
lines changed

libcxx/include/__config

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,6 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
12831283
# define _LIBCPP_SAFE_STATIC
12841284
#endif
12851285

1286-
#if !__has_builtin(__builtin_addressof) && _GNUC_VER < 700
1287-
#define _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
1288-
#endif
1289-
12901286
#if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
12911287
# define _LIBCPP_DIAGNOSE_WARNING(...) \
12921288
__attribute__((diagnose_if(__VA_ARGS__, "warning")))

libcxx/include/__memory/addressof.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ _LIBCPP_PUSH_MACROS
2121

2222
_LIBCPP_BEGIN_NAMESPACE_STD
2323

24-
#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
25-
2624
template <class _Tp>
2725
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
2826
_LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
@@ -32,19 +30,6 @@ addressof(_Tp& __x) _NOEXCEPT
3230
return __builtin_addressof(__x);
3331
}
3432

35-
#else
36-
37-
template <class _Tp>
38-
inline _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
39-
_Tp*
40-
addressof(_Tp& __x) _NOEXCEPT
41-
{
42-
return reinterpret_cast<_Tp *>(
43-
const_cast<char *>(&reinterpret_cast<const volatile char &>(__x)));
44-
}
45-
46-
#endif // _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
47-
4833
#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
4934
// Objective-C++ Automatic Reference Counting uses qualified pointers
5035
// that require special addressof() signatures. When

libcxx/include/optional

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -883,11 +883,7 @@ public:
883883
operator->() const
884884
{
885885
_LIBCPP_ASSERT(this->has_value(), "optional operator-> called on a disengaged value");
886-
#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
887886
return _VSTD::addressof(this->__get());
888-
#else
889-
return __operator_arrow(__has_operator_addressof<value_type>{}, this->__get());
890-
#endif
891887
}
892888

893889
_LIBCPP_INLINE_VISIBILITY
@@ -896,11 +892,7 @@ public:
896892
operator->()
897893
{
898894
_LIBCPP_ASSERT(this->has_value(), "optional operator-> called on a disengaged value");
899-
#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
900895
return _VSTD::addressof(this->__get());
901-
#else
902-
return __operator_arrow(__has_operator_addressof<value_type>{}, this->__get());
903-
#endif
904896
}
905897

906898
_LIBCPP_INLINE_VISIBILITY
@@ -1006,23 +998,6 @@ public:
1006998
}
1007999

10081000
using __base::reset;
1009-
1010-
private:
1011-
template <class _Up>
1012-
_LIBCPP_INLINE_VISIBILITY
1013-
static _LIBCPP_CONSTEXPR_AFTER_CXX17 _Up*
1014-
__operator_arrow(true_type, _Up& __x)
1015-
{
1016-
return _VSTD::addressof(__x);
1017-
}
1018-
1019-
template <class _Up>
1020-
_LIBCPP_INLINE_VISIBILITY
1021-
static constexpr _Up*
1022-
__operator_arrow(false_type, _Up& __x)
1023-
{
1024-
return &__x;
1025-
}
10261001
};
10271002

10281003
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES

libcxx/include/type_traits

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4349,40 +4349,6 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
43494349
typename __sfinae_underlying_type<_Tp>::__promoted_type
43504350
__convert_to_integral(_Tp __val) { return __val; }
43514351

4352-
#ifndef _LIBCPP_CXX03_LANG
4353-
4354-
template <class _Tp>
4355-
struct __has_operator_addressof_member_imp
4356-
{
4357-
template <class _Up>
4358-
static auto __test(int)
4359-
-> typename __select_2nd<decltype(declval<_Up>().operator&()), true_type>::type;
4360-
template <class>
4361-
static auto __test(long) -> false_type;
4362-
4363-
static const bool value = decltype(__test<_Tp>(0))::value;
4364-
};
4365-
4366-
template <class _Tp>
4367-
struct __has_operator_addressof_free_imp
4368-
{
4369-
template <class _Up>
4370-
static auto __test(int)
4371-
-> typename __select_2nd<decltype(operator&(declval<_Up>())), true_type>::type;
4372-
template <class>
4373-
static auto __test(long) -> false_type;
4374-
4375-
static const bool value = decltype(__test<_Tp>(0))::value;
4376-
};
4377-
4378-
template <class _Tp>
4379-
struct __has_operator_addressof
4380-
: public integral_constant<bool, __has_operator_addressof_member_imp<_Tp>::value
4381-
|| __has_operator_addressof_free_imp<_Tp>::value>
4382-
{};
4383-
4384-
#endif // _LIBCPP_CXX03_LANG
4385-
43864352
// is_scoped_enum [meta.unary.prop]
43874353

43884354
#if _LIBCPP_STD_VER > 20

libcxx/include/version

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ __cpp_lib_void_t 201411L <type_traits>
199199
#endif
200200

201201
#if _LIBCPP_STD_VER > 14
202-
# if !defined(_LIBCPP_HAS_NO_BUILTIN_ADDRESSOF)
203-
# define __cpp_lib_addressof_constexpr 201603L
204-
# endif
202+
# define __cpp_lib_addressof_constexpr 201603L
205203
# define __cpp_lib_allocator_traits_is_always_equal 201411L
206204
# define __cpp_lib_any 201606L
207205
# define __cpp_lib_apply 201603L

libcxx/test/libcxx/utilities/meta/meta.unary/meta.unary.prop/__has_operator_addressof.pass.cpp

Lines changed: 0 additions & 72 deletions
This file was deleted.

libcxx/test/std/language.support/support.limits/support.limits.general/memory.version.pass.cpp

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,11 @@
178178

179179
#elif TEST_STD_VER == 17
180180

181-
# if TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700
182-
# ifndef __cpp_lib_addressof_constexpr
183-
# error "__cpp_lib_addressof_constexpr should be defined in c++17"
184-
# endif
185-
# if __cpp_lib_addressof_constexpr != 201603L
186-
# error "__cpp_lib_addressof_constexpr should have the value 201603L in c++17"
187-
# endif
188-
# else
189-
# ifdef __cpp_lib_addressof_constexpr
190-
# error "__cpp_lib_addressof_constexpr should not be defined when TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700 is not defined!"
191-
# endif
181+
# ifndef __cpp_lib_addressof_constexpr
182+
# error "__cpp_lib_addressof_constexpr should be defined in c++17"
183+
# endif
184+
# if __cpp_lib_addressof_constexpr != 201603L
185+
# error "__cpp_lib_addressof_constexpr should have the value 201603L in c++17"
192186
# endif
193187

194188
# ifndef __cpp_lib_allocator_traits_is_always_equal
@@ -274,17 +268,11 @@
274268

275269
#elif TEST_STD_VER == 20
276270

277-
# if TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700
278-
# ifndef __cpp_lib_addressof_constexpr
279-
# error "__cpp_lib_addressof_constexpr should be defined in c++20"
280-
# endif
281-
# if __cpp_lib_addressof_constexpr != 201603L
282-
# error "__cpp_lib_addressof_constexpr should have the value 201603L in c++20"
283-
# endif
284-
# else
285-
# ifdef __cpp_lib_addressof_constexpr
286-
# error "__cpp_lib_addressof_constexpr should not be defined when TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700 is not defined!"
287-
# endif
271+
# ifndef __cpp_lib_addressof_constexpr
272+
# error "__cpp_lib_addressof_constexpr should be defined in c++20"
273+
# endif
274+
# if __cpp_lib_addressof_constexpr != 201603L
275+
# error "__cpp_lib_addressof_constexpr should have the value 201603L in c++20"
288276
# endif
289277

290278
# ifndef __cpp_lib_allocator_traits_is_always_equal
@@ -424,17 +412,11 @@
424412

425413
#elif TEST_STD_VER > 20
426414

427-
# if TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700
428-
# ifndef __cpp_lib_addressof_constexpr
429-
# error "__cpp_lib_addressof_constexpr should be defined in c++2b"
430-
# endif
431-
# if __cpp_lib_addressof_constexpr != 201603L
432-
# error "__cpp_lib_addressof_constexpr should have the value 201603L in c++2b"
433-
# endif
434-
# else
435-
# ifdef __cpp_lib_addressof_constexpr
436-
# error "__cpp_lib_addressof_constexpr should not be defined when TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700 is not defined!"
437-
# endif
415+
# ifndef __cpp_lib_addressof_constexpr
416+
# error "__cpp_lib_addressof_constexpr should be defined in c++2b"
417+
# endif
418+
# if __cpp_lib_addressof_constexpr != 201603L
419+
# error "__cpp_lib_addressof_constexpr should have the value 201603L in c++2b"
438420
# endif
439421

440422
# ifndef __cpp_lib_allocator_traits_is_always_equal

libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,17 +1285,11 @@
12851285

12861286
#elif TEST_STD_VER == 17
12871287

1288-
# if TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700
1289-
# ifndef __cpp_lib_addressof_constexpr
1290-
# error "__cpp_lib_addressof_constexpr should be defined in c++17"
1291-
# endif
1292-
# if __cpp_lib_addressof_constexpr != 201603L
1293-
# error "__cpp_lib_addressof_constexpr should have the value 201603L in c++17"
1294-
# endif
1295-
# else
1296-
# ifdef __cpp_lib_addressof_constexpr
1297-
# error "__cpp_lib_addressof_constexpr should not be defined when TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700 is not defined!"
1298-
# endif
1288+
# ifndef __cpp_lib_addressof_constexpr
1289+
# error "__cpp_lib_addressof_constexpr should be defined in c++17"
1290+
# endif
1291+
# if __cpp_lib_addressof_constexpr != 201603L
1292+
# error "__cpp_lib_addressof_constexpr should have the value 201603L in c++17"
12991293
# endif
13001294

13011295
# ifndef __cpp_lib_allocator_traits_is_always_equal
@@ -2091,17 +2085,11 @@
20912085

20922086
#elif TEST_STD_VER == 20
20932087

2094-
# if TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700
2095-
# ifndef __cpp_lib_addressof_constexpr
2096-
# error "__cpp_lib_addressof_constexpr should be defined in c++20"
2097-
# endif
2098-
# if __cpp_lib_addressof_constexpr != 201603L
2099-
# error "__cpp_lib_addressof_constexpr should have the value 201603L in c++20"
2100-
# endif
2101-
# else
2102-
# ifdef __cpp_lib_addressof_constexpr
2103-
# error "__cpp_lib_addressof_constexpr should not be defined when TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700 is not defined!"
2104-
# endif
2088+
# ifndef __cpp_lib_addressof_constexpr
2089+
# error "__cpp_lib_addressof_constexpr should be defined in c++20"
2090+
# endif
2091+
# if __cpp_lib_addressof_constexpr != 201603L
2092+
# error "__cpp_lib_addressof_constexpr should have the value 201603L in c++20"
21052093
# endif
21062094

21072095
# ifndef __cpp_lib_allocator_traits_is_always_equal
@@ -3254,17 +3242,11 @@
32543242

32553243
#elif TEST_STD_VER > 20
32563244

3257-
# if TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700
3258-
# ifndef __cpp_lib_addressof_constexpr
3259-
# error "__cpp_lib_addressof_constexpr should be defined in c++2b"
3260-
# endif
3261-
# if __cpp_lib_addressof_constexpr != 201603L
3262-
# error "__cpp_lib_addressof_constexpr should have the value 201603L in c++2b"
3263-
# endif
3264-
# else
3265-
# ifdef __cpp_lib_addressof_constexpr
3266-
# error "__cpp_lib_addressof_constexpr should not be defined when TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700 is not defined!"
3267-
# endif
3245+
# ifndef __cpp_lib_addressof_constexpr
3246+
# error "__cpp_lib_addressof_constexpr should be defined in c++2b"
3247+
# endif
3248+
# if __cpp_lib_addressof_constexpr != 201603L
3249+
# error "__cpp_lib_addressof_constexpr should have the value 201603L in c++2b"
32683250
# endif
32693251

32703252
# ifndef __cpp_lib_allocator_traits_is_always_equal

libcxx/utils/generate_feature_test_macro_components.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ def add_version_header(tc):
6666
"name": "__cpp_lib_addressof_constexpr",
6767
"values": { "c++17": 201603 },
6868
"headers": ["memory"],
69-
"test_suite_guard": "TEST_HAS_BUILTIN(__builtin_addressof) || TEST_GCC_VER >= 700",
70-
"libcxx_guard": "!defined(_LIBCPP_HAS_NO_BUILTIN_ADDRESSOF)",
7169
}, {
7270
"name": "__cpp_lib_allocator_traits_is_always_equal",
7371
"values": { "c++17": 201411 },

0 commit comments

Comments
 (0)