Skip to content

Commit 583129d

Browse files
committed
[libc++] Add tests for the ABI of deque, list and vector for replacing __compressed_pair with [[no_unique_address]]
1 parent 2acf302 commit 583129d

File tree

4 files changed

+267
-1
lines changed

4 files changed

+267
-1
lines changed

libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class small_iter_allocator {
2222
public:
2323
using value_type = T;
2424
using pointer = small_pointer<T>;
25-
using size_type = std::int16_t;
25+
using size_type = std::uint16_t;
2626
using difference_type = std::int16_t;
2727

2828
small_iter_allocator() TEST_NOEXCEPT {}
@@ -37,49 +37,77 @@ class small_iter_allocator {
3737
friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; }
3838
};
3939

40+
template <class T>
41+
class final_small_iter_allocator final {
42+
public:
43+
using value_type = T;
44+
using pointer = small_pointer<T>;
45+
using size_type = std::uint16_t;
46+
using difference_type = std::int16_t;
47+
48+
final_small_iter_allocator() TEST_NOEXCEPT {}
49+
50+
template <class U>
51+
final_small_iter_allocator(final_small_iter_allocator<U>) TEST_NOEXCEPT {}
52+
53+
T* allocate(std::size_t n);
54+
void deallocate(T* p, std::size_t);
55+
56+
friend bool operator==(final_small_iter_allocator, final_small_iter_allocator) { return true; }
57+
friend bool operator!=(final_small_iter_allocator, final_small_iter_allocator) { return false; }
58+
};
59+
4060
#if __SIZE_WIDTH__ == 64
4161

4262
static_assert(sizeof(std::deque<int>) == 48, "");
4363
static_assert(sizeof(std::deque<int, min_allocator<int> >) == 48, "");
4464
static_assert(sizeof(std::deque<int, test_allocator<int> >) == 80, "");
4565
static_assert(sizeof(std::deque<int, small_iter_allocator<int> >) == 12, "");
66+
static_assert(sizeof(std::deque<int, final_small_iter_allocator<int> >) == 16, "");
4667

4768
static_assert(sizeof(std::deque<char>) == 48, "");
4869
static_assert(sizeof(std::deque<char, min_allocator<char> >) == 48, "");
4970
static_assert(sizeof(std::deque<char, test_allocator<char> >) == 80, "");
5071
static_assert(sizeof(std::deque<char, small_iter_allocator<char> >) == 12, "");
72+
static_assert(sizeof(std::deque<char, final_small_iter_allocator<char> >) == 16, "");
5173

5274
static_assert(TEST_ALIGNOF(std::deque<int>) == 8, "");
5375
static_assert(TEST_ALIGNOF(std::deque<int, min_allocator<int> >) == 8, "");
5476
static_assert(TEST_ALIGNOF(std::deque<int, test_allocator<int> >) == 8, "");
5577
static_assert(TEST_ALIGNOF(std::deque<int, small_iter_allocator<int> >) == 2, "");
78+
static_assert(TEST_ALIGNOF(std::deque<int, final_small_iter_allocator<int> >) == 2, "");
5679

5780
static_assert(TEST_ALIGNOF(std::deque<char>) == 8, "");
5881
static_assert(TEST_ALIGNOF(std::deque<char, min_allocator<char> >) == 8, "");
5982
static_assert(TEST_ALIGNOF(std::deque<char, test_allocator<char> >) == 8, "");
6083
static_assert(TEST_ALIGNOF(std::deque<char, small_iter_allocator<char> >) == 2, "");
84+
static_assert(TEST_ALIGNOF(std::deque<char, final_small_iter_allocator<char> >) == 2, "");
6185

6286
#elif __SIZE_WIDTH__ == 32
6387

6488
static_assert(sizeof(std::deque<int>) == 24, "");
6589
static_assert(sizeof(std::deque<int, min_allocator<int> >) == 24, "");
6690
static_assert(sizeof(std::deque<int, test_allocator<int> >) == 48, "");
6791
static_assert(sizeof(std::deque<int, small_iter_allocator<int> >) == 12, "");
92+
static_assert(sizeof(std::deque<int, final_small_iter_allocator<int> >) == 12, "");
6893

6994
static_assert(sizeof(std::deque<char>) == 24, "");
7095
static_assert(sizeof(std::deque<char, min_allocator<char> >) == 24, "");
7196
static_assert(sizeof(std::deque<char, test_allocator<char> >) == 48, "");
7297
static_assert(sizeof(std::deque<char, small_iter_allocator<char> >) == 12, "");
98+
static_assert(sizeof(std::deque<char, final_small_iter_allocator<char> >) == 12, "");
7399

74100
static_assert(TEST_ALIGNOF(std::deque<int>) == 4, "");
75101
static_assert(TEST_ALIGNOF(std::deque<int, min_allocator<int> >) == 4, "");
76102
static_assert(TEST_ALIGNOF(std::deque<int, test_allocator<int> >) == 4, "");
77103
static_assert(TEST_ALIGNOF(std::deque<int, small_iter_allocator<int> >) == 2, "");
104+
static_assert(TEST_ALIGNOF(std::deque<int, final_small_iter_allocator<int> >) == 2, "");
78105

79106
static_assert(TEST_ALIGNOF(std::deque<char>) == 4, "");
80107
static_assert(TEST_ALIGNOF(std::deque<char, min_allocator<char> >) == 4, "");
81108
static_assert(TEST_ALIGNOF(std::deque<char, test_allocator<char> >) == 4, "");
82109
static_assert(TEST_ALIGNOF(std::deque<char, small_iter_allocator<char> >) == 2, "");
110+
static_assert(TEST_ALIGNOF(std::deque<char, final_small_iter_allocator<char> >) == 2, "");
83111

84112
#else
85113
# error std::size_t has an unexpected size
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <list>
10+
11+
#include "min_allocator.h"
12+
#include "test_allocator.h"
13+
#include "test_macros.h"
14+
15+
template <class T>
16+
class small_pointer {
17+
std::uint16_t offset;
18+
};
19+
20+
template <class T>
21+
class small_iter_allocator {
22+
public:
23+
using value_type = T;
24+
using pointer = small_pointer<T>;
25+
using size_type = std::int16_t;
26+
using difference_type = std::int16_t;
27+
28+
small_iter_allocator() TEST_NOEXCEPT {}
29+
30+
template <class U>
31+
small_iter_allocator(small_iter_allocator<U>) TEST_NOEXCEPT {}
32+
33+
T* allocate(std::size_t n);
34+
void deallocate(T* p, std::size_t);
35+
36+
friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; }
37+
friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; }
38+
};
39+
40+
#if __SIZE_WIDTH__ == 64
41+
42+
static_assert(sizeof(std::list<int>) == 24, "");
43+
static_assert(sizeof(std::list<int, min_allocator<int> >) == 24, "");
44+
static_assert(sizeof(std::list<int, test_allocator<int> >) == 40, "");
45+
static_assert(sizeof(std::list<int, small_iter_allocator<int> >) == 6, "");
46+
47+
static_assert(sizeof(std::list<char>) == 24, "");
48+
static_assert(sizeof(std::list<char, min_allocator<char> >) == 24, "");
49+
static_assert(sizeof(std::list<char, test_allocator<char> >) == 40, "");
50+
static_assert(sizeof(std::list<char, small_iter_allocator<char> >) == 6, "");
51+
52+
static_assert(TEST_ALIGNOF(std::list<int>) == 8, "");
53+
static_assert(TEST_ALIGNOF(std::list<int, min_allocator<int> >) == 8, "");
54+
static_assert(TEST_ALIGNOF(std::list<int, test_allocator<int> >) == 8, "");
55+
static_assert(TEST_ALIGNOF(std::list<int, small_iter_allocator<int> >) == 2, "");
56+
57+
static_assert(TEST_ALIGNOF(std::list<char>) == 8, "");
58+
static_assert(TEST_ALIGNOF(std::list<char, min_allocator<char> >) == 8, "");
59+
static_assert(TEST_ALIGNOF(std::list<char, test_allocator<char> >) == 8, "");
60+
static_assert(TEST_ALIGNOF(std::list<char, small_iter_allocator<char> >) == 2, "");
61+
62+
#elif __SIZE_WIDTH__ == 32
63+
64+
static_assert(sizeof(std::list<int>) == 24, "");
65+
static_assert(sizeof(std::list<int, min_allocator<int> >) == 24, "");
66+
static_assert(sizeof(std::list<int, test_allocator<int> >) == 24, "");
67+
static_assert(sizeof(std::list<int, small_iter_allocator<int> >) == 6, "");
68+
69+
static_assert(sizeof(std::list<char>) == 24, "");
70+
static_assert(sizeof(std::list<char, min_allocator<char> >) == 24, "");
71+
static_assert(sizeof(std::list<char, test_allocator<char> >) == 24, "");
72+
static_assert(sizeof(std::list<char, small_iter_allocator<char> >) == 6, "");
73+
74+
static_assert(TEST_ALIGNOF(std::list<int>) == 4, "");
75+
static_assert(TEST_ALIGNOF(std::list<int, min_allocator<int> >) == 4, "");
76+
static_assert(TEST_ALIGNOF(std::list<int, test_allocator<int> >) == 4, "");
77+
static_assert(TEST_ALIGNOF(std::list<int, small_iter_allocator<int> >) == 2, "");
78+
79+
static_assert(TEST_ALIGNOF(std::list<char>) == 4, "");
80+
static_assert(TEST_ALIGNOF(std::list<char, min_allocator<char> >) == 4, "");
81+
static_assert(TEST_ALIGNOF(std::list<char, test_allocator<char> >) == 4, "");
82+
static_assert(TEST_ALIGNOF(std::list<char, small_iter_allocator<char> >) == 2, "");
83+
84+
#else
85+
# error std::size_t has an unexpected size
86+
#endif
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <vector>
10+
11+
#include "min_allocator.h"
12+
#include "test_allocator.h"
13+
#include "test_macros.h"
14+
15+
template <class T>
16+
class small_pointer {
17+
std::uint16_t offset;
18+
};
19+
20+
template <class T>
21+
class small_iter_allocator {
22+
public:
23+
using value_type = T;
24+
using pointer = small_pointer<T>;
25+
using size_type = std::int16_t;
26+
using difference_type = std::int16_t;
27+
28+
small_iter_allocator() TEST_NOEXCEPT {}
29+
30+
template <class U>
31+
small_iter_allocator(small_iter_allocator<U>) TEST_NOEXCEPT {}
32+
33+
T* allocate(std::size_t n);
34+
void deallocate(T* p, std::size_t);
35+
36+
friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; }
37+
friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; }
38+
};
39+
40+
#if __SIZE_WIDTH__ == 64
41+
42+
static_assert(sizeof(std::vector<bool>) == 24, "");
43+
static_assert(sizeof(std::vector<bool, min_allocator<bool> >) == 24, "");
44+
static_assert(sizeof(std::vector<bool, test_allocator<bool> >) == 40, "");
45+
static_assert(sizeof(std::vector<bool, small_iter_allocator<bool> >) == 6, "");
46+
47+
static_assert(TEST_ALIGNOF(std::vector<bool>) == 8, "");
48+
static_assert(TEST_ALIGNOF(std::vector<bool, min_allocator<bool> >) == 8, "");
49+
static_assert(TEST_ALIGNOF(std::vector<bool, test_allocator<bool> >) == 8, "");
50+
static_assert(TEST_ALIGNOF(std::vector<bool, small_iter_allocator<bool> >) == 2, "");
51+
52+
#elif __SIZE_WIDTH__ == 32
53+
54+
static_assert(sizeof(std::vector<bool>) == 24, "");
55+
static_assert(sizeof(std::vector<bool, min_allocator<bool> >) == 24, "");
56+
static_assert(sizeof(std::vector<bool, test_allocator<bool> >) == 24, "");
57+
static_assert(sizeof(std::vector<bool, small_iter_allocator<bool> >) == 6, "");
58+
59+
static_assert(TEST_ALIGNOF(std::vector<bool>) == 4, "");
60+
static_assert(TEST_ALIGNOF(std::vector<bool, min_allocator<bool> >) == 4, "");
61+
static_assert(TEST_ALIGNOF(std::vector<bool, test_allocator<bool> >) == 4, "");
62+
static_assert(TEST_ALIGNOF(std::vector<bool, small_iter_allocator<bool> >) == 2, "");
63+
64+
#else
65+
# error std::size_t has an unexpected size
66+
#endif
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <vector>
10+
11+
#include "min_allocator.h"
12+
#include "test_allocator.h"
13+
#include "test_macros.h"
14+
15+
template <class T>
16+
class small_pointer {
17+
std::uint16_t offset;
18+
};
19+
20+
template <class T>
21+
class small_iter_allocator {
22+
public:
23+
using value_type = T;
24+
using pointer = small_pointer<T>;
25+
using size_type = std::int16_t;
26+
using difference_type = std::int16_t;
27+
28+
small_iter_allocator() TEST_NOEXCEPT {}
29+
30+
template <class U>
31+
small_iter_allocator(small_iter_allocator<U>) TEST_NOEXCEPT {}
32+
33+
T* allocate(std::size_t n);
34+
void deallocate(T* p, std::size_t);
35+
36+
friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; }
37+
friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; }
38+
};
39+
40+
#if __SIZE_WIDTH__ == 64
41+
42+
static_assert(sizeof(std::vector<int>) == 24, "");
43+
static_assert(sizeof(std::vector<int, min_allocator<int> >) == 24, "");
44+
static_assert(sizeof(std::vector<int, test_allocator<int> >) == 40, "");
45+
static_assert(sizeof(std::vector<int, small_iter_allocator<int> >) == 6, "");
46+
47+
static_assert(sizeof(std::vector<char>) == 24, "");
48+
static_assert(sizeof(std::vector<char, min_allocator<char> >) == 24, "");
49+
static_assert(sizeof(std::vector<char, test_allocator<char> >) == 40, "");
50+
static_assert(sizeof(std::vector<char, small_iter_allocator<char> >) == 6, "");
51+
52+
static_assert(TEST_ALIGNOF(std::vector<int>) == 8, "");
53+
static_assert(TEST_ALIGNOF(std::vector<int, min_allocator<int> >) == 8, "");
54+
static_assert(TEST_ALIGNOF(std::vector<int, test_allocator<int> >) == 8, "");
55+
static_assert(TEST_ALIGNOF(std::vector<int, small_iter_allocator<int> >) == 2, "");
56+
57+
static_assert(TEST_ALIGNOF(std::vector<char>) == 8, "");
58+
static_assert(TEST_ALIGNOF(std::vector<char, min_allocator<char> >) == 8, "");
59+
static_assert(TEST_ALIGNOF(std::vector<char, test_allocator<char> >) == 8, "");
60+
static_assert(TEST_ALIGNOF(std::vector<char, small_iter_allocator<char> >) == 2, "");
61+
62+
#elif __SIZE_WIDTH__ == 32
63+
64+
static_assert(sizeof(std::vector<int>) == 24, "");
65+
static_assert(sizeof(std::vector<int, min_allocator<int> >) == 24, "");
66+
static_assert(sizeof(std::vector<int, test_allocator<int> >) == 24, "");
67+
static_assert(sizeof(std::vector<int, small_iter_allocator<int> >) == 6, "");
68+
69+
static_assert(sizeof(std::vector<char>) == 24, "");
70+
static_assert(sizeof(std::vector<char, min_allocator<char> >) == 24, "");
71+
static_assert(sizeof(std::vector<char, test_allocator<char> >) == 24, "");
72+
static_assert(sizeof(std::vector<char, small_iter_allocator<char> >) == 6, "");
73+
74+
static_assert(TEST_ALIGNOF(std::vector<int>) == 4, "");
75+
static_assert(TEST_ALIGNOF(std::vector<int, min_allocator<int> >) == 4, "");
76+
static_assert(TEST_ALIGNOF(std::vector<int, test_allocator<int> >) == 4, "");
77+
static_assert(TEST_ALIGNOF(std::vector<int, small_iter_allocator<int> >) == 2, "");
78+
79+
static_assert(TEST_ALIGNOF(std::vector<char>) == 4, "");
80+
static_assert(TEST_ALIGNOF(std::vector<char, min_allocator<char> >) == 4, "");
81+
static_assert(TEST_ALIGNOF(std::vector<char, test_allocator<char> >) == 4, "");
82+
static_assert(TEST_ALIGNOF(std::vector<char, small_iter_allocator<char> >) == 2, "");
83+
84+
#else
85+
# error std::size_t has an unexpected size
86+
#endif

0 commit comments

Comments
 (0)