diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -43,4 +43,4 @@ API Changes ----------- -- ... +- The ``std::pointer_safety`` utility is not available in C++03 anymore. Furthermore, in other standard modes, it has changed from a struct to an enum class, which is an ABI break. Finally, the ``std::get_pointer_safety`` function was previously in the dylib, but it is now defined as inline in the headers. While those are all ABI breaks, we do not expect them to have any measurable impact because the support for garbage collection was never actually implemented. diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -88,11 +88,6 @@ // provided under the alternate keyword __nullptr, which changes the mangling // of nullptr_t. This option is ABI incompatible with GCC in C++03 mode. # define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR -// Define the `pointer_safety` enum as a C++11 strongly typed enumeration -// instead of as a class simulating an enum. If this option is enabled -// `pointer_safety` and `get_pointer_safety()` will no longer be available -// in C++03. -# define _LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE // Define a key function for `bad_function_call` in the library, to centralize // its vtable and typeinfo to libc++ rather than having all other libraries // using that class define their own copies. diff --git a/libcxx/include/__memory/pointer_safety.h b/libcxx/include/__memory/pointer_safety.h --- a/libcxx/include/__memory/pointer_safety.h +++ b/libcxx/include/__memory/pointer_safety.h @@ -21,50 +21,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD -//enum class -#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) -# ifndef _LIBCPP_CXX03_LANG +#if !defined(_LIBCPP_CXX03_LANG) + enum class pointer_safety : unsigned char { relaxed, preferred, strict }; -# endif -#else -struct _LIBCPP_TYPE_VIS pointer_safety -{ - enum __lx - { - relaxed, - preferred, - strict - }; - - __lx __v_; - - _LIBCPP_INLINE_VISIBILITY - pointer_safety() : __v_() {} - - _LIBCPP_INLINE_VISIBILITY - pointer_safety(__lx __v) : __v_(__v) {} - _LIBCPP_INLINE_VISIBILITY - operator int() const {return __v_;} -}; -#endif -#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \ - defined(_LIBCPP_BUILDING_LIBRARY) -_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT; -#else -// This function is only offered in C++03 under ABI v1. -# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG) inline _LIBCPP_INLINE_VISIBILITY pointer_safety get_pointer_safety() _NOEXCEPT { return pointer_safety::relaxed; } -# endif -#endif - _LIBCPP_FUNC_VIS void declare_reachable(void* __p); _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n); @@ -79,6 +47,8 @@ return static_cast<_Tp*>(__undeclare_reachable(__p)); } +#endif // !C++03 + _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/libcxx/include/memory b/libcxx/include/memory --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -651,12 +651,12 @@ inline constexpr bool uses_allocator_v = uses_allocator::value; // Pointer safety -enum class pointer_safety { relaxed, preferred, strict }; -void declare_reachable(void *p); -template T *undeclare_reachable(T *p); -void declare_no_pointers(char *p, size_t n); -void undeclare_no_pointers(char *p, size_t n); -pointer_safety get_pointer_safety() noexcept; +enum class pointer_safety { relaxed, preferred, strict }; // since C++11 +void declare_reachable(void *p); // since C++11 +template T *undeclare_reachable(T *p); // since C++11 +void declare_no_pointers(char *p, size_t n); // since C++11 +void undeclare_no_pointers(char *p, size_t n); // since C++11 +pointer_safety get_pointer_safety() noexcept; // since C++11 void* align(size_t alignment, size_t size, void*& ptr, size_t& space); diff --git a/libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.no_new_in_libcxx.abilist b/libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.no_new_in_libcxx.abilist --- a/libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.no_new_in_libcxx.abilist +++ b/libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.no_new_in_libcxx.abilist @@ -1507,7 +1507,6 @@ {'is_defined': True, 'name': '__ZNSt3__118condition_variable4waitERNS_11unique_lockINS_5mutexEEE', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__118condition_variableD1Ev', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__118condition_variableD2Ev', 'type': 'FUNC'} -{'is_defined': True, 'name': '__ZNSt3__118get_pointer_safetyEv', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__118shared_timed_mutex11lock_sharedEv', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__118shared_timed_mutex13unlock_sharedEv', 'type': 'FUNC'} {'is_defined': True, 'name': '__ZNSt3__118shared_timed_mutex15try_lock_sharedEv', 'type': 'FUNC'} diff --git a/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.no_new_in_libcxx.abilist b/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.no_new_in_libcxx.abilist --- a/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.no_new_in_libcxx.abilist +++ b/libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.no_new_in_libcxx.abilist @@ -1194,7 +1194,6 @@ {'is_defined': True, 'name': '_ZNSt3__118condition_variable4waitERNS_11unique_lockINS_5mutexEEE', 'type': 'FUNC'} {'is_defined': True, 'name': '_ZNSt3__118condition_variableD1Ev', 'type': 'FUNC'} {'is_defined': True, 'name': '_ZNSt3__118condition_variableD2Ev', 'type': 'FUNC'} -{'is_defined': True, 'name': '_ZNSt3__118get_pointer_safetyEv', 'type': 'FUNC'} {'is_defined': True, 'name': '_ZNSt3__118shared_timed_mutex11lock_sharedEv', 'type': 'FUNC'} {'is_defined': True, 'name': '_ZNSt3__118shared_timed_mutex13unlock_sharedEv', 'type': 'FUNC'} {'is_defined': True, 'name': '_ZNSt3__118shared_timed_mutex15try_lock_sharedEv', 'type': 'FUNC'} diff --git a/libcxx/src/memory.cpp b/libcxx/src/memory.cpp --- a/libcxx/src/memory.cpp +++ b/libcxx/src/memory.cpp @@ -198,13 +198,6 @@ { } -#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) -pointer_safety get_pointer_safety() noexcept -{ - return pointer_safety::relaxed; -} -#endif - void* __undeclare_reachable(void* p) { diff --git a/libcxx/test/libcxx/utilities/memory/util.dynamic.safety/get_pointer_safety_cxx03.pass.cpp b/libcxx/test/libcxx/utilities/memory/util.dynamic.safety/get_pointer_safety_cxx03.pass.cpp deleted file mode 100644 --- a/libcxx/test/libcxx/utilities/memory/util.dynamic.safety/get_pointer_safety_cxx03.pass.cpp +++ /dev/null @@ -1,47 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// - -// pointer_safety get_pointer_safety(); - -#include -#include - -#include "test_macros.h" - -// libc++ doesn't offer std::pointer_safety in C++03 under the new ABI -#if TEST_STD_VER < 11 && defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) -#define TEST_IS_UNSUPPORTED -#endif - -#ifndef TEST_IS_UNSUPPORTED -void test_pr26961() { - std::pointer_safety d; - d = std::get_pointer_safety(); - assert(d == std::get_pointer_safety()); -} -#endif - -int main(int, char**) -{ -#ifndef TEST_IS_UNSUPPORTED - { - // Test that std::pointer_safety is still offered in C++03 under the old ABI. - std::pointer_safety r = std::get_pointer_safety(); - assert(r == std::pointer_safety::relaxed || - r == std::pointer_safety::preferred || - r == std::pointer_safety::strict); - } - { - test_pr26961(); - } -#endif - - return 0; -} diff --git a/libcxx/test/libcxx/utilities/memory/util.dynamic.safety/get_pointer_safety_new_abi.pass.cpp b/libcxx/test/libcxx/utilities/memory/util.dynamic.safety/get_pointer_safety_new_abi.pass.cpp deleted file mode 100644 --- a/libcxx/test/libcxx/utilities/memory/util.dynamic.safety/get_pointer_safety_new_abi.pass.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// - -// pointer_safety get_pointer_safety(); - -// The pointer_safety interface is no longer provided in C++03 in the new ABI. -// XFAIL: c++03 - -// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE - -#include -#include - -#include "test_macros.h" - -int main(int, char**) -{ - { - static_assert(std::is_enum::value, ""); - static_assert(!std::is_convertible::value, ""); - static_assert(std::is_same< - std::underlying_type::type, - unsigned char - >::value, ""); - } - { - std::pointer_safety r = std::get_pointer_safety(); - assert(r == std::pointer_safety::relaxed || - r == std::pointer_safety::preferred || - r == std::pointer_safety::strict); - } - - return 0; -} diff --git a/libcxx/test/std/utilities/memory/util.dynamic.safety/get_pointer_safety.pass.cpp b/libcxx/test/std/utilities/memory/util.dynamic.safety/get_pointer_safety.pass.cpp --- a/libcxx/test/std/utilities/memory/util.dynamic.safety/get_pointer_safety.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.dynamic.safety/get_pointer_safety.pass.cpp @@ -17,23 +17,27 @@ #include "test_macros.h" - -void test_pr26961() { - std::pointer_safety d; - d = std::get_pointer_safety(); - assert(d == std::get_pointer_safety()); -} - int main(int, char**) { + { + static_assert(std::is_enum::value, ""); + static_assert(!std::is_convertible::value, ""); + static_assert(std::is_same< + std::underlying_type::type, + unsigned char + >::value, ""); + } { std::pointer_safety r = std::get_pointer_safety(); assert(r == std::pointer_safety::relaxed || r == std::pointer_safety::preferred || r == std::pointer_safety::strict); } + // Regression test for https://llvm.org/PR26961 { - test_pr26961(); + std::pointer_safety d; + d = std::get_pointer_safety(); + assert(d == std::get_pointer_safety()); } return 0;