Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / cxx11-initializer-array-new.cpp
blob48ee019a55f555aff3da0890eee613ec5e26700d
1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 %s -emit-llvm -o - | FileCheck %s
3 // PR10878
5 struct S { S(); S(int); ~S(); int n; };
7 void *p = new S[2][3]{ { 1, 2, 3 }, { 4, 5, 6 } };
9 // CHECK-LABEL: define
10 // CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull ptr @_Znam(i64 noundef 32)
11 // CHECK: store i64 6, ptr %[[ALLOC]]
12 // CHECK: %[[START_AS_i8:.*]] = getelementptr inbounds i8, ptr %[[ALLOC]], i64 8
14 // Explicit initializers:
16 // { 1, 2, 3 }
19 // CHECK: %[[S_0_0:.*]] = getelementptr inbounds [3 x %[[S:.*]]], ptr %[[START_AS_i8]], i64 0, i64 0
20 // CHECK: call void @_ZN1SC1Ei(ptr {{[^,]*}} %[[S_0_0]], i32 noundef 1)
21 // CHECK: %[[S_0_1:.*]] = getelementptr inbounds %[[S]], ptr %[[S_0_0]], i64 1
22 // CHECK: call void @_ZN1SC1Ei(ptr {{[^,]*}} %[[S_0_1]], i32 noundef 2)
23 // CHECK: %[[S_0_2:.*]] = getelementptr inbounds %[[S]], ptr %[[S_0_1]], i64 1
24 // CHECK: call void @_ZN1SC1Ei(ptr {{[^,]*}} %[[S_0_2]], i32 noundef 3)
26 // { 4, 5, 6 }
28 // CHECK: %[[S_1:.*]] = getelementptr inbounds [3 x %[[S]]], ptr %[[START_AS_i8]], i64 1
30 // CHECK: %[[S_1_0:.*]] = getelementptr inbounds [3 x %[[S]]], ptr %[[S_1]], i64 0, i64 0
31 // CHECK: call void @_ZN1SC1Ei(ptr {{[^,]*}} %[[S_1_0]], i32 noundef 4)
32 // CHECK: %[[S_1_1:.*]] = getelementptr inbounds %[[S]], ptr %[[S_1_0]], i64 1
33 // CHECK: call void @_ZN1SC1Ei(ptr {{[^,]*}} %[[S_1_1]], i32 noundef 5)
34 // CHECK: %[[S_1_2:.*]] = getelementptr inbounds %[[S]], ptr %[[S_1_1]], i64 1
35 // CHECK: call void @_ZN1SC1Ei(ptr {{[^,]*}} %[[S_1_2]], i32 noundef 6)
37 // CHECK-NOT: br i1
38 // CHECK-NOT: call
39 // CHECK: }
41 int n;
42 void *q = new S[n][3]{ { 1, 2, 3 }, { 4, 5, 6 } };
44 // CHECK-LABEL: define
46 // CHECK: load i32, ptr @n
47 // CHECK: call {{.*}} @llvm.umul.with.overflow.i64(i64 %[[N:.*]], i64 12)
48 // CHECK: %[[ELTS:.*]] = mul i64 %[[N]], 3
49 // CHECK: call {{.*}} @llvm.uadd.with.overflow.i64(i64 %{{.*}}, i64 8)
50 // CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull ptr @_Znam(i64 noundef %{{.*}})
52 // CHECK: store i64 %[[ELTS]], ptr %[[ALLOC]]
53 // CHECK: %[[START_AS_i8:.*]] = getelementptr inbounds i8, ptr %[[ALLOC]], i64 8
55 // Explicit initializers:
57 // { 1, 2, 3 }
60 // CHECK: %[[S_0_0:.*]] = getelementptr inbounds [3 x %[[S]]], ptr %[[START_AS_i8]], i64 0, i64 0
61 // CHECK: call void @_ZN1SC1Ei(ptr {{[^,]*}} %[[S_0_0]], i32 noundef 1)
62 // CHECK: %[[S_0_1:.*]] = getelementptr inbounds %[[S]], ptr %[[S_0_0]], i64 1
63 // CHECK: call void @_ZN1SC1Ei(ptr {{[^,]*}} %[[S_0_1]], i32 noundef 2)
64 // CHECK: %[[S_0_2:.*]] = getelementptr inbounds %[[S]], ptr %[[S_0_1]], i64 1
65 // CHECK: call void @_ZN1SC1Ei(ptr {{[^,]*}} %[[S_0_2]], i32 noundef 3)
67 // { 4, 5, 6 }
69 // CHECK: %[[S_1:.*]] = getelementptr inbounds [3 x %[[S]]], ptr %[[START_AS_i8]], i64 1
71 // CHECK: %[[S_1_0:.*]] = getelementptr inbounds [3 x %[[S]]], ptr %[[S_1]], i64 0, i64 0
72 // CHECK: call void @_ZN1SC1Ei(ptr {{[^,]*}} %[[S_1_0]], i32 noundef 4)
73 // CHECK: %[[S_1_1:.*]] = getelementptr inbounds %[[S]], ptr %[[S_1_0]], i64 1
74 // CHECK: call void @_ZN1SC1Ei(ptr {{[^,]*}} %[[S_1_1]], i32 noundef 5)
75 // CHECK: %[[S_1_2:.*]] = getelementptr inbounds %[[S]], ptr %[[S_1_1]], i64 1
76 // CHECK: call void @_ZN1SC1Ei(ptr {{[^,]*}} %[[S_1_2]], i32 noundef 6)
78 // And the rest.
80 // CHECK: %[[S_2:.*]] = getelementptr inbounds [3 x %[[S]]], ptr %[[S_1]], i64 1
82 // CHECK: %[[REST:.*]] = sub i64 %[[ELTS]], 6
83 // CHECK: icmp eq i64 %[[REST]], 0
84 // CHECK: br i1
86 // CHECK: %[[END:.*]] = getelementptr inbounds %[[S]], ptr %[[S_2]], i64 %[[REST]]
87 // CHECK: br label
89 // CHECK: %[[CUR:.*]] = phi ptr [ %[[S_2]], {{.*}} ], [ %[[NEXT:.*]], {{.*}} ]
90 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} %[[CUR]])
91 // CHECK: %[[NEXT]] = getelementptr inbounds %[[S]], ptr %[[CUR]], i64 1
92 // CHECK: icmp eq ptr %[[NEXT]], %[[END]]
93 // CHECK: br i1
95 // CHECK: }
97 struct T { int a; };
98 void *r = new T[n][3]{ { 1, 2, 3 }, { 4, 5, 6 } };
100 // CHECK-LABEL: define
102 // CHECK: load i32, ptr @n
103 // CHECK: call {{.*}} @llvm.umul.with.overflow.i64(i64 %[[N:.*]], i64 12)
104 // CHECK: %[[ELTS:.*]] = mul i64 %[[N]], 3
106 // No cookie.
107 // CHECK-NOT: @llvm.uadd.with.overflow
109 // CHECK: %[[ALLOC:.*]] = call noalias noundef nonnull ptr @_Znam(i64 noundef %{{.*}})
112 // Explicit initializers:
114 // { 1, 2, 3 }
117 // CHECK: %[[T_0_0:.*]] = getelementptr inbounds [3 x %[[T:.*]]], ptr %[[ALLOC]], i64 0, i64 0
118 // CHECK: %[[T_0_0_0:.*]] = getelementptr inbounds %[[T]], ptr %[[T_0_0]], i32 0, i32 0
119 // CHECK: store i32 1, ptr %[[T_0_0_0]]
120 // CHECK: %[[T_0_1:.*]] = getelementptr inbounds %[[T]], ptr %[[T_0_0]], i64 1
121 // CHECK: %[[T_0_1_0:.*]] = getelementptr inbounds %[[T]], ptr %[[T_0_1]], i32 0, i32 0
122 // CHECK: store i32 2, ptr %[[T_0_1_0]]
123 // CHECK: %[[T_0_2:.*]] = getelementptr inbounds %[[T]], ptr %[[T_0_1]], i64 1
124 // CHECK: %[[T_0_2_0:.*]] = getelementptr inbounds %[[T]], ptr %[[T_0_2]], i32 0, i32 0
125 // CHECK: store i32 3, ptr %[[T_0_2_0]]
127 // { 4, 5, 6 }
129 // CHECK: %[[T_1:.*]] = getelementptr inbounds [3 x %[[T]]], ptr %[[ALLOC]], i64 1
131 // CHECK: %[[T_1_0:.*]] = getelementptr inbounds [3 x %[[T]]], ptr %[[T_1]], i64 0, i64 0
132 // CHECK: %[[T_1_0_0:.*]] = getelementptr inbounds %[[T]], ptr %[[T_1_0]], i32 0, i32 0
133 // CHECK: store i32 4, ptr %[[T_1_0_0]]
134 // CHECK: %[[T_1_1:.*]] = getelementptr inbounds %[[T]], ptr %[[T_1_0]], i64 1
135 // CHECK: %[[T_1_1_0:.*]] = getelementptr inbounds %[[T]], ptr %[[T_1_1]], i32 0, i32 0
136 // CHECK: store i32 5, ptr %[[T_1_1_0]]
137 // CHECK: %[[T_1_2:.*]] = getelementptr inbounds %[[T]], ptr %[[T_1_1]], i64 1
138 // CHECK: %[[T_1_2_0:.*]] = getelementptr inbounds %[[T]], ptr %[[T_1_2]], i32 0, i32 0
139 // CHECK: store i32 6, ptr %[[T_1_2_0]]
141 // And the rest gets memset to 0.
143 // CHECK: %[[T_2:.*]] = getelementptr inbounds [3 x %[[T]]], ptr %[[T_1]], i64 1
145 // CHECK: %[[SIZE:.*]] = sub i64 %{{.*}}, 24
146 // CHECK: call void @llvm.memset.p0.i64(ptr align 4 %[[T_2]], i8 0, i64 %[[SIZE]], i1 false)
148 // CHECK: }