[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / containers / sequences / array / size_and_alignment.compile.pass.cpp
blobb7fb40c988678ae7197cbb10637ab9d20a2a507a
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>
25 #include <__type_traits/datasizeof.h>
27 #include "test_macros.h"
29 template <class T, std::size_t Size>
30 struct MyArray {
31 T elems[Size];
34 template <class T>
35 void test_type() {
37 using Array = std::array<T, 0>;
38 LIBCPP_STATIC_ASSERT(sizeof(Array) == sizeof(T), "");
39 LIBCPP_STATIC_ASSERT(TEST_ALIGNOF(Array) == TEST_ALIGNOF(T), "");
40 LIBCPP_STATIC_ASSERT(sizeof(Array) == sizeof(T[1]), "");
41 LIBCPP_STATIC_ASSERT(sizeof(Array) == sizeof(MyArray<T, 1>), "");
42 LIBCPP_STATIC_ASSERT(TEST_ALIGNOF(Array) == TEST_ALIGNOF(MyArray<T, 1>), "");
43 static_assert(!std::is_empty<Array>::value, "");
45 // Make sure empty arrays don't have padding bytes
46 LIBCPP_STATIC_ASSERT(std::__libcpp_datasizeof<Array>::value == sizeof(Array), "");
50 using Array = std::array<T, 1>;
51 static_assert(sizeof(Array) == sizeof(T), "");
52 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(T), "");
53 static_assert(sizeof(Array) == sizeof(T[1]), "");
54 static_assert(sizeof(Array) == sizeof(MyArray<T, 1>), "");
55 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(MyArray<T, 1>), "");
56 static_assert(!std::is_empty<Array>::value, "");
60 using Array = std::array<T, 2>;
61 static_assert(sizeof(Array) == sizeof(T) * 2, "");
62 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(T), "");
63 static_assert(sizeof(Array) == sizeof(T[2]), "");
64 static_assert(sizeof(Array) == sizeof(MyArray<T, 2>), "");
65 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(MyArray<T, 2>), "");
66 static_assert(!std::is_empty<Array>::value, "");
70 using Array = std::array<T, 3>;
71 static_assert(sizeof(Array) == sizeof(T) * 3, "");
72 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(T), "");
73 static_assert(sizeof(Array) == sizeof(T[3]), "");
74 static_assert(sizeof(Array) == sizeof(MyArray<T, 3>), "");
75 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(MyArray<T, 3>), "");
76 static_assert(!std::is_empty<Array>::value, "");
80 using Array = std::array<T, 444>;
81 static_assert(sizeof(Array) == sizeof(T) * 444, "");
82 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(T), "");
83 static_assert(sizeof(Array) == sizeof(T[444]), "");
84 static_assert(sizeof(Array) == sizeof(MyArray<T, 444>), "");
85 static_assert(TEST_ALIGNOF(Array) == TEST_ALIGNOF(MyArray<T, 444>), "");
86 static_assert(!std::is_empty<Array>::value, "");
90 struct Empty {};
92 struct Aggregate {
93 int i;
96 struct WithPadding {
97 long double ld;
98 char c;
101 #if TEST_STD_VER >= 11
102 struct alignas(TEST_ALIGNOF(std::max_align_t) * 2) Overaligned1 {};
104 struct alignas(TEST_ALIGNOF(std::max_align_t) * 2) Overaligned2 {
105 char data[1000];
108 struct alignas(TEST_ALIGNOF(std::max_align_t)) Overaligned3 {
109 char data[1000];
112 struct alignas(8) Overaligned4 {
113 char c;
116 struct alignas(8) Overaligned5 {};
117 #endif
119 void test() {
120 test_type<char>();
121 test_type<short>();
122 test_type<int>();
123 test_type<long>();
124 test_type<long long>();
125 test_type<float>();
126 test_type<double>();
127 test_type<long double>();
128 test_type<char[1]>();
129 test_type<char[2]>();
130 test_type<char[3]>();
131 test_type<Empty>();
132 test_type<Aggregate>();
133 test_type<WithPadding>();
135 #if TEST_STD_VER >= 11
136 test_type<std::max_align_t>();
137 test_type<Overaligned1>();
138 test_type<Overaligned2>();
139 test_type<Overaligned3>();
140 test_type<Overaligned4>();
141 test_type<Overaligned5>();
142 #endif