diff --git a/libcxx/test/libcxx/containers/associative/map/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/associative/map/abi.compile.pass.cpp new file mode 100644 index 0000000000000..04c1802bc84f6 --- /dev/null +++ b/libcxx/test/libcxx/containers/associative/map/abi.compile.pass.cpp @@ -0,0 +1,161 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: libcpp-abi-no-compressed-pair-padding + +// XFAIL: FROZEN-CXX03-HEADERS-FIXME + +#include +#include + +#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" + +template +class small_pointer { + std::uint16_t offset; +}; + +template +class small_iter_allocator { +public: + using value_type = T; + using pointer = small_pointer; + using size_type = std::uint16_t; + using difference_type = std::int16_t; + + small_iter_allocator() TEST_NOEXCEPT {} + + template + small_iter_allocator(small_iter_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; } + friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; } +}; + +template +class final_small_iter_allocator final { +public: + using value_type = T; + using pointer = small_pointer; + using size_type = std::uint16_t; + using difference_type = std::int16_t; + + final_small_iter_allocator() TEST_NOEXCEPT {} + + template + final_small_iter_allocator(final_small_iter_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(final_small_iter_allocator, final_small_iter_allocator) { return true; } + friend bool operator!=(final_small_iter_allocator, final_small_iter_allocator) { return false; } +}; + +struct allocator_base {}; + +// Make sure that types with a common base type don't get broken. See https://llvm.org/PR154146 +template +struct common_base_allocator : allocator_base { + using value_type = T; + + common_base_allocator() TEST_NOEXCEPT {} + + template + common_base_allocator(common_base_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(common_base_allocator, common_base_allocator) { return true; } + friend bool operator!=(common_base_allocator, common_base_allocator) { return false; } +}; + +template +using map_alloc = std::map, Alloc>; + +struct user_struct { + map_alloc > > v; + [[no_unique_address]] common_base_allocator a; +}; + +#if __SIZE_WIDTH__ == 64 +static_assert(sizeof(user_struct) == 32, ""); +static_assert(TEST_ALIGNOF(user_struct) == 8, ""); + +static_assert(sizeof(map_alloc > >) == 24, ""); +static_assert(sizeof(map_alloc > >) == 24, ""); +static_assert(sizeof(map_alloc > >) == 40, ""); +static_assert(sizeof(map_alloc > >) == 6, ""); +static_assert(sizeof(map_alloc > >) == 8, ""); + +static_assert(sizeof(map_alloc > >) == 24, ""); +static_assert(sizeof(map_alloc > >) == 24, ""); +static_assert(sizeof(map_alloc > >) == 40, ""); +static_assert(sizeof(map_alloc > >) == 6, ""); +static_assert(sizeof(map_alloc > >) == 8, ""); + +static_assert(TEST_ALIGNOF(map_alloc > >) == 8, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 8, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 8, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 2, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 2, ""); + +static_assert(TEST_ALIGNOF(map_alloc > >) == 8, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 8, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 8, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 2, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 2, ""); + +struct TEST_ALIGNAS(32) AlignedLess {}; + +// This part of the ABI has been broken between LLVM 19 and LLVM 20. +static_assert(sizeof(std::map) == 64, ""); +static_assert(TEST_ALIGNOF(std::map) == 32, ""); + +#elif __SIZE_WIDTH__ == 32 +static_assert(sizeof(user_struct) == 16, ""); +static_assert(TEST_ALIGNOF(user_struct) == 4, ""); + +static_assert(sizeof(map_alloc > >) == 12, ""); +static_assert(sizeof(map_alloc > >) == 12, ""); +static_assert(sizeof(map_alloc > >) == 24, ""); +static_assert(sizeof(map_alloc > >) == 6, ""); +static_assert(sizeof(map_alloc > >) == 8, ""); + +static_assert(sizeof(map_alloc > >) == 12, ""); +static_assert(sizeof(map_alloc > >) == 12, ""); +static_assert(sizeof(map_alloc > >) == 24, ""); +static_assert(sizeof(map_alloc > >) == 6, ""); +static_assert(sizeof(map_alloc > >) == 8, ""); + +static_assert(TEST_ALIGNOF(map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 2, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 2, ""); + +static_assert(TEST_ALIGNOF(map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 2, ""); +static_assert(TEST_ALIGNOF(map_alloc > >) == 2, ""); + +struct TEST_ALIGNAS(32) AlignedLess {}; + +static_assert(sizeof(std::map) == 64); +static_assert(TEST_ALIGNOF(std::map) == 32); + +#else +# error std::size_t has an unexpected size +#endif diff --git a/libcxx/test/libcxx/containers/associative/set/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/associative/set/abi.compile.pass.cpp new file mode 100644 index 0000000000000..1b85bb7c93773 --- /dev/null +++ b/libcxx/test/libcxx/containers/associative/set/abi.compile.pass.cpp @@ -0,0 +1,161 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: libcpp-abi-no-compressed-pair-padding + +// XFAIL: FROZEN-CXX03-HEADERS-FIXME + +#include +#include + +#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" + +template +class small_pointer { + std::uint16_t offset; +}; + +template +class small_iter_allocator { +public: + using value_type = T; + using pointer = small_pointer; + using size_type = std::uint16_t; + using difference_type = std::int16_t; + + small_iter_allocator() TEST_NOEXCEPT {} + + template + small_iter_allocator(small_iter_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; } + friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; } +}; + +template +class final_small_iter_allocator final { +public: + using value_type = T; + using pointer = small_pointer; + using size_type = std::uint16_t; + using difference_type = std::int16_t; + + final_small_iter_allocator() TEST_NOEXCEPT {} + + template + final_small_iter_allocator(final_small_iter_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(final_small_iter_allocator, final_small_iter_allocator) { return true; } + friend bool operator!=(final_small_iter_allocator, final_small_iter_allocator) { return false; } +}; + +struct allocator_base {}; + +// Make sure that types with a common base type don't get broken. See https://llvm.org/PR154146 +template +struct common_base_allocator : allocator_base { + using value_type = T; + + common_base_allocator() TEST_NOEXCEPT {} + + template + common_base_allocator(common_base_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(common_base_allocator, common_base_allocator) { return true; } + friend bool operator!=(common_base_allocator, common_base_allocator) { return false; } +}; + +template +using set_alloc = std::set, Alloc>; + +struct user_struct { + set_alloc > v; + [[no_unique_address]] common_base_allocator a; +}; + +#if __SIZE_WIDTH__ == 64 +static_assert(sizeof(user_struct) == 32, ""); +static_assert(TEST_ALIGNOF(user_struct) == 8, ""); + +static_assert(sizeof(set_alloc >) == 24, ""); +static_assert(sizeof(set_alloc >) == 24, ""); +static_assert(sizeof(set_alloc >) == 40, ""); +static_assert(sizeof(set_alloc >) == 6, ""); +static_assert(sizeof(set_alloc >) == 8, ""); + +static_assert(sizeof(set_alloc >) == 24, ""); +static_assert(sizeof(set_alloc >) == 24, ""); +static_assert(sizeof(set_alloc >) == 40, ""); +static_assert(sizeof(set_alloc >) == 6, ""); +static_assert(sizeof(set_alloc >) == 8, ""); + +static_assert(TEST_ALIGNOF(set_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 2, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 2, ""); + +static_assert(TEST_ALIGNOF(set_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 2, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 2, ""); + +struct TEST_ALIGNAS(32) AlignedLess {}; + +// This part of the ABI has been broken between LLVM 19 and LLVM 20. +static_assert(sizeof(std::set) == 64, ""); +static_assert(TEST_ALIGNOF(std::set) == 32, ""); + +#elif __SIZE_WIDTH__ == 32 +static_assert(sizeof(user_struct) == 16, ""); +static_assert(TEST_ALIGNOF(user_struct) == 4, ""); + +static_assert(sizeof(set_alloc >) == 12, ""); +static_assert(sizeof(set_alloc >) == 12, ""); +static_assert(sizeof(set_alloc >) == 24, ""); +static_assert(sizeof(set_alloc >) == 6, ""); +static_assert(sizeof(set_alloc >) == 8, ""); + +static_assert(sizeof(set_alloc >) == 12, ""); +static_assert(sizeof(set_alloc >) == 12, ""); +static_assert(sizeof(set_alloc >) == 24, ""); +static_assert(sizeof(set_alloc >) == 6, ""); +static_assert(sizeof(set_alloc >) == 8, ""); + +static_assert(TEST_ALIGNOF(set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 2, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 2, ""); + +static_assert(TEST_ALIGNOF(set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 2, ""); +static_assert(TEST_ALIGNOF(set_alloc >) == 2, ""); + +struct TEST_ALIGNAS(32) AlignedLess {}; + +static_assert(sizeof(std::set) == 64); +static_assert(TEST_ALIGNOF(std::set) == 32); + +#else +# error std::size_t has an unexpected size +#endif diff --git a/libcxx/test/libcxx/containers/associative/unord.map/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/associative/unord.map/abi.compile.pass.cpp index 55d42a8d017e1..0476872487036 100644 --- a/libcxx/test/libcxx/containers/associative/unord.map/abi.compile.pass.cpp +++ b/libcxx/test/libcxx/containers/associative/unord.map/abi.compile.pass.cpp @@ -66,10 +66,36 @@ class final_small_iter_allocator final { friend bool operator!=(final_small_iter_allocator, final_small_iter_allocator) { return false; } }; +struct allocator_base {}; + +// Make sure that types with a common base type don't get broken. See https://llvm.org/PR154146 +template +struct common_base_allocator : allocator_base { + using value_type = T; + + common_base_allocator() TEST_NOEXCEPT {} + + template + common_base_allocator(common_base_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(common_base_allocator, common_base_allocator) { return true; } + friend bool operator!=(common_base_allocator, common_base_allocator) { return false; } +}; + template using unordered_map_alloc = std::unordered_map, std::equal_to, Alloc>; +struct user_struct { + unordered_map_alloc > > v; + [[no_unique_address]] common_base_allocator a; +}; + #if __SIZE_WIDTH__ == 64 +static_assert(sizeof(user_struct) == 48, ""); +static_assert(TEST_ALIGNOF(user_struct) == 8, ""); static_assert(sizeof(unordered_map_alloc > >) == 40, ""); static_assert(sizeof(unordered_map_alloc > >) == 40, ""); @@ -104,6 +130,8 @@ static_assert(sizeof(std::unordered_map static_assert(TEST_ALIGNOF(std::unordered_map) == 32, ""); #elif __SIZE_WIDTH__ == 32 +static_assert(sizeof(user_struct) == 24, ""); +static_assert(TEST_ALIGNOF(user_struct) == 4, ""); static_assert(sizeof(unordered_map_alloc > >) == 20, ""); static_assert(sizeof(unordered_map_alloc > >) == 20, ""); diff --git a/libcxx/test/libcxx/containers/associative/unord.set/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/associative/unord.set/abi.compile.pass.cpp index bee2012bbea29..e9d88a126de6c 100644 --- a/libcxx/test/libcxx/containers/associative/unord.set/abi.compile.pass.cpp +++ b/libcxx/test/libcxx/containers/associative/unord.set/abi.compile.pass.cpp @@ -66,10 +66,36 @@ class final_small_iter_allocator final { friend bool operator!=(final_small_iter_allocator, final_small_iter_allocator) { return false; } }; +struct allocator_base {}; + +// Make sure that types with a common base type don't get broken. See https://llvm.org/PR154146 +template +struct common_base_allocator : allocator_base { + using value_type = T; + + common_base_allocator() TEST_NOEXCEPT {} + + template + common_base_allocator(common_base_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(common_base_allocator, common_base_allocator) { return true; } + friend bool operator!=(common_base_allocator, common_base_allocator) { return false; } +}; + template using unordered_set_alloc = std::unordered_set, std::equal_to, Alloc>; +struct user_struct { + unordered_set_alloc > v; + [[no_unique_address]] common_base_allocator a; +}; + #if __SIZE_WIDTH__ == 64 +static_assert(sizeof(user_struct) == 48, ""); +static_assert(TEST_ALIGNOF(user_struct) == 8, ""); static_assert(sizeof(unordered_set_alloc >) == 40, ""); static_assert(sizeof(unordered_set_alloc >) == 40, ""); @@ -103,6 +129,8 @@ static_assert(sizeof(std::unordered_set) == static_assert(TEST_ALIGNOF(std::unordered_set) == 32, ""); #elif __SIZE_WIDTH__ == 32 +static_assert(sizeof(user_struct) == 24, ""); +static_assert(TEST_ALIGNOF(user_struct) == 4, ""); static_assert(sizeof(unordered_set_alloc >) == 20, ""); static_assert(sizeof(unordered_set_alloc >) == 20, ""); diff --git a/libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp index 30586d8b2422c..38f957f416c87 100644 --- a/libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp +++ b/libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp @@ -8,6 +8,8 @@ // UNSUPPORTED: libcpp-abi-no-compressed-pair-padding +// XFAIL: FROZEN-CXX03-HEADERS-FIXME + #include #include @@ -60,6 +62,25 @@ class final_small_iter_allocator final { friend bool operator!=(final_small_iter_allocator, final_small_iter_allocator) { return false; } }; +struct allocator_base {}; + +// Make sure that types with a common base type don't get broken. See https://llvm.org/PR154146 +template +struct common_base_allocator : allocator_base { + using value_type = T; + + common_base_allocator() TEST_NOEXCEPT {} + + template + common_base_allocator(common_base_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(common_base_allocator, common_base_allocator) { return true; } + friend bool operator!=(common_base_allocator, common_base_allocator) { return false; } +}; + #if __SIZE_WIDTH__ == 64 static_assert(sizeof(std::deque) == 48, ""); @@ -67,24 +88,28 @@ static_assert(sizeof(std::deque >) == 48, ""); static_assert(sizeof(std::deque >) == 80, ""); static_assert(sizeof(std::deque >) == 12, ""); static_assert(sizeof(std::deque >) == 16, ""); +static_assert(sizeof(std::deque >) == 56, ""); static_assert(sizeof(std::deque) == 48, ""); static_assert(sizeof(std::deque >) == 48, ""); static_assert(sizeof(std::deque >) == 80, ""); static_assert(sizeof(std::deque >) == 12, ""); static_assert(sizeof(std::deque >) == 16, ""); +static_assert(sizeof(std::deque >) == 56, ""); static_assert(TEST_ALIGNOF(std::deque) == 8, ""); static_assert(TEST_ALIGNOF(std::deque >) == 8, ""); static_assert(TEST_ALIGNOF(std::deque >) == 8, ""); static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); +static_assert(TEST_ALIGNOF(std::deque >) == 8, ""); static_assert(TEST_ALIGNOF(std::deque) == 8, ""); static_assert(TEST_ALIGNOF(std::deque >) == 8, ""); static_assert(TEST_ALIGNOF(std::deque >) == 8, ""); static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); +static_assert(TEST_ALIGNOF(std::deque >) == 8, ""); #elif __SIZE_WIDTH__ == 32 @@ -93,24 +118,28 @@ static_assert(sizeof(std::deque >) == 24, ""); static_assert(sizeof(std::deque >) == 48, ""); static_assert(sizeof(std::deque >) == 12, ""); static_assert(sizeof(std::deque >) == 16, ""); +static_assert(sizeof(std::deque >) == 28, ""); static_assert(sizeof(std::deque) == 24, ""); static_assert(sizeof(std::deque >) == 24, ""); static_assert(sizeof(std::deque >) == 48, ""); static_assert(sizeof(std::deque >) == 12, ""); static_assert(sizeof(std::deque >) == 16, ""); +static_assert(sizeof(std::deque >) == 28, ""); static_assert(TEST_ALIGNOF(std::deque) == 4, ""); static_assert(TEST_ALIGNOF(std::deque >) == 4, ""); static_assert(TEST_ALIGNOF(std::deque >) == 4, ""); static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); +static_assert(TEST_ALIGNOF(std::deque >) == 4, ""); static_assert(TEST_ALIGNOF(std::deque) == 4, ""); static_assert(TEST_ALIGNOF(std::deque >) == 4, ""); static_assert(TEST_ALIGNOF(std::deque >) == 4, ""); static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); static_assert(TEST_ALIGNOF(std::deque >) == 2, ""); +static_assert(TEST_ALIGNOF(std::deque >) == 4, ""); #else # error std::size_t has an unexpected size diff --git a/libcxx/test/libcxx/containers/sequences/forwardlist/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/forwardlist/abi.compile.pass.cpp new file mode 100644 index 0000000000000..cb500f9c4d61b --- /dev/null +++ b/libcxx/test/libcxx/containers/sequences/forwardlist/abi.compile.pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include +#include + +#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" + +template +class small_pointer { + std::uint16_t offset; +}; + +template +class small_iter_allocator { +public: + using value_type = T; + using pointer = small_pointer; + using size_type = std::int16_t; + using difference_type = std::int16_t; + + small_iter_allocator() TEST_NOEXCEPT {} + + template + small_iter_allocator(small_iter_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; } + friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; } +}; + +struct allocator_base {}; + +// Make sure that types with a common base type don't get broken. See https://llvm.org/PR154146 +template +struct common_base_allocator : allocator_base { + using value_type = T; + + common_base_allocator() TEST_NOEXCEPT {} + + template + common_base_allocator(common_base_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(common_base_allocator, common_base_allocator) { return true; } + friend bool operator!=(common_base_allocator, common_base_allocator) { return false; } +}; + +struct user_struct { + std::forward_list > v; + [[no_unique_address]] common_base_allocator a; +}; + +#if __SIZE_WIDTH__ == 64 +static_assert(sizeof(user_struct) == 16, ""); +static_assert(TEST_ALIGNOF(user_struct) == 8, ""); + +static_assert(sizeof(std::forward_list) == 8, ""); +static_assert(sizeof(std::forward_list >) == 8, ""); +static_assert(sizeof(std::forward_list >) == 24, ""); +static_assert(sizeof(std::forward_list >) == 2, ""); + +static_assert(sizeof(std::forward_list) == 8, ""); +static_assert(sizeof(std::forward_list >) == 8, ""); +static_assert(sizeof(std::forward_list >) == 24, ""); +static_assert(sizeof(std::forward_list >) == 2, ""); + +static_assert(TEST_ALIGNOF(std::forward_list) == 8, ""); +static_assert(TEST_ALIGNOF(std::forward_list >) == 8, ""); +static_assert(TEST_ALIGNOF(std::forward_list >) == 8, ""); +static_assert(TEST_ALIGNOF(std::forward_list >) == 2, ""); + +static_assert(TEST_ALIGNOF(std::forward_list) == 8, ""); +static_assert(TEST_ALIGNOF(std::forward_list >) == 8, ""); +static_assert(TEST_ALIGNOF(std::forward_list >) == 8, ""); +static_assert(TEST_ALIGNOF(std::forward_list >) == 2, ""); + +#elif __SIZE_WIDTH__ == 32 +static_assert(sizeof(user_struct) == 8, ""); +static_assert(TEST_ALIGNOF(user_struct) == 4, ""); + +static_assert(sizeof(std::forward_list) == 4, ""); +static_assert(sizeof(std::forward_list >) == 4, ""); +static_assert(sizeof(std::forward_list >) == 16, ""); +static_assert(sizeof(std::forward_list >) == 2, ""); + +static_assert(sizeof(std::forward_list) == 4, ""); +static_assert(sizeof(std::forward_list >) == 4, ""); +static_assert(sizeof(std::forward_list >) == 16, ""); +static_assert(sizeof(std::forward_list >) == 2, ""); + +static_assert(TEST_ALIGNOF(std::forward_list) == 4, ""); +static_assert(TEST_ALIGNOF(std::forward_list >) == 4, ""); +static_assert(TEST_ALIGNOF(std::forward_list >) == 4, ""); +static_assert(TEST_ALIGNOF(std::forward_list >) == 2, ""); + +static_assert(TEST_ALIGNOF(std::forward_list) == 4, ""); +static_assert(TEST_ALIGNOF(std::forward_list >) == 4, ""); +static_assert(TEST_ALIGNOF(std::forward_list >) == 4, ""); +static_assert(TEST_ALIGNOF(std::forward_list >) == 2, ""); + +#else +# error std::size_t has an unexpected size +#endif diff --git a/libcxx/test/libcxx/containers/sequences/list/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/list/abi.compile.pass.cpp index a16ae1d527921..1737497ab159e 100644 --- a/libcxx/test/libcxx/containers/sequences/list/abi.compile.pass.cpp +++ b/libcxx/test/libcxx/containers/sequences/list/abi.compile.pass.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +// XFAIL: FROZEN-CXX03-HEADERS-FIXME + #include #include @@ -38,7 +40,33 @@ class small_iter_allocator { friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; } }; +struct allocator_base {}; + +// Make sure that types with a common base type don't get broken. See https://llvm.org/PR154146 +template +struct common_base_allocator : allocator_base { + using value_type = T; + + common_base_allocator() TEST_NOEXCEPT {} + + template + common_base_allocator(common_base_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(common_base_allocator, common_base_allocator) { return true; } + friend bool operator!=(common_base_allocator, common_base_allocator) { return false; } +}; + +struct user_struct { + std::list > v; + [[no_unique_address]] common_base_allocator a; +}; + #if __SIZE_WIDTH__ == 64 +static_assert(sizeof(user_struct) == 32, ""); +static_assert(TEST_ALIGNOF(user_struct) == 8, ""); static_assert(sizeof(std::list) == 24, ""); static_assert(sizeof(std::list >) == 24, ""); @@ -61,6 +89,8 @@ static_assert(TEST_ALIGNOF(std::list >) == 8, ""); static_assert(TEST_ALIGNOF(std::list >) == 2, ""); #elif __SIZE_WIDTH__ == 32 +static_assert(sizeof(user_struct) == 16, ""); +static_assert(TEST_ALIGNOF(user_struct) == 4, ""); static_assert(sizeof(std::list) == 12, ""); static_assert(sizeof(std::list >) == 12, ""); diff --git a/libcxx/test/libcxx/containers/sequences/vector.bool/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/vector.bool/abi.compile.pass.cpp index cc6b0d94e7daf..97e09ab4ca868 100644 --- a/libcxx/test/libcxx/containers/sequences/vector.bool/abi.compile.pass.cpp +++ b/libcxx/test/libcxx/containers/sequences/vector.bool/abi.compile.pass.cpp @@ -8,6 +8,8 @@ // UNSUPPORTED: libcpp-abi-no-compressed-pair-padding +// XFAIL: FROZEN-CXX03-HEADERS-FIXME + #include #include @@ -40,7 +42,33 @@ class small_iter_allocator { friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; } }; +struct allocator_base {}; + +// Make sure that types with a common base type don't get broken. See https://llvm.org/PR154146 +template +struct common_base_allocator : allocator_base { + using value_type = T; + + common_base_allocator() TEST_NOEXCEPT {} + + template + common_base_allocator(common_base_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(common_base_allocator, common_base_allocator) { return true; } + friend bool operator!=(common_base_allocator, common_base_allocator) { return false; } +}; + +struct user_struct { + std::vector > v; + [[no_unique_address]] common_base_allocator a; +}; + #if __SIZE_WIDTH__ == 64 +static_assert(sizeof(user_struct) == 32, ""); +static_assert(TEST_ALIGNOF(user_struct) == 8, ""); static_assert(sizeof(std::vector) == 24, ""); static_assert(sizeof(std::vector >) == 24, ""); @@ -53,6 +81,8 @@ static_assert(TEST_ALIGNOF(std::vector >) == 8, ""); static_assert(TEST_ALIGNOF(std::vector >) == 2, ""); #elif __SIZE_WIDTH__ == 32 +static_assert(sizeof(user_struct) == 16, ""); +static_assert(TEST_ALIGNOF(user_struct) == 4, ""); static_assert(sizeof(std::vector) == 12, ""); static_assert(sizeof(std::vector >) == 12, ""); diff --git a/libcxx/test/libcxx/containers/sequences/vector/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/vector/abi.compile.pass.cpp index 57684951c8e8e..879e143510752 100644 --- a/libcxx/test/libcxx/containers/sequences/vector/abi.compile.pass.cpp +++ b/libcxx/test/libcxx/containers/sequences/vector/abi.compile.pass.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +// XFAIL: FROZEN-CXX03-HEADERS-FIXME + #include #include @@ -46,7 +48,33 @@ class small_iter_allocator { friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; } }; +struct allocator_base {}; + +// Make sure that types with a common base type don't get broken. See https://llvm.org/PR154146 +template +struct common_base_allocator : allocator_base { + using value_type = T; + + common_base_allocator() TEST_NOEXCEPT {} + + template + common_base_allocator(common_base_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(common_base_allocator, common_base_allocator) { return true; } + friend bool operator!=(common_base_allocator, common_base_allocator) { return false; } +}; + +struct user_struct { + std::vector > v; + [[no_unique_address]] common_base_allocator a; +}; + #if __SIZE_WIDTH__ == 64 +static_assert(sizeof(user_struct) == 32, ""); +static_assert(TEST_ALIGNOF(user_struct) == 8, ""); static_assert(sizeof(std::vector) == 24, ""); static_assert(sizeof(std::vector >) == 24, ""); @@ -69,6 +97,8 @@ static_assert(TEST_ALIGNOF(std::vector >) == 8, ""); static_assert(TEST_ALIGNOF(std::vector >) == 2, ""); #elif __SIZE_WIDTH__ == 32 +static_assert(sizeof(user_struct) == 16, ""); +static_assert(TEST_ALIGNOF(user_struct) == 4, ""); static_assert(sizeof(std::vector) == 12, ""); static_assert(sizeof(std::vector >) == 12, ""); diff --git a/libcxx/test/libcxx/containers/strings/basic.string/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/strings/basic.string/abi.compile.pass.cpp new file mode 100644 index 0000000000000..cf802e214d07c --- /dev/null +++ b/libcxx/test/libcxx/containers/strings/basic.string/abi.compile.pass.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include +#include + +#include "min_allocator.h" +#include "test_allocator.h" +#include "test_macros.h" + +template +class small_pointer { +public: + using value_type = T; + using difference_type = std::int16_t; + using pointer = small_pointer; + using reference = T&; + using iterator_category = std::random_access_iterator_tag; + +private: + std::uint16_t offset; +}; + +template +class small_iter_allocator { +public: + using value_type = T; + using pointer = small_pointer; + using size_type = std::int16_t; + using difference_type = std::int16_t; + + small_iter_allocator() TEST_NOEXCEPT {} + + template + small_iter_allocator(small_iter_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; } + friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; } +}; + +struct allocator_base {}; + +// Make sure that types with a common base type don't get broken. See https://llvm.org/PR154146 +template +struct common_base_allocator : allocator_base { + using value_type = T; + + common_base_allocator() TEST_NOEXCEPT {} + + template + common_base_allocator(common_base_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n); + void deallocate(T* p, std::size_t); + + friend bool operator==(common_base_allocator, common_base_allocator) { return true; } + friend bool operator!=(common_base_allocator, common_base_allocator) { return false; } +}; + +template +using string_alloc = std::basic_string, Alloc>; + +struct user_struct { + string_alloc > v; + [[no_unique_address]] common_base_allocator a; +}; + +#if __SIZE_WIDTH__ == 64 +static_assert(sizeof(user_struct) == 32, ""); +static_assert(TEST_ALIGNOF(user_struct) == 8, ""); + +static_assert(sizeof(string_alloc >) == 24, ""); +static_assert(sizeof(string_alloc >) == 24, ""); +static_assert(sizeof(string_alloc >) == 32, ""); +static_assert(sizeof(string_alloc >) == 6, ""); + +static_assert(TEST_ALIGNOF(string_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(string_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(string_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(string_alloc >) == 2, ""); + +#elif __SIZE_WIDTH__ == 32 +static_assert(sizeof(user_struct) == 16, ""); +static_assert(TEST_ALIGNOF(user_struct) == 4, ""); + +static_assert(sizeof(string_alloc >) == 12, ""); +static_assert(sizeof(string_alloc >) == 12, ""); +static_assert(sizeof(string_alloc >) == 24, ""); +static_assert(sizeof(string_alloc >) == 6, ""); + +static_assert(TEST_ALIGNOF(string_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(string_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(string_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(string_alloc >) == 2, ""); + +#else +# error std::size_t has an unexpected size +#endif