From 1c478d38edf6e2aca73e3d4c342b14e8a1c723e7 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Tue, 2 Sep 2025 09:24:50 +0200 Subject: [PATCH] [libc++] Add ABI tests for introducing _LIBCPP_COMPRESSED_ELEMENT --- .../associative/map/abi.compile.pass.cpp | 28 +++- .../unord.map/abi.compile.pass.cpp | 54 +++++++- .../utilities/tuple/abi.compile.pass.cpp | 124 ++++++++++++++++++ 3 files changed, 197 insertions(+), 9 deletions(-) create mode 100644 libcxx/test/libcxx/utilities/tuple/abi.compile.pass.cpp diff --git a/libcxx/test/libcxx/containers/associative/map/abi.compile.pass.cpp b/libcxx/test/libcxx/containers/associative/map/abi.compile.pass.cpp index e0598b4ff1746..ca4e9747bc490 100644 --- a/libcxx/test/libcxx/containers/associative/map/abi.compile.pass.cpp +++ b/libcxx/test/libcxx/containers/associative/map/abi.compile.pass.cpp @@ -87,6 +87,18 @@ struct user_struct { [[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 @@ -120,10 +132,13 @@ 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(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 @@ -158,10 +173,13 @@ 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(sizeof(std::map) == 16, ""); +static_assert(sizeof(std::map) == 20, ""); -static_assert(sizeof(std::map) == 64); -static_assert(TEST_ALIGNOF(std::map) == 32); +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 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 60c3e5bf31b00..39fc9fe94a83c 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 @@ -91,6 +91,33 @@ struct user_struct { [[no_unique_address]] common_base_allocator a; }; +struct TEST_ALIGNAS(32) AlignedHash {}; +struct FinalHash final {}; +struct NonEmptyHash final { + int i; + char c; +}; +struct UnalignedEqualTo {}; +struct FinalEqualTo final {}; +struct NonEmptyEqualTo { + int i; + char c; +}; + +static_assert(std::is_empty, std::hash, int> >::value, + ""); +static_assert(std::is_empty, AlignedHash, int> >::value, ""); +static_assert(!std::is_empty, FinalHash, int> >::value, ""); +static_assert(!std::is_empty, NonEmptyHash, int> >::value, + ""); + +static_assert(std::is_empty, std::hash, int> >::value, + ""); +static_assert(std::is_empty, AlignedHash, int> >::value, ""); +static_assert(!std::is_empty, FinalHash, int> >::value, ""); +static_assert(!std::is_empty, NonEmptyHash, int> >::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 @@ -125,8 +152,20 @@ static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); -struct TEST_ALIGNAS(32) AlignedHash {}; -struct UnalignedEqualTo {}; +#ifdef TEST_COMPILER_GCC +static_assert(sizeof(std::unordered_map) == 40, ""); +#else +static_assert(sizeof(std::unordered_map) == 48, ""); +#endif +static_assert(sizeof(std::unordered_map) == 48, ""); +static_assert(sizeof(std::unordered_map) == 48, ""); +static_assert(sizeof(std::unordered_map) == 56, ""); + +static_assert(TEST_ALIGNOF(std::unordered_map) == 8, ""); +static_assert(TEST_ALIGNOF(std::unordered_map) == 8, ""); +static_assert(TEST_ALIGNOF(std::unordered_map) == 8, ""); +static_assert(TEST_ALIGNOF(std::unordered_map) == 8, ""); + // 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(std::unordered_map) == 64, ""); @@ -169,8 +208,15 @@ static_assert(TEST_ALIGNOF(unordered_map_alloc > >) == 4, ""); -struct TEST_ALIGNAS(32) AlignedHash {}; -struct UnalignedEqualTo {}; +static_assert(sizeof(std::unordered_map) == 24, ""); +static_assert(sizeof(std::unordered_map) == 24, ""); +static_assert(sizeof(std::unordered_map) == 28, ""); +static_assert(sizeof(std::unordered_map) == 32, ""); + +static_assert(TEST_ALIGNOF(std::unordered_map) == 4, ""); +static_assert(TEST_ALIGNOF(std::unordered_map) == 4, ""); +static_assert(TEST_ALIGNOF(std::unordered_map) == 4, ""); +static_assert(TEST_ALIGNOF(std::unordered_map) == 4, ""); // 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 diff --git a/libcxx/test/libcxx/utilities/tuple/abi.compile.pass.cpp b/libcxx/test/libcxx/utilities/tuple/abi.compile.pass.cpp new file mode 100644 index 0000000000000..467214a0779db --- /dev/null +++ b/libcxx/test/libcxx/utilities/tuple/abi.compile.pass.cpp @@ -0,0 +1,124 @@ +//===----------------------------------------------------------------------===// +// +// 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: c++03 + +// UNSUPPORTED: libcpp-abi-no-compressed-pair-padding + +#include +#include + +#include "test_macros.h" + +struct S {}; + +struct Final final {}; + +struct NonEmpty { + int i; + char c; +}; + +struct NonEmptyFinal final { + int i; + char c; +}; + +struct TEST_ALIGNAS(16) Overaligned {}; +struct TEST_ALIGNAS(16) OveralignedFinal final {}; + +static_assert(std::is_empty>::value, ""); +static_assert(!std::is_empty>::value, ""); +static_assert(!std::is_empty>::value, ""); +static_assert(!std::is_empty>::value, ""); +static_assert(!std::is_empty>::value, ""); +static_assert(!std::is_empty>::value, ""); +static_assert(!std::is_empty>::value, ""); +static_assert(!std::is_empty>::value, ""); +static_assert(!std::is_empty>::value, ""); + +static_assert(sizeof(std::tuple) == 1, ""); +static_assert(sizeof(std::tuple) == sizeof(void*), ""); +static_assert(sizeof(std::tuple) == sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 1, ""); +static_assert(sizeof(std::tuple) == 8, ""); +static_assert(sizeof(std::tuple) == 8, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 16, ""); + +static_assert(sizeof(std::tuple) == 2, ""); +static_assert(sizeof(std::tuple) == sizeof(void*), ""); +static_assert(sizeof(std::tuple) == sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 1, ""); +static_assert(sizeof(std::tuple) == 8, ""); +static_assert(sizeof(std::tuple) == 8, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 16, ""); + +static_assert(sizeof(std::tuple) == sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 2 * sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 2 * sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 2 * sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 8 + sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 8 + sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 32, ""); + +static_assert(sizeof(std::tuple) == sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 2 * sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 2 * sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 2 * sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 8 + sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 8 + sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 32, ""); + +static_assert(sizeof(std::tuple) == 1, ""); +static_assert(sizeof(std::tuple) == 2 * sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 2 * sizeof(void*), ""); +static_assert(sizeof(std::tuple) == 2, ""); +static_assert(sizeof(std::tuple) == 12, ""); +static_assert(sizeof(std::tuple) == 12, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 32, ""); + +static_assert(sizeof(std::tuple) == 8, ""); +static_assert(sizeof(std::tuple) == sizeof(void*) + 8, ""); +static_assert(sizeof(std::tuple) == sizeof(void*) + 8, ""); +static_assert(sizeof(std::tuple) == 12, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 32, ""); + +static_assert(sizeof(std::tuple) == 8, ""); +static_assert(sizeof(std::tuple) == sizeof(void*) + 8, ""); +static_assert(sizeof(std::tuple) == sizeof(void*) + 8, ""); +static_assert(sizeof(std::tuple) == 12, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 32, ""); + +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 32, ""); +static_assert(sizeof(std::tuple) == 16, ""); + +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 32, ""); +static_assert(sizeof(std::tuple) == 32, ""); +static_assert(sizeof(std::tuple) == 32, ""); +static_assert(sizeof(std::tuple) == 32, ""); +static_assert(sizeof(std::tuple) == 32, ""); +static_assert(sizeof(std::tuple) == 16, ""); +static_assert(sizeof(std::tuple) == 32, "");