//===----------------------------------------------------------------------===// // // 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 #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; }; struct TEST_ALIGNAS(32) AlignedLess {}; struct FinalLess final {}; struct NonEmptyLess { int i; char c; }; static_assert(std::is_empty, std::less > >::value, ""); static_assert(std::is_empty, AlignedLess> >::value, ""); static_assert(!std::is_empty, FinalLess> >::value, ""); static_assert(!std::is_empty, NonEmptyLess> >::value, ""); #if __SIZE_WIDTH__ == 64 // TODO: Fix the ABI for GCC as well once https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121637 is fixed # ifdef TEST_COMPILER_GCC static_assert(sizeof(user_struct) == 32, ""); # else static_assert(sizeof(user_struct) == 24, ""); # endif 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, ""); static_assert(sizeof(std::map) == 64, ""); static_assert(sizeof(std::map) == 32, ""); static_assert(sizeof(std::map) == 32, ""); static_assert(TEST_ALIGNOF(std::map) == 32, ""); static_assert(TEST_ALIGNOF(std::map) == 8, ""); static_assert(TEST_ALIGNOF(std::map) == 8, ""); #elif __SIZE_WIDTH__ == 32 // TODO: Fix the ABI for GCC as well once https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121637 is fixed # ifdef TEST_COMPILER_GCC static_assert(sizeof(user_struct) == 16, ""); # else static_assert(sizeof(user_struct) == 12, ""); # endif 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, ""); static_assert(sizeof(std::map) == 64, ""); static_assert(sizeof(std::map) == 16, ""); static_assert(sizeof(std::map) == 20, ""); static_assert(TEST_ALIGNOF(std::map) == 32, ""); static_assert(TEST_ALIGNOF(std::map) == 4, ""); static_assert(TEST_ALIGNOF(std::map) == 4, ""); #else # error std::size_t has an unexpected size #endif