[AMDGPU][True16][CodeGen] true16 codegen pattern for v_med3_u/i16 (#121850)
[llvm-project.git] / clang / test / CodeGenCXX / new-array-init.cpp
blob732bbb60102be2d15622a4ce23c5497dae12275e
1 // RUN: %clang_cc1 -std=c++11 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck %s
2 // RUN: %clang_cc1 -std=c++20 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECKCXX20
3 // RUN: %clang_cc1 -std=c++11 -triple i386-unknown-unknown %s -emit-llvm -fsanitize=signed-integer-overflow -o - | FileCheck --check-prefix=SIO %s
5 // CHECK: @[[ABC4:.*]] = {{.*}} constant [4 x i8] c"abc\00"
6 // CHECK: @[[ABC15:.*]] = {{.*}} constant [15 x i8] c"abc\00\00\00\00
8 // CHECK-LABEL: define{{.*}} void @_Z2fni
9 void fn(int n) {
10 // CHECK: icmp ult i{{32|64}} %{{[^ ]+}}, 3
11 // CHECK: store i32 1
12 // CHECK: store i32 2
13 // CHECK: store i32 3
14 // CHECK: sub {{.*}}, 12
15 // CHECK: call void @llvm.memset
16 new int[n] { 1, 2, 3 };
19 #if __cplusplus >= 202002L
20 // CHECKCXX20-LABEL: define{{.*}} void @_Z8fn_pareni
21 void fn_paren(int n) {
22 // CHECKCXX20: icmp ult i{{32|64}} %{{[^ ]+}}, 3
23 // CHECKCXX20: store i32 1
24 // CHECKCXX20: store i32 2
25 // CHECKCXX20: store i32 3
26 // CHECKCXX20: sub {{.*}}, 12
27 // CHECKCXX20: call void @llvm.memset
28 new int[n](1, 2, 3);
30 #endif
32 // CHECK-LABEL: define{{.*}} void @_Z11const_exactv
33 void const_exact() {
34 // CHECK-NOT: icmp ult i{{32|64}} %{{[^ ]+}}, 3
35 // CHECK-NOT: icmp eq ptr
36 new int[3] { 1, 2, 3 };
39 #if __cplusplus >= 202002L
40 // CHECKCXX20-LABEL: define{{.*}} void @_Z17const_exact_parenv
41 void const_exact_paren() {
42 // CHECKCXX20-NOT: icmp ult i{{32|64}} %{{[^ ]+}}, 3
43 // CHECKCXX20-NOT: icmp eq ptr
44 new int[3](1, 2, 3);
46 #endif
48 // CHECK-LABEL: define{{.*}} void @_Z16const_sufficientv
49 void const_sufficient() {
50 // CHECK-NOT: icmp ult i{{32|64}} %{{[^ ]+}}, 3
51 new int[4] { 1, 2, 3 };
52 // CHECK: ret void
55 #if __cplusplus >= 202002L
56 // CHECKCXX20-LABEL: define{{.*}} void @_Z22const_sufficient_parenv
57 void const_sufficient_paren() {
58 // CHECKCXX20-NOT: icmp ult i{{32|64}} %{{[^ ]+}}, 3
59 new int[4](1, 2, 3);
60 // CHECKCXX20: ret void
62 #endif
64 // CHECK-LABEL: define{{.*}} void @_Z22check_array_value_initv
65 void check_array_value_init() {
66 struct S;
67 new (int S::*[3][4][5]) ();
69 // CHECK: call noalias noundef nonnull ptr @_Zna{{.}}(i{{32 noundef 240|64 noundef 480}})
70 // CHECK: getelementptr inbounds i{{32|64}}, ptr {{.*}}, i{{32|64}} 60
72 // CHECK: phi
73 // CHECK: store i{{32|64}} -1,
74 // CHECK: getelementptr inbounds i{{32|64}}, ptr {{.*}}, i{{32|64}} 1
75 // CHECK: icmp eq
76 // CHECK: br i1
79 // CHECK-LABEL: define{{.*}} void @_Z15string_nonconsti
80 void string_nonconst(int n) {
81 // CHECK: icmp {{s|u}}lt i{{32|64}} %{{[^ ]+}}, 4
82 // FIXME: Conditionally throw an exception rather than passing -1 to alloc function
83 // CHECK: select
84 // CHECK: %[[PTR:.*]] = call noalias noundef nonnull ptr @_Zna{{.}}(i{{32|64}}
85 // CHECK: call void @llvm.memcpy{{.*}}(ptr align {{[0-9]+}} %[[PTR]], ptr align {{[0-9]+}} @[[ABC4]], i32 4,
86 // CHECK: %[[REST:.*]] = getelementptr inbounds i8, ptr %[[PTR]], i32 4
87 // CHECK: %[[RESTSIZE:.*]] = sub {{.*}}, 4
88 // CHECK: call void @llvm.memset{{.*}}(ptr align {{[0-9]+}} %[[REST]], i8 0, i{{32|64}} %[[RESTSIZE]],
89 new char[n] { "abc" };
92 #if __cplusplus >= 202002L
93 // CHECKCXX20-LABEL: define{{.*}} void @_Z21string_nonconst_pareni
94 void string_nonconst_paren(int n) {
95 // CHECKCXX20: icmp {{s|u}}lt i{{32|64}} %{{[^ ]+}}, 4
96 // FIXME: Conditionally throw an exception rather than passing -1 to alloc function
97 // CHECKCXX20: select
98 // CHECKCXX20: %[[PTR:.*]] = call noalias noundef nonnull ptr @_Zna{{.}}(i{{32|64}}
99 // CHECKCXX20: call void @llvm.memcpy{{.*}}(ptr align {{[0-9]+}} %[[PTR]], ptr align {{[0-9]+}} @[[ABC4]], i32 4,
100 // CHECKCXX20: %[[REST:.*]] = getelementptr inbounds i8, ptr %[[PTR]], i32 4
101 // CHECKCXX20: %[[RESTSIZE:.*]] = sub {{.*}}, 4
102 // CHECKCXX20: call void @llvm.memset{{.*}}(ptr align {{[0-9]+}} %[[REST]], i8 0, i{{32|64}} %[[RESTSIZE]],
103 new char[n]("abc");
106 // CHECKCXX20-LABEL: define{{.*}} void @_Z33string_nonconst_paren_extra_pareni
107 void string_nonconst_paren_extra_paren(int n) {
108 // CHECKCXX20: icmp {{s|u}}lt i{{32|64}} %{{[^ ]+}}, 4
109 // FIXME: Conditionally throw an exception rather than passing -1 to alloc function
110 // CHECKCXX20: select
111 // CHECKCXX20: %[[PTR:.*]] = call noalias noundef nonnull ptr @_Zna{{.}}(i{{32|64}}
112 // CHECKCXX20: call void @llvm.memcpy{{.*}}(ptr align {{[0-9]+}} %[[PTR]], ptr align {{[0-9]+}} @[[ABC4]], i32 4,
113 // CHECKCXX20: %[[REST:.*]] = getelementptr inbounds i8, ptr %[[PTR]], i32 4
114 // CHECKCXX20: %[[RESTSIZE:.*]] = sub {{.*}}, 4
115 // CHECKCXX20: call void @llvm.memset{{.*}}(ptr align {{[0-9]+}} %[[REST]], i8 0, i{{32|64}} %[[RESTSIZE]],
116 new char[n](("abc"));
118 #endif
120 // CHECK-LABEL: define{{.*}} void @_Z12string_exactv
121 void string_exact() {
122 // CHECK-NOT: icmp
123 // CHECK: %[[PTR:.*]] = call noalias noundef nonnull ptr @_Zna{{.}}(i{{32|64}} noundef 4)
124 // CHECK: call void @llvm.memcpy{{.*}}(ptr align {{[0-9]+}} %[[PTR]], ptr align {{[0-9]+}} @[[ABC4]], i32 4,
125 // CHECK-NOT: memset
126 new char[4] { "abc" };
129 #if __cplusplus >= 202002L
130 // CHECKCXX20-LABEL: define{{.*}} void @_Z18string_exact_parenv
131 void string_exact_paren() {
132 // CHECKCXX20-NOT: icmp
133 // CHECKCXX20: %[[PTR:.*]] = call noalias noundef nonnull ptr @_Zna{{.}}(i{{32|64}} noundef 4)
134 // CHECKCXX20: call void @llvm.memcpy{{.*}}(ptr align {{[0-9]+}} %[[PTR]], ptr align {{[0-9]+}} @[[ABC4]], i32 4,
135 // CHECKCXX20-NOT: memset
136 new char[4]("abc");
139 // CHECKCXX20-LABEL: define{{.*}} void @_Z28string_exact_paren_extensionv
140 void string_exact_paren_extension() {
141 // CHECKCXX20-NOT: icmp
142 // CHECKCXX20: %[[PTR:.*]] = call noalias noundef nonnull ptr @_Zna{{.}}(i{{32|64}} noundef 4)
143 // CHECKCXX20: call void @llvm.memcpy{{.*}}(ptr align {{[0-9]+}} %[[PTR]], ptr align {{[0-9]+}} @[[ABC4]], i32 4,
144 // CHECKCXX20-NOT: memset
145 new char[4](__extension__ "abc");
147 #endif
149 // CHECK-LABEL: define{{.*}} void @_Z17string_sufficientv
150 void string_sufficient() {
151 // CHECK-NOT: icmp
152 // CHECK: %[[PTR:.*]] = call noalias noundef nonnull ptr @_Zna{{.}}(i{{32|64}} noundef 15)
153 // FIXME: For very large arrays, it would be preferable to emit a small copy and a memset.
154 // CHECK: call void @llvm.memcpy{{.*}}(ptr align {{[0-9]+}} %[[PTR]], ptr align {{[0-9]+}} @[[ABC15]], i32 15,
155 // CHECK-NOT: memset
156 new char[15] { "abc" };
159 #if __cplusplus >= 202002L
160 // CHECKCXX20-LABEL: define{{.*}} void @_Z23string_sufficient_parenv
161 void string_sufficient_paren() {
162 // CHECKCXX20-NOT: icmp
163 // CHECKCXX20: %[[PTR:.*]] = call noalias noundef nonnull ptr @_Zna{{.}}(i{{32|64}} noundef 15)
164 // FIXME: For very large arrays, it would be preferable to emit a small copy and a memset.
165 // CHECKCXX20: call void @llvm.memcpy{{.*}}(ptr align {{[0-9]+}} %[[PTR]], ptr align {{[0-9]+}} @[[ABC15]], i32 15,
166 // CHECKCXX20-NOT: memset
167 new char[15]("abc");
169 #endif
171 // CHECK-LABEL: define{{.*}} void @_Z10aggr_exactv
172 void aggr_exact() {
173 // CHECK-NOT: icmp
174 // CHECK: %[[MEM:.*]] = call noalias noundef nonnull ptr @_Zna{{.}}(i{{32|64}} noundef 16)
175 // CHECK: %[[FIELD:.*]] = getelementptr inbounds nuw %[[AGGR:.*]], ptr %[[MEM]], i32 0, i32 0{{$}}
176 // CHECK: store i32 1, ptr %[[FIELD]]
177 // CHECK: %[[FIELD:.*]] = getelementptr inbounds nuw %[[AGGR]], ptr %[[MEM]], i32 0, i32 1{{$}}
178 // CHECK: store i32 2, ptr %[[FIELD]]
179 // CHECK: %[[PTR1:.*]] = getelementptr inbounds %[[AGGR]], ptr %[[MEM]], i32 1{{$}}
180 // CHECK: %[[FIELD:.*]] = getelementptr inbounds nuw %[[AGGR]], ptr %[[PTR1]], i32 0, i32 0{{$}}
181 // CHECK: store i32 3, ptr %[[FIELD]]
182 // CHECK: %[[FIELD:.*]] = getelementptr inbounds nuw %[[AGGR]], ptr %[[PTR1]], i32 0, i32 1{{$}}
183 // CHECK: store i32 0, ptr %[[FIELD]]
184 // CHECK-NOT: store
185 // CHECK-NOT: memset
186 struct Aggr { int a, b; };
187 new Aggr[2] { 1, 2, 3 };
190 // CHECK-LABEL: define{{.*}} void @_Z15aggr_sufficienti
191 void aggr_sufficient(int n) {
192 // CHECK: icmp ult i32 %{{.*}}, 2
193 // CHECK: %[[MEM:.*]] = call noalias noundef nonnull ptr @_Zna{{.}}(
194 // CHECK: %[[FIELD:.*]] = getelementptr inbounds nuw %[[AGGR:.*]], ptr %[[MEM]], i32 0, i32 0{{$}}
195 // CHECK: store i32 1, ptr %[[FIELD]]
196 // CHECK: %[[FIELD:.*]] = getelementptr inbounds nuw %[[AGGR]], ptr %[[MEM]], i32 0, i32 1{{$}}
197 // CHECK: store i32 2, ptr %[[FIELD]]
198 // CHECK: %[[PTR1:.*]] = getelementptr inbounds %[[AGGR]], ptr %[[MEM]], i32 1{{$}}
199 // CHECK: %[[FIELD:.*]] = getelementptr inbounds nuw %[[AGGR]], ptr %[[PTR1]], i32 0, i32 0{{$}}
200 // CHECK: store i32 3, ptr %[[FIELD]]
201 // CHECK: %[[FIELD:.*]] = getelementptr inbounds nuw %[[AGGR]], ptr %[[PTR1]], i32 0, i32 1{{$}}
202 // CHECK: store i32 0, ptr %[[FIELD]]
203 // CHECK: %[[PTR2:.*]] = getelementptr inbounds %[[AGGR]], ptr %[[PTR1]], i32 1{{$}}
204 // CHECK: %[[REMAIN:.*]] = sub i32 {{.*}}, 16
205 // CHECK: call void @llvm.memset{{.*}}(ptr align {{[0-9]+}} %[[PTR2]], i8 0, i32 %[[REMAIN]],
206 struct Aggr { int a, b; };
207 new Aggr[n] { 1, 2, 3 };
210 // SIO-LABEL: define{{.*}} void @_Z14constexpr_testv
211 void constexpr_test() {
212 // SIO: call noalias noundef nonnull ptr @_Zna{{.}}(i32 noundef 4)
213 new int[0+1]{0};
216 // CHECK-LABEL: define{{.*}} void @_Z13unknown_boundv
217 void unknown_bound() {
218 struct Aggr { int x, y, z; };
219 new Aggr[]{1, 2, 3, 4};
220 // CHECK: call {{.*}}_Znaj(i32 noundef 24)
221 // CHECK: store i32 1
222 // CHECK: store i32 2
223 // CHECK: store i32 3
224 // CHECK: store i32 4
225 // CHECK: store i32 0
226 // CHECK: store i32 0
227 // CHECK-NOT: store
228 // CHECK: }
231 // CHECK-LABEL: define{{.*}} void @_Z20unknown_bound_stringv
232 void unknown_bound_string() {
233 new char[]{"hello"};
234 // CHECK: call {{.*}}_Znaj(i32 noundef 6)
235 // CHECK: memcpy{{.*}} i32 6,