-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[libc++] Add tests for the ABI break introduced by switching to _LIBCPP_COMPRESSED_PAIR #154559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
161 changes: 161 additions & 0 deletions
161
libcxx/test/libcxx/containers/associative/map/abi.compile.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <cstdint> | ||
| #include <map> | ||
|
|
||
| #include "min_allocator.h" | ||
| #include "test_allocator.h" | ||
| #include "test_macros.h" | ||
|
|
||
| template <class T> | ||
| class small_pointer { | ||
| std::uint16_t offset; | ||
| }; | ||
|
|
||
| template <class T> | ||
| class small_iter_allocator { | ||
| public: | ||
| using value_type = T; | ||
| using pointer = small_pointer<T>; | ||
| using size_type = std::uint16_t; | ||
| using difference_type = std::int16_t; | ||
|
|
||
| small_iter_allocator() TEST_NOEXCEPT {} | ||
|
|
||
| template <class U> | ||
| small_iter_allocator(small_iter_allocator<U>) 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 T> | ||
| class final_small_iter_allocator final { | ||
| public: | ||
| using value_type = T; | ||
| using pointer = small_pointer<T>; | ||
| using size_type = std::uint16_t; | ||
| using difference_type = std::int16_t; | ||
|
|
||
| final_small_iter_allocator() TEST_NOEXCEPT {} | ||
|
|
||
| template <class U> | ||
| final_small_iter_allocator(final_small_iter_allocator<U>) 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 <class T> | ||
| struct common_base_allocator : allocator_base { | ||
| using value_type = T; | ||
|
|
||
| common_base_allocator() TEST_NOEXCEPT {} | ||
|
|
||
| template <class U> | ||
| common_base_allocator(common_base_allocator<U>) 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 <class T, class Alloc> | ||
| using map_alloc = std::map<T, T, std::less<T>, Alloc>; | ||
|
|
||
| struct user_struct { | ||
| map_alloc<int, common_base_allocator<std::pair<const int, int> > > v; | ||
| [[no_unique_address]] common_base_allocator<int> a; | ||
| }; | ||
|
|
||
| #if __SIZE_WIDTH__ == 64 | ||
| static_assert(sizeof(user_struct) == 32, ""); | ||
| static_assert(TEST_ALIGNOF(user_struct) == 8, ""); | ||
|
|
||
| static_assert(sizeof(map_alloc<int, std::allocator<std::pair<const int, int> > >) == 24, ""); | ||
| static_assert(sizeof(map_alloc<int, min_allocator<std::pair<const int, int> > >) == 24, ""); | ||
| static_assert(sizeof(map_alloc<int, test_allocator<std::pair<const int, int> > >) == 40, ""); | ||
| static_assert(sizeof(map_alloc<int, small_iter_allocator<std::pair<const int, int> > >) == 6, ""); | ||
| static_assert(sizeof(map_alloc<int, final_small_iter_allocator<std::pair<const int, int> > >) == 8, ""); | ||
|
|
||
| static_assert(sizeof(map_alloc<char, std::allocator<std::pair<const char, char> > >) == 24, ""); | ||
| static_assert(sizeof(map_alloc<char, min_allocator<std::pair<const char, char> > >) == 24, ""); | ||
| static_assert(sizeof(map_alloc<char, test_allocator<std::pair<const char, char> > >) == 40, ""); | ||
| static_assert(sizeof(map_alloc<char, small_iter_allocator<std::pair<const char, char> > >) == 6, ""); | ||
| static_assert(sizeof(map_alloc<char, final_small_iter_allocator<std::pair<const char, char> > >) == 8, ""); | ||
|
|
||
| static_assert(TEST_ALIGNOF(map_alloc<int, std::allocator<std::pair<const int, int> > >) == 8, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<int, min_allocator<std::pair<const int, int> > >) == 8, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<int, test_allocator<std::pair<const int, int> > >) == 8, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<int, small_iter_allocator<std::pair<const int, int> > >) == 2, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<int, final_small_iter_allocator<std::pair<const int, int> > >) == 2, ""); | ||
|
|
||
| static_assert(TEST_ALIGNOF(map_alloc<char, std::allocator<std::pair<const char, char> > >) == 8, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<char, min_allocator<std::pair<const char, char> > >) == 8, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<char, test_allocator<std::pair<const char, char> > >) == 8, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<char, small_iter_allocator<std::pair<const char, char> > >) == 2, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<char, final_small_iter_allocator<std::pair<const char, char> > >) == 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<int, int, AlignedLess>) == 64, ""); | ||
| static_assert(TEST_ALIGNOF(std::map<int, int, AlignedLess>) == 32, ""); | ||
|
|
||
| #elif __SIZE_WIDTH__ == 32 | ||
| static_assert(sizeof(user_struct) == 16, ""); | ||
| static_assert(TEST_ALIGNOF(user_struct) == 4, ""); | ||
|
|
||
| static_assert(sizeof(map_alloc<int, std::allocator<std::pair<const int, int> > >) == 12, ""); | ||
| static_assert(sizeof(map_alloc<int, min_allocator<std::pair<const int, int> > >) == 12, ""); | ||
| static_assert(sizeof(map_alloc<int, test_allocator<std::pair<const int, int> > >) == 24, ""); | ||
| static_assert(sizeof(map_alloc<int, small_iter_allocator<std::pair<const int, int> > >) == 6, ""); | ||
| static_assert(sizeof(map_alloc<int, final_small_iter_allocator<std::pair<const int, int> > >) == 8, ""); | ||
|
|
||
| static_assert(sizeof(map_alloc<char, std::allocator<std::pair<const char, char> > >) == 12, ""); | ||
| static_assert(sizeof(map_alloc<char, min_allocator<std::pair<const char, char> > >) == 12, ""); | ||
| static_assert(sizeof(map_alloc<char, test_allocator<std::pair<const char, char> > >) == 24, ""); | ||
| static_assert(sizeof(map_alloc<char, small_iter_allocator<std::pair<const char, char> > >) == 6, ""); | ||
| static_assert(sizeof(map_alloc<char, final_small_iter_allocator<std::pair<const char, char> > >) == 8, ""); | ||
|
|
||
| static_assert(TEST_ALIGNOF(map_alloc<int, std::allocator<std::pair<const int, int> > >) == 4, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<int, min_allocator<std::pair<const int, int> > >) == 4, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<int, test_allocator<std::pair<const int, int> > >) == 4, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<int, small_iter_allocator<std::pair<const int, int> > >) == 2, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<int, final_small_iter_allocator<std::pair<const int, int> > >) == 2, ""); | ||
|
|
||
| static_assert(TEST_ALIGNOF(map_alloc<char, std::allocator<std::pair<const char, char> > >) == 4, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<char, min_allocator<std::pair<const char, char> > >) == 4, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<char, test_allocator<std::pair<const char, char> > >) == 4, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<char, small_iter_allocator<std::pair<const char, char> > >) == 2, ""); | ||
| static_assert(TEST_ALIGNOF(map_alloc<char, final_small_iter_allocator<std::pair<const char, char> > >) == 2, ""); | ||
|
|
||
| struct TEST_ALIGNAS(32) AlignedLess {}; | ||
|
|
||
| static_assert(sizeof(std::map<int, int, AlignedLess>) == 64); | ||
| static_assert(TEST_ALIGNOF(std::map<int, int, AlignedLess>) == 32); | ||
|
|
||
| #else | ||
| # error std::size_t has an unexpected size | ||
| #endif |
161 changes: 161 additions & 0 deletions
161
libcxx/test/libcxx/containers/associative/set/abi.compile.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <cstdint> | ||
| #include <set> | ||
|
|
||
| #include "min_allocator.h" | ||
| #include "test_allocator.h" | ||
| #include "test_macros.h" | ||
|
|
||
| template <class T> | ||
| class small_pointer { | ||
| std::uint16_t offset; | ||
| }; | ||
|
|
||
| template <class T> | ||
| class small_iter_allocator { | ||
| public: | ||
| using value_type = T; | ||
| using pointer = small_pointer<T>; | ||
| using size_type = std::uint16_t; | ||
| using difference_type = std::int16_t; | ||
|
|
||
| small_iter_allocator() TEST_NOEXCEPT {} | ||
|
|
||
| template <class U> | ||
| small_iter_allocator(small_iter_allocator<U>) 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 T> | ||
| class final_small_iter_allocator final { | ||
| public: | ||
| using value_type = T; | ||
| using pointer = small_pointer<T>; | ||
| using size_type = std::uint16_t; | ||
| using difference_type = std::int16_t; | ||
|
|
||
| final_small_iter_allocator() TEST_NOEXCEPT {} | ||
|
|
||
| template <class U> | ||
| final_small_iter_allocator(final_small_iter_allocator<U>) 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 <class T> | ||
| struct common_base_allocator : allocator_base { | ||
| using value_type = T; | ||
|
|
||
| common_base_allocator() TEST_NOEXCEPT {} | ||
|
|
||
| template <class U> | ||
| common_base_allocator(common_base_allocator<U>) 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 <class T, class Alloc> | ||
| using set_alloc = std::set<T, std::less<T>, Alloc>; | ||
|
|
||
| struct user_struct { | ||
| set_alloc<int, common_base_allocator<int> > v; | ||
| [[no_unique_address]] common_base_allocator<int> a; | ||
| }; | ||
|
|
||
| #if __SIZE_WIDTH__ == 64 | ||
| static_assert(sizeof(user_struct) == 32, ""); | ||
| static_assert(TEST_ALIGNOF(user_struct) == 8, ""); | ||
|
|
||
| static_assert(sizeof(set_alloc<int, std::allocator<int> >) == 24, ""); | ||
| static_assert(sizeof(set_alloc<int, min_allocator<int> >) == 24, ""); | ||
| static_assert(sizeof(set_alloc<int, test_allocator<int> >) == 40, ""); | ||
| static_assert(sizeof(set_alloc<int, small_iter_allocator<int> >) == 6, ""); | ||
| static_assert(sizeof(set_alloc<int, final_small_iter_allocator<int> >) == 8, ""); | ||
|
|
||
| static_assert(sizeof(set_alloc<char, std::allocator<char> >) == 24, ""); | ||
| static_assert(sizeof(set_alloc<char, min_allocator<char> >) == 24, ""); | ||
| static_assert(sizeof(set_alloc<char, test_allocator<char> >) == 40, ""); | ||
| static_assert(sizeof(set_alloc<char, small_iter_allocator<char> >) == 6, ""); | ||
| static_assert(sizeof(set_alloc<char, final_small_iter_allocator<char> >) == 8, ""); | ||
|
|
||
| static_assert(TEST_ALIGNOF(set_alloc<int, std::allocator<int> >) == 8, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<int, min_allocator<int> >) == 8, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<int, test_allocator<int> >) == 8, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<int, small_iter_allocator<int> >) == 2, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<int, final_small_iter_allocator<int> >) == 2, ""); | ||
|
|
||
| static_assert(TEST_ALIGNOF(set_alloc<char, std::allocator<char> >) == 8, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<char, min_allocator<char> >) == 8, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<char, test_allocator<char> >) == 8, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<char, small_iter_allocator<char> >) == 2, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<char, final_small_iter_allocator<char> >) == 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<int, AlignedLess>) == 64, ""); | ||
| static_assert(TEST_ALIGNOF(std::set<int, AlignedLess>) == 32, ""); | ||
|
|
||
| #elif __SIZE_WIDTH__ == 32 | ||
| static_assert(sizeof(user_struct) == 16, ""); | ||
| static_assert(TEST_ALIGNOF(user_struct) == 4, ""); | ||
|
|
||
| static_assert(sizeof(set_alloc<int, std::allocator<int> >) == 12, ""); | ||
| static_assert(sizeof(set_alloc<int, min_allocator<int> >) == 12, ""); | ||
| static_assert(sizeof(set_alloc<int, test_allocator<int> >) == 24, ""); | ||
| static_assert(sizeof(set_alloc<int, small_iter_allocator<int> >) == 6, ""); | ||
| static_assert(sizeof(set_alloc<int, final_small_iter_allocator<int> >) == 8, ""); | ||
|
|
||
| static_assert(sizeof(set_alloc<char, std::allocator<char> >) == 12, ""); | ||
| static_assert(sizeof(set_alloc<char, min_allocator<char> >) == 12, ""); | ||
| static_assert(sizeof(set_alloc<char, test_allocator<char> >) == 24, ""); | ||
| static_assert(sizeof(set_alloc<char, small_iter_allocator<char> >) == 6, ""); | ||
| static_assert(sizeof(set_alloc<char, final_small_iter_allocator<char> >) == 8, ""); | ||
|
|
||
| static_assert(TEST_ALIGNOF(set_alloc<int, std::allocator<int> >) == 4, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<int, min_allocator<int> >) == 4, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<int, test_allocator<int> >) == 4, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<int, small_iter_allocator<int> >) == 2, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<int, final_small_iter_allocator<int> >) == 2, ""); | ||
|
|
||
| static_assert(TEST_ALIGNOF(set_alloc<char, std::allocator<char> >) == 4, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<char, min_allocator<char> >) == 4, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<char, test_allocator<char> >) == 4, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<char, small_iter_allocator<char> >) == 2, ""); | ||
| static_assert(TEST_ALIGNOF(set_alloc<char, final_small_iter_allocator<char> >) == 2, ""); | ||
|
|
||
| struct TEST_ALIGNAS(32) AlignedLess {}; | ||
|
|
||
| static_assert(sizeof(std::set<int, AlignedLess>) == 64); | ||
| static_assert(TEST_ALIGNOF(std::set<int, AlignedLess>) == 32); | ||
|
|
||
| #else | ||
| # error std::size_t has an unexpected size | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.