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 new file mode 100644 index 00000000000000..c8e5ba0ec899eb --- /dev/null +++ b/libcxx/test/libcxx/containers/associative/unord.map/abi.compile.pass.cpp @@ -0,0 +1,134 @@ +//===----------------------------------------------------------------------===// +// +// 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-has-abi-fix-unordered-container-size-type + +#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; } +}; + +template +using unordered_map_alloc = std::unordered_map, std::equal_to, Alloc>; + +#if __SIZE_WIDTH__ == 64 + +static_assert(sizeof(unordered_map_alloc > >) == 40, ""); +static_assert(sizeof(unordered_map_alloc > >) == 40, ""); +static_assert(sizeof(unordered_map_alloc > >) == 64, ""); +static_assert(sizeof(unordered_map_alloc > >) == 12, ""); +static_assert(sizeof(unordered_map_alloc > >) == 16, ""); + +static_assert(sizeof(unordered_map_alloc > >) == 40, ""); +static_assert(sizeof(unordered_map_alloc > >) == 40, ""); +static_assert(sizeof(unordered_map_alloc > >) == 64, ""); +static_assert(sizeof(unordered_map_alloc > >) == 12, ""); +static_assert(sizeof(unordered_map_alloc > >) == 16, ""); + +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 8, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 8, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 8, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); + +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 8, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 8, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 8, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, + ""); + +struct TEST_ALIGNAS(32) AlignedHash {}; +struct UnalignedEqualTo {}; + +static_assert(sizeof(std::unordered_map) == 96, ""); +static_assert(TEST_ALIGNOF(std::unordered_map) == 32, ""); + +#elif __SIZE_WIDTH__ == 32 + +static_assert(sizeof(unordered_map_alloc > >) == 20, ""); +static_assert(sizeof(unordered_map_alloc > >) == 20, ""); +static_assert(sizeof(unordered_map_alloc > >) == 44, ""); +static_assert(sizeof(unordered_map_alloc > >) == 12, ""); +static_assert(sizeof(unordered_map_alloc > >) == 16, ""); + +static_assert(sizeof(unordered_map_alloc > >) == 20, ""); +static_assert(sizeof(unordered_map_alloc > >) == 20, ""); +static_assert(sizeof(unordered_map_alloc > >) == 44, ""); +static_assert(sizeof(unordered_map_alloc > >) == 12, ""); +static_assert(sizeof(unordered_map_alloc > >) == 16, ""); + +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); + +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, + ""); + +struct TEST_ALIGNAS(32) AlignedHash {}; +struct UnalignedEqualTo {}; + +static_assert(sizeof(std::unordered_map) == 96); +static_assert(TEST_ALIGNOF(std::unordered_map) == 32); + +#else +# error std::size_t has an unexpected size +#endif 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 new file mode 100644 index 00000000000000..359e248ff7a4f0 --- /dev/null +++ b/libcxx/test/libcxx/containers/associative/unord.set/abi.compile.pass.cpp @@ -0,0 +1,132 @@ +//===----------------------------------------------------------------------===// +// +// 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-has-abi-fix-unordered-container-size-type + +#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; } +}; + +template +using unordered_set_alloc = std::unordered_set, std::equal_to, Alloc>; + +#if __SIZE_WIDTH__ == 64 + +static_assert(sizeof(unordered_set_alloc >) == 40, ""); +static_assert(sizeof(unordered_set_alloc >) == 40, ""); +static_assert(sizeof(unordered_set_alloc >) == 64, ""); +static_assert(sizeof(unordered_set_alloc >) == 12, ""); +static_assert(sizeof(unordered_set_alloc >) == 16, ""); + +static_assert(sizeof(unordered_set_alloc >) == 40, ""); +static_assert(sizeof(unordered_set_alloc >) == 40, ""); +static_assert(sizeof(unordered_set_alloc >) == 64, ""); +static_assert(sizeof(unordered_set_alloc >) == 12, ""); +static_assert(sizeof(unordered_set_alloc >) == 16, ""); + +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); + +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 8, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); + +struct TEST_ALIGNAS(32) AlignedHash {}; +struct UnalignedEqualTo {}; + +static_assert(sizeof(std::unordered_set) == 96, ""); +static_assert(TEST_ALIGNOF(std::unordered_set) == 32, ""); + +#elif __SIZE_WIDTH__ == 32 + +static_assert(sizeof(unordered_set_alloc >) == 20, ""); +static_assert(sizeof(unordered_set_alloc >) == 20, ""); +static_assert(sizeof(unordered_set_alloc >) == 44, ""); +static_assert(sizeof(unordered_set_alloc >) == 12, ""); +static_assert(sizeof(unordered_set_alloc >) == 16, ""); + +static_assert(sizeof(unordered_set_alloc >) == 20, ""); +static_assert(sizeof(unordered_set_alloc >) == 20, ""); +static_assert(sizeof(unordered_set_alloc >) == 44, ""); +static_assert(sizeof(unordered_set_alloc >) == 12, ""); +static_assert(sizeof(unordered_set_alloc >) == 16, ""); + +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); + +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); +static_assert(TEST_ALIGNOF(unordered_set_alloc >) == 4, ""); + +struct TEST_ALIGNAS(32) AlignedHash {}; +struct UnalignedEqualTo {}; + +static_assert(sizeof(std::unordered_set) == 96); +static_assert(TEST_ALIGNOF(std::unordered_set) == 32); + +#else +# error std::size_t has an unexpected size +#endif diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py index 6857a28eb32995..2cd04124a6ca5e 100644 --- a/libcxx/utils/libcxx/test/features.py +++ b/libcxx/utils/libcxx/test/features.py @@ -374,6 +374,7 @@ def _mingwSupportsModules(cfg): "_LIBCPP_ABI_BOUNDED_ITERATORS": "libcpp-has-abi-bounded-iterators", "_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING": "libcpp-has-abi-bounded-iterators-in-string", "_LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR": "libcpp-has-abi-bounded-iterators-in-vector", + "_LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE": "libcpp-has-abi-fix-unordered-container-size-type", "_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR": "libcpp-deprecated-abi-disable-pair-trivial-copy-ctor", "_LIBCPP_HAS_NO_FILESYSTEM": "no-filesystem", "_LIBCPP_HAS_NO_RANDOM_DEVICE": "no-random-device",