[SLP] Make getSameOpcode support different instructions if they have same semantics...
[llvm-project.git] / libcxx / test / std / containers / sequences / array / size_and_alignment.compile.pass.cpp
blob7ba56577d1bb76d923f51b14fe5ecde308cda4c9
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 //===----------------------------------------------------------------------===//
9 // <array>
11 // template <class T, size_t N>
12 // struct array
14 // Make sure std::array<T, N> has the correct object size and alignment.
15 // This test is mostly meant to catch subtle ABI-breaking regressions.
17 // Ignore error about requesting a large alignment not being ABI compatible with older AIX systems.
18 #if defined(_AIX)
19 # pragma clang diagnostic ignored "-Waix-compat"
20 #endif
22 #include <array>
23 #include <cstddef>
24 #include <type_traits>
26 #ifdef _LIBCPP_VERSION
27 # include <__type_traits/datasizeof.h>
28 #endif
30 #include "test_macros.h"
32 template <class T, std::size_t Size>
33 struct MyArray {
34 T elems[Size];
37 template <class T>
38 void test_type() {
40 using Array = std::array<T, 0>;
41 LIBCPP_STATIC_ASSERT(sizeof(Array) == sizeof(T), "");
42 LIBCPP_STATIC_ASSERT(TEST_ALIGNOF(Array) == TEST_ALIGNOF(T), "");
43 LIBCPP_STATIC_ASSERT(sizeof(Array) == sizeof(T[1]), "");
44 LIBCPP_STATIC_ASSERT(sizeof(Array) == sizeof(MyArray<T, 1>), "");
45 LIBCPP_STATIC_ASSERT(TEST_ALIGNOF(Array) == TEST_ALIGNOF(MyArray<T, 1>), "");
46 static_assert(!std::is_empty<Array>::value, "");
48 // Make sure empty arrays don't have padding bytes
49 LIBCPP_STATIC_ASSERT(std::__datasizeof_v<Array> == sizeof(Array), "");
53 using Array = std::array<T, 1>;
54 static_assert(sizeof(Array) == sizeof(T), "");
55 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(T), "");
56 static_assert(sizeof(Array) == sizeof(T[1]), "");
57 static_assert(sizeof(Array) == sizeof(MyArray<T, 1>), "");
58 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(MyArray<T, 1>), "");
59 static_assert(!std::is_empty<Array>::value, "");
63 using Array = std::array<T, 2>;
64 static_assert(sizeof(Array) == sizeof(T) * 2, "");
65 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(T), "");
66 static_assert(sizeof(Array) == sizeof(T[2]), "");
67 static_assert(sizeof(Array) == sizeof(MyArray<T, 2>), "");
68 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(MyArray<T, 2>), "");
69 static_assert(!std::is_empty<Array>::value, "");
73 using Array = std::array<T, 3>;
74 static_assert(sizeof(Array) == sizeof(T) * 3, "");
75 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(T), "");
76 static_assert(sizeof(Array) == sizeof(T[3]), "");
77 static_assert(sizeof(Array) == sizeof(MyArray<T, 3>), "");
78 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(MyArray<T, 3>), "");
79 static_assert(!std::is_empty<Array>::value, "");
83 using Array = std::array<T, 444>;
84 static_assert(sizeof(Array) == sizeof(T) * 444, "");
85 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(T), "");
86 static_assert(sizeof(Array) == sizeof(T[444]), "");
87 static_assert(sizeof(Array) == sizeof(MyArray<T, 444>), "");
88 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(MyArray<T, 444>), "");
89 static_assert(!std::is_empty<Array>::value, "");
93 struct Empty {};
95 struct Aggregate {
96 int i;
99 struct WithPadding {
100 long double ld;
101 char c;
104 #if TEST_STD_VER >= 11
105 struct alignas(TEST_ALIGNOF(std::max_align_t) * 2) Overaligned1 {};
107 struct alignas(TEST_ALIGNOF(std::max_align_t) * 2) Overaligned2 {
108 char data[1000];
111 struct alignas(TEST_ALIGNOF(std::max_align_t)) Overaligned3 {
112 char data[1000];
115 struct alignas(8) Overaligned4 {
116 char c;
119 struct alignas(8) Overaligned5 {};
120 #endif
122 void test() {
123 test_type<char>();
124 test_type<short>();
125 test_type<int>();
126 test_type<long>();
127 test_type<long long>();
128 test_type<float>();
129 test_type<double>();
130 test_type<long double>();
131 test_type<char[1]>();
132 test_type<char[2]>();
133 test_type<char[3]>();
134 test_type<Empty>();
135 test_type<Aggregate>();
136 test_type<WithPadding>();
138 #if TEST_STD_VER >= 11
139 test_type<std::max_align_t>();
140 test_type<Overaligned1>();
141 test_type<Overaligned2>();
142 test_type<Overaligned3>();
143 test_type<Overaligned4>();
144 test_type<Overaligned5>();
145 #endif