• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 %s -emit-llvm -o - | FileCheck %s
2 
3 // PR10878
4 
5 struct S { S(); S(int); ~S(); int n; };
6 
7 void *p = new S[2][3]{ { 1, 2, 3 }, { 4, 5, 6 } };
8 
9 // CHECK-LABEL: define
10 // CHECK: %[[ALLOC:.*]] = call i8* @_Znam(i64 32)
11 // CHECK: %[[COOKIE:.*]] = bitcast i8* %[[ALLOC]] to i64*
12 // CHECK: store i64 6, i64* %[[COOKIE]]
13 // CHECK: %[[START_AS_i8:.*]] = getelementptr inbounds i8, i8* %[[ALLOC]], i64 8
14 // CHECK: %[[START_AS_S:.*]] = bitcast i8* %[[START_AS_i8]] to %[[S:.*]]*
15 //
16 // Explicit initializers:
17 //
18 // { 1, 2, 3 }
19 //
20 // CHECK: %[[S_0:.*]] = bitcast %[[S]]* %[[START_AS_S]] to [3 x %[[S]]]*
21 //
22 // CHECK: %[[S_0_0:.*]] = getelementptr inbounds [3 x %[[S]]], [3 x %[[S]]]* %[[S_0]], i64 0, i64 0
23 // CHECK: call void @_ZN1SC1Ei(%[[S]]* %[[S_0_0]], i32 1)
24 // CHECK: %[[S_0_1:.*]] = getelementptr inbounds %[[S]], %[[S]]* %[[S_0_0]], i64 1
25 // CHECK: call void @_ZN1SC1Ei(%[[S]]* %[[S_0_1]], i32 2)
26 // CHECK: %[[S_0_2:.*]] = getelementptr inbounds %[[S]], %[[S]]* %[[S_0_1]], i64 1
27 // CHECK: call void @_ZN1SC1Ei(%[[S]]* %[[S_0_2]], i32 3)
28 //
29 // { 4, 5, 6 }
30 //
31 // CHECK: %[[S_1:.*]] = getelementptr inbounds [3 x %[[S]]], [3 x %[[S]]]* %[[S_0]], i64 1
32 //
33 // CHECK: %[[S_1_0:.*]] = getelementptr inbounds [3 x %[[S]]], [3 x %[[S]]]* %[[S_1]], i64 0, i64 0
34 // CHECK: call void @_ZN1SC1Ei(%[[S]]* %[[S_1_0]], i32 4)
35 // CHECK: %[[S_1_1:.*]] = getelementptr inbounds %[[S]], %[[S]]* %[[S_1_0]], i64 1
36 // CHECK: call void @_ZN1SC1Ei(%[[S]]* %[[S_1_1]], i32 5)
37 // CHECK: %[[S_1_2:.*]] = getelementptr inbounds %[[S]], %[[S]]* %[[S_1_1]], i64 1
38 // CHECK: call void @_ZN1SC1Ei(%[[S]]* %[[S_1_2]], i32 6)
39 //
40 // CHECK-NOT: br i1
41 // CHECK-NOT: call
42 // CHECK: }
43 
44 int n;
45 void *q = new S[n][3]{ { 1, 2, 3 }, { 4, 5, 6 } };
46 
47 // CHECK-LABEL: define
48 //
49 // CHECK: load i32, i32* @n
50 // CHECK: call {{.*}} @llvm.umul.with.overflow.i64(i64 %[[N:.*]], i64 12)
51 // CHECK: %[[ELTS:.*]] = mul i64 %[[N]], 3
52 // CHECK: call {{.*}} @llvm.uadd.with.overflow.i64(i64 %{{.*}}, i64 8)
53 // CHECK: %[[ALLOC:.*]] = call i8* @_Znam(i64 %{{.*}})
54 //
55 // CHECK: %[[COOKIE:.*]] = bitcast i8* %[[ALLOC]] to i64*
56 // CHECK: store i64 %[[ELTS]], i64* %[[COOKIE]]
57 // CHECK: %[[START_AS_i8:.*]] = getelementptr inbounds i8, i8* %[[ALLOC]], i64 8
58 // CHECK: %[[START_AS_S:.*]] = bitcast i8* %[[START_AS_i8]] to %[[S]]*
59 //
60 // Explicit initializers:
61 //
62 // { 1, 2, 3 }
63 //
64 // CHECK: %[[S_0:.*]] = bitcast %[[S]]* %[[START_AS_S]] to [3 x %[[S]]]*
65 //
66 // CHECK: %[[S_0_0:.*]] = getelementptr inbounds [3 x %[[S]]], [3 x %[[S]]]* %[[S_0]], i64 0, i64 0
67 // CHECK: call void @_ZN1SC1Ei(%[[S]]* %[[S_0_0]], i32 1)
68 // CHECK: %[[S_0_1:.*]] = getelementptr inbounds %[[S]], %[[S]]* %[[S_0_0]], i64 1
69 // CHECK: call void @_ZN1SC1Ei(%[[S]]* %[[S_0_1]], i32 2)
70 // CHECK: %[[S_0_2:.*]] = getelementptr inbounds %[[S]], %[[S]]* %[[S_0_1]], i64 1
71 // CHECK: call void @_ZN1SC1Ei(%[[S]]* %[[S_0_2]], i32 3)
72 //
73 // { 4, 5, 6 }
74 //
75 // CHECK: %[[S_1:.*]] = getelementptr inbounds [3 x %[[S]]], [3 x %[[S]]]* %[[S_0]], i64 1
76 //
77 // CHECK: %[[S_1_0:.*]] = getelementptr inbounds [3 x %[[S]]], [3 x %[[S]]]* %[[S_1]], i64 0, i64 0
78 // CHECK: call void @_ZN1SC1Ei(%[[S]]* %[[S_1_0]], i32 4)
79 // CHECK: %[[S_1_1:.*]] = getelementptr inbounds %[[S]], %[[S]]* %[[S_1_0]], i64 1
80 // CHECK: call void @_ZN1SC1Ei(%[[S]]* %[[S_1_1]], i32 5)
81 // CHECK: %[[S_1_2:.*]] = getelementptr inbounds %[[S]], %[[S]]* %[[S_1_1]], i64 1
82 // CHECK: call void @_ZN1SC1Ei(%[[S]]* %[[S_1_2]], i32 6)
83 //
84 // And the rest.
85 //
86 // CHECK: %[[S_2:.*]] = getelementptr inbounds [3 x %[[S]]], [3 x %[[S]]]* %[[S_1]], i64 1
87 // CHECK: %[[S_2_AS_S:.*]] = bitcast [3 x %[[S]]]* %[[S_2]] to %[[S]]*
88 //
89 // CHECK: %[[REST:.*]] = sub i64 %[[ELTS]], 6
90 // CHECK: icmp eq i64 %[[REST]], 0
91 // CHECK: br i1
92 //
93 // CHECK: %[[END:.*]] = getelementptr inbounds %[[S]], %[[S]]* %[[S_2_AS_S]], i64 %[[REST]]
94 // CHECK: br label
95 //
96 // CHECK: %[[CUR:.*]] = phi %[[S]]* [ %[[S_2_AS_S]], {{.*}} ], [ %[[NEXT:.*]], {{.*}} ]
97 // CHECK: call void @_ZN1SC1Ev(%[[S]]* %[[CUR]])
98 // CHECK: %[[NEXT]] = getelementptr inbounds %[[S]], %[[S]]* %[[CUR]], i64 1
99 // CHECK: icmp eq %[[S]]* %[[NEXT]], %[[END]]
100 // CHECK: br i1
101 //
102 // CHECK: }
103 
104 struct T { int a; };
105 void *r = new T[n][3]{ { 1, 2, 3 }, { 4, 5, 6 } };
106 
107 // CHECK-LABEL: define
108 //
109 // CHECK: load i32, i32* @n
110 // CHECK: call {{.*}} @llvm.umul.with.overflow.i64(i64 %[[N:.*]], i64 12)
111 // CHECK: %[[ELTS:.*]] = mul i64 %[[N]], 3
112 //
113 // No cookie.
114 // CHECK-NOT: @llvm.uadd.with.overflow
115 //
116 // CHECK: %[[ALLOC:.*]] = call i8* @_Znam(i64 %{{.*}})
117 //
118 // CHECK: %[[START_AS_T:.*]] = bitcast i8* %[[ALLOC]] to %[[T:.*]]*
119 //
120 // Explicit initializers:
121 //
122 // { 1, 2, 3 }
123 //
124 // CHECK: %[[T_0:.*]] = bitcast %[[T]]* %[[START_AS_T]] to [3 x %[[T]]]*
125 //
126 // CHECK: %[[T_0_0:.*]] = getelementptr inbounds [3 x %[[T]]], [3 x %[[T]]]* %[[T_0]], i64 0, i64 0
127 // CHECK: %[[T_0_0_0:.*]] = getelementptr inbounds %[[T]], %[[T]]* %[[T_0_0]], i32 0, i32 0
128 // CHECK: store i32 1, i32* %[[T_0_0_0]]
129 // CHECK: %[[T_0_1:.*]] = getelementptr inbounds %[[T]], %[[T]]* %[[T_0_0]], i64 1
130 // CHECK: %[[T_0_1_0:.*]] = getelementptr inbounds %[[T]], %[[T]]* %[[T_0_1]], i32 0, i32 0
131 // CHECK: store i32 2, i32* %[[T_0_1_0]]
132 // CHECK: %[[T_0_2:.*]] = getelementptr inbounds %[[T]], %[[T]]* %[[T_0_1]], i64 1
133 // CHECK: %[[T_0_2_0:.*]] = getelementptr inbounds %[[T]], %[[T]]* %[[T_0_2]], i32 0, i32 0
134 // CHECK: store i32 3, i32* %[[T_0_2_0]]
135 //
136 // { 4, 5, 6 }
137 //
138 // CHECK: %[[T_1:.*]] = getelementptr inbounds [3 x %[[T]]], [3 x %[[T]]]* %[[T_0]], i64 1
139 //
140 // CHECK: %[[T_1_0:.*]] = getelementptr inbounds [3 x %[[T]]], [3 x %[[T]]]* %[[T_1]], i64 0, i64 0
141 // CHECK: %[[T_1_0_0:.*]] = getelementptr inbounds %[[T]], %[[T]]* %[[T_1_0]], i32 0, i32 0
142 // CHECK: store i32 4, i32* %[[T_1_0_0]]
143 // CHECK: %[[T_1_1:.*]] = getelementptr inbounds %[[T]], %[[T]]* %[[T_1_0]], i64 1
144 // CHECK: %[[T_1_1_0:.*]] = getelementptr inbounds %[[T]], %[[T]]* %[[T_1_1]], i32 0, i32 0
145 // CHECK: store i32 5, i32* %[[T_1_1_0]]
146 // CHECK: %[[T_1_2:.*]] = getelementptr inbounds %[[T]], %[[T]]* %[[T_1_1]], i64 1
147 // CHECK: %[[T_1_2_0:.*]] = getelementptr inbounds %[[T]], %[[T]]* %[[T_1_2]], i32 0, i32 0
148 // CHECK: store i32 6, i32* %[[T_1_2_0]]
149 //
150 // And the rest gets memset to 0.
151 //
152 // CHECK: %[[T_2:.*]] = getelementptr inbounds [3 x %[[T]]], [3 x %[[T]]]* %[[T_1]], i64 1
153 // CHECK: %[[T_2_AS_T:.*]] = bitcast [3 x %[[T]]]* %[[T_2]] to %[[T]]*
154 //
155 // CHECK: %[[SIZE:.*]] = sub i64 %{{.*}}, 24
156 // CHECK: %[[REST:.*]] = bitcast %[[T]]* %[[T_2_AS_T]] to i8*
157 // CHECK: call void @llvm.memset.p0i8.i64(i8* %[[REST]], i8 0, i64 %[[SIZE]], i32 4, i1 false)
158 //
159 // CHECK: }
160 
161