blob: 6310943d2efcb348b876133e5e27e762a226cab6 [file] [log] [blame]
Akira Hatanakaceb66522018-03-13 23:37:51 +00001// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-llvm -o - -DUSESTRUCT -I %S/Inputs %s | FileCheck %s
Akira Hatanaka34fb2642018-03-13 18:58:25 +00002
Akira Hatanakaceb66522018-03-13 23:37:51 +00003// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-pch -I %S/Inputs -o %t %s
4// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -include-pch %t -emit-llvm -o - -DUSESTRUCT -I %S/Inputs %s | FileCheck %s
Akira Hatanaka34fb2642018-03-13 18:58:25 +00005
6#ifndef HEADER
7#define HEADER
Akira Hatanakaceb66522018-03-13 23:37:51 +00008#include "strong_in_union.h"
Akira Hatanaka7275da02018-02-28 07:15:55 +00009
10typedef void (^BlockTy)(void);
11
12typedef struct {
13 int a[4];
14} Trivial;
15
16typedef struct {
17 Trivial f0;
18 id f1;
19} Strong;
20
21typedef struct {
22 int i;
23 id f1;
24} StrongSmall;
25
26typedef struct {
27 Strong f0;
28 id f1;
29 double d;
30} StrongOuter;
31
32typedef struct {
33 int f0;
34 volatile id f1;
35} StrongVolatile;
36
37typedef struct {
38 BlockTy f0;
39} StrongBlock;
40
41typedef struct {
42 int i;
43 id f0[2][2];
44} IDArray;
45
46typedef struct {
47 double d;
48 Strong f0[2][2];
49} StructArray;
50
51typedef struct {
52 id f0;
53 int i : 9;
54} Bitfield0;
55
56typedef struct {
57 char c;
58 int i0 : 2;
59 int i1 : 4;
60 id f0;
61 int i2 : 31;
62 int i3 : 1;
63 id f1;
64 int : 0;
65 int a[3];
66 id f2;
67 double d;
68 int i4 : 1;
69 volatile int i5 : 2;
70 volatile char i6;
71} Bitfield1;
72
Akira Hatanaka34fb2642018-03-13 18:58:25 +000073#endif
74
75#ifdef USESTRUCT
76
Akira Hatanaka7275da02018-02-28 07:15:55 +000077StrongSmall getStrongSmall(void);
78StrongOuter getStrongOuter(void);
79void calleeStrongSmall(StrongSmall);
80void func(Strong *);
81
82// CHECK: %[[STRUCT_BITFIELD1:.*]] = type { i8, i8, i8*, i32, i8*, [3 x i32], i8*, double, i8, i8 }
83
84// CHECK: define void @test_constructor_destructor_StrongOuter()
85// CHECK: %[[T:.*]] = alloca %[[STRUCT_STRONGOUTER:.*]], align 8
86// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8**
87// CHECK: call void @__default_constructor_8_s16_s24(i8** %[[V0]])
88// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8**
89// CHECK: call void @__destructor_8_s16_s24(i8** %[[V1]])
90// CHECK: ret void
91
92// CHECK: define linkonce_odr hidden void @__default_constructor_8_s16_s24(i8** %[[DST:.*]])
93// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
94// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
95// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
96// CHECK: call void @__default_constructor_8_s16(i8** %[[V0]])
97// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
98// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 24
99// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
100// CHECK: %[[V4:.*]] = bitcast i8** %[[V3]] to i8*
101// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V4]], i8 0, i64 8, i1 false)
102// CHECK: ret void
103
104// CHECK: define linkonce_odr hidden void @__default_constructor_8_s16(i8** %[[DST:.*]])
105// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
106// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
107// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
108// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
109// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 16
110// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
111// CHECK: %[[V4:.*]] = bitcast i8** %[[V3]] to i8*
112// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V4]], i8 0, i64 8, i1 false)
113// CHECK: ret void
114
115// CHECK: define linkonce_odr hidden void @__destructor_8_s16_s24(i8** %[[DST:.*]])
116// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
117// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
118// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
119// CHECK: call void @__destructor_8_s16(i8** %[[V0]])
120// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
121// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 24
122// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
123// CHECK: call void @objc_storeStrong(i8** %[[V3]], i8* null)
124// CHECK: ret void
125
126// CHECK: define linkonce_odr hidden void @__destructor_8_s16(i8** %[[DST:.*]])
127// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
128// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
129// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
130// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
131// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 16
132// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
133// CHECK: call void @objc_storeStrong(i8** %[[V3]], i8* null)
134// CHECK: ret void
135
136void test_constructor_destructor_StrongOuter(void) {
137 StrongOuter t;
138}
139
140// CHECK: define void @test_copy_constructor_StrongOuter(%[[STRUCT_STRONGOUTER:.*]]* %[[S:.*]])
141// CHECK: %[[S_ADDR:.*]] = alloca %[[STRUCT_STRONGOUTER]]*, align 8
142// CHECK: %[[T:.*]] = alloca %[[STRUCT_STRONGOUTER]], align 8
143// CHECK: store %[[STRUCT_STRONGOUTER]]* %[[S]], %[[STRUCT_STRONGOUTER]]** %[[S_ADDR]], align 8
144// CHECK: %[[V0:.*]] = load %[[STRUCT_STRONGOUTER]]*, %[[STRUCT_STRONGOUTER]]** %[[S_ADDR]], align 8
145// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8**
146// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[V0]] to i8**
147// CHECK: call void @__copy_constructor_8_8_t0w16_s16_s24_t32w8(i8** %[[V1]], i8** %[[V2]])
148// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8**
149// CHECK: call void @__destructor_8_s16_s24(i8** %[[V3]])
150// CHECK: ret void
151
152// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])
153// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
154// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
155// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
156// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
157// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
158// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
159// CHECK: call void @__copy_constructor_8_8_t0w16_s16(i8** %[[V0]], i8** %[[V1]])
160// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
161// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24
162// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
163// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8*
164// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24
165// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**
166// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8
167// CHECK: %[[V9:.*]] = call i8* @objc_retain(i8* %[[V8]])
168// CHECK: store i8* %[[V9]], i8** %[[V4]], align 8
169// CHECK: %[[V10:.*]] = bitcast i8** %[[V0]] to i8*
170// CHECK: %[[V11:.*]] = getelementptr inbounds i8, i8* %[[V10]], i64 32
171// CHECK: %[[V12:.*]] = bitcast i8* %[[V11]] to i8**
172// CHECK: %[[V13:.*]] = bitcast i8** %[[V1]] to i8*
173// CHECK: %[[V14:.*]] = getelementptr inbounds i8, i8* %[[V13]], i64 32
174// CHECK: %[[V15:.*]] = bitcast i8* %[[V14]] to i8**
175// CHECK: %[[V16:.*]] = bitcast i8** %[[V12]] to i64*
176// CHECK: %[[V17:.*]] = bitcast i8** %[[V15]] to i64*
177// CHECK: %[[V18:.*]] = load i64, i64* %[[V17]], align 8
178// CHECK: store i64 %[[V18]], i64* %[[V16]], align 8
179// CHECK: ret void
180
181// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w16_s16(i8** %[[DST:.*]], i8** %[[SRC:.*]])
182// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
183// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
184// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
185// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
186// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
187// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
188// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
189// CHECK: %[[V3:.*]] = bitcast i8** %[[V1]] to i8*
190// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[V2]], i8* align 8 %[[V3]], i64 16, i1 false)
191// CHECK: %[[V4:.*]] = bitcast i8** %[[V0]] to i8*
192// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 16
193// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to i8**
194// CHECK: %[[V7:.*]] = bitcast i8** %[[V1]] to i8*
195// CHECK: %[[V8:.*]] = getelementptr inbounds i8, i8* %[[V7]], i64 16
196// CHECK: %[[V9:.*]] = bitcast i8* %[[V8]] to i8**
197// CHECK: %[[V10:.*]] = load i8*, i8** %[[V9]], align 8
198// CHECK: %[[V11:.*]] = call i8* @objc_retain(i8* %[[V10]])
199// CHECK: store i8* %[[V11]], i8** %[[V6]], align 8
200// CHECK: ret void
201
202void test_copy_constructor_StrongOuter(StrongOuter *s) {
203 StrongOuter t = *s;
204}
205
206/// CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])
207// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
208// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
209// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
210// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
211// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
212// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
213// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
214// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24
215// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
216// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8*
217// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24
218// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**
219// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8
220// CHECK: call void @objc_storeStrong(i8** %[[V4]], i8* %[[V8]])
221
222void test_copy_assignment_StrongOuter(StrongOuter *d, StrongOuter *s) {
223 *d = *s;
224}
225
226// CHECK: define void @test_move_constructor_StrongOuter()
227// CHECK: %[[T1:.*]] = getelementptr inbounds %[[STRUCT_BLOCK_BYREF_T:.*]], %[[STRUCT_BLOCK_BYREF_T]]* %{{.*}}, i32 0, i32 7
228// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T1]] to i8**
229// CHECK: call void @__default_constructor_8_s16_s24(i8** %[[V1]])
230// CHECK: %[[T2:.*]] = getelementptr inbounds %[[STRUCT_BLOCK_BYREF_T]], %[[STRUCT_BLOCK_BYREF_T]]* %{{.*}}, i32 0, i32 7
231// CHECK: %[[V9:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T2]] to i8**
232// CHECK: call void @__destructor_8_s16_s24(i8** %[[V9]])
233
234// CHECK: define internal void @__Block_byref_object_copy_(i8*, i8*)
235// CHECK: call void @__move_constructor_8_8_t0w16_s16_s24_t32w8(
236
237// CHECK: define linkonce_odr hidden void @__move_constructor_8_8_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])
238// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
239// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
240// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
241// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
242// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
243// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
244// CHECK: call void @__move_constructor_8_8_t0w16_s16(i8** %[[V0]], i8** %[[V1]])
245// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
246// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24
247// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
248// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8*
249// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24
250// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**
251// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8
252// CHECK: store i8* null, i8** %[[V7]], align 8
253// CHECK: store i8* %[[V8]], i8** %[[V4]], align 8
254
255// CHECK: define internal void @__Block_byref_object_dispose_(i8*)
256// CHECK: call void @__destructor_8_s16_s24(
257
258void test_move_constructor_StrongOuter(void) {
259 __block StrongOuter t;
260 BlockTy b = ^{ (void)t; };
261}
262
263// CHECK: define linkonce_odr hidden void @__move_assignment_8_8_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])
264// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
265// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
266// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
267// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
268// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
269// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
270// CHECK: call void @__move_assignment_8_8_t0w16_s16(i8** %[[V0]], i8** %[[V1]])
271// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
272// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24
273// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
274// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8*
275// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24
276// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**
277// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8
278// CHECK: store i8* null, i8** %[[V7]], align 8
279// CHECK: %[[V9:.*]] = load i8*, i8** %[[V4]], align 8
280// CHECK: store i8* %[[V8]], i8** %[[V4]], align 8
281// CHECK: call void @objc_release(i8* %[[V9]])
282
283void test_move_assignment_StrongOuter(StrongOuter *p) {
284 *p = getStrongOuter();
285}
286
287// CHECK: define void @test_parameter_StrongSmall([2 x i64] %[[A_COERCE:.*]])
288// CHECK: %[[A:.*]] = alloca %[[STRUCT_STRONG:.*]], align 8
289// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONG]]* %[[A]] to [2 x i64]*
290// CHECK: store [2 x i64] %[[A_COERCE]], [2 x i64]* %[[V0]], align 8
291// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONG]]* %[[A]] to i8**
292// CHECK: call void @__destructor_8_s8(i8** %[[V1]])
293// CHECK: ret void
294
295void test_parameter_StrongSmall(StrongSmall a) {
296}
297
298// CHECK: define void @test_argument_StrongSmall([2 x i64] %[[A_COERCE:.*]])
299// CHECK: %[[A:.*]] = alloca %[[STRUCT_STRONGSMALL:.*]], align 8
300// CHECK: %[[TEMP_LVALUE:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
301// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to [2 x i64]*
302// CHECK: store [2 x i64] %[[A_COERCE]], [2 x i64]* %[[V0]], align 8
303// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TEMP_LVALUE]] to i8**
304// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
305// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V1]], i8** %[[V2]])
306// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TEMP_LVALUE]] to [2 x i64]*
307// CHECK: %[[V4:.*]] = load [2 x i64], [2 x i64]* %[[V3]], align 8
308// CHECK: call void @calleeStrongSmall([2 x i64] %[[V4]])
309// CHECK: %[[V5:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
310// CHECK: call void @__destructor_8_s8(i8** %[[V5]])
311// CHECK: ret void
312
313void test_argument_StrongSmall(StrongSmall a) {
314 calleeStrongSmall(a);
315}
316
317// CHECK: define [2 x i64] @test_return_StrongSmall([2 x i64] %[[A_COERCE:.*]])
318// CHECK: %[[RETVAL:.*]] = alloca %[[STRUCT_STRONGSMALL:.*]], align 8
319// CHECK: %[[A:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
320// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to [2 x i64]*
321// CHECK: store [2 x i64] %[[A_COERCE]], [2 x i64]* %[[V0]], align 8
322// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[RETVAL]] to i8**
323// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
324// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V1]], i8** %[[V2]])
325// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
326// CHECK: call void @__destructor_8_s8(i8** %[[V3]])
327// CHECK: %[[V4:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[RETVAL]] to [2 x i64]*
328// CHECK: %[[V5:.*]] = load [2 x i64], [2 x i64]* %[[V4]], align 8
329// CHECK: ret [2 x i64] %[[V5]]
330
331StrongSmall test_return_StrongSmall(StrongSmall a) {
332 return a;
333}
334
335// CHECK: define void @test_destructor_ignored_result()
336// CHECK: %[[COERCE:.*]] = alloca %[[STRUCT_STRONGSMALL:.*]], align 8
337// CHECK: %[[CALL:.*]] = call [2 x i64] @getStrongSmall()
338// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to [2 x i64]*
339// CHECK: store [2 x i64] %[[CALL]], [2 x i64]* %[[V0]], align 8
340// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to i8**
341// CHECK: call void @__destructor_8_s8(i8** %[[V1]])
342// CHECK: ret void
343
344void test_destructor_ignored_result(void) {
345 getStrongSmall();
346}
347
348// CHECK: define void @test_copy_constructor_StrongBlock(
349// CHECK: call void @__copy_constructor_8_8_sb0(
350// CHECK: call void @__destructor_8_sb0(
351// CHECK: ret void
352
353// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_sb0(i8** %[[DST:.*]], i8** %[[SRC:.*]])
354// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
355// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
356// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
357// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
358// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
359// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
360// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8
361// CHECK: %[[V3:.*]] = call i8* @objc_retainBlock(i8* %[[V2]])
362// CHECK: store i8* %[[V3]], i8** %[[V0]], align 8
363// CHECK: ret void
364
365void test_copy_constructor_StrongBlock(StrongBlock *s) {
366 StrongBlock t = *s;
367}
368
369// CHECK: define void @test_copy_assignment_StrongBlock(%[[STRUCT_STRONGBLOCK:.*]]* %[[D:.*]], %[[STRUCT_STRONGBLOCK]]* %[[S:.*]])
370// CHECK: call void @__copy_assignment_8_8_sb0(
371
372// CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_sb0(i8** %[[DST:.*]], i8** %[[SRC:.*]])
373// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
374// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
375// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
376// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
377// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
378// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
379// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8
380// CHECK: %[[V3:.*]] = call i8* @objc_retainBlock(i8* %[[V2]])
381// CHECK: %[[V4:.*]] = load i8*, i8** %[[V0]], align 8
382// CHECK: store i8* %[[V3]], i8** %[[V0]], align 8
383// CHECK: call void @objc_release(i8* %[[V4]])
384// CHECK: ret void
385
386void test_copy_assignment_StrongBlock(StrongBlock *d, StrongBlock *s) {
387 *d = *s;
388}
389
390// CHECK: define void @test_copy_constructor_StrongVolatile0(
391// CHECK: call void @__copy_constructor_8_8_t0w4_sv8(
392// CHECK: call void @__destructor_8_sv8(
393
394// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w4_sv8(
395// CHECK: %[[V8:.*]] = load volatile i8*, i8** %{{.*}}, align 8
396// CHECK: %[[V9:.*]] = call i8* @objc_retain(i8* %[[V8]])
397// CHECK: store volatile i8* %[[V9]], i8** %{{.*}}, align 8
398
399void test_copy_constructor_StrongVolatile0(StrongVolatile *s) {
400 StrongVolatile t = *s;
401}
402
403// CHECK: define void @test_copy_constructor_StrongVolatile1(
404// CHECK: call void @__copy_constructor_8_8_tv0w128_sv16(
405
406void test_copy_constructor_StrongVolatile1(Strong *s) {
407 volatile Strong t = *s;
408}
409
410// CHECK: define void @test_block_capture_Strong()
411// CHECK: call void @__default_constructor_8_s16(
412// CHECK: call void @__copy_constructor_8_8_t0w16_s16(
413// CHECK: call void @__destructor_8_s16(
414// CHECK: call void @__destructor_8_s16(
415// CHECK: ret void
416
417// CHECK: define internal void @__copy_helper_block_.1(i8*, i8*)
418// CHECK: call void @__copy_constructor_8_8_t0w16_s16(
419// CHECK: ret void
420
421// CHECK: define internal void @__destroy_helper_block_.2(
422// CHECK: call void @__destructor_8_s16(
423// CHECK: ret void
424
425void test_block_capture_Strong(void) {
426 Strong t;
427 BlockTy b = ^(){ (void)t; };
428}
429
430// CHECK: define void @test_variable_length_array(i32 %[[N:.*]])
431// CHECK: %[[N_ADDR:.*]] = alloca i32, align 4
432// CHECK: store i32 %[[N]], i32* %[[N_ADDR]], align 4
433// CHECK: %[[V0:.*]] = load i32, i32* %[[N_ADDR]], align 4
434// CHECK: %[[V1:.*]] = zext i32 %[[V0]] to i64
435// CHECK: %[[VLA:.*]] = alloca %[[STRUCT_STRONG:.*]], i64 %[[V1]], align 8
436// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONG]]* %[[VLA]] to i8**
437// CHECK: %[[V4:.*]] = mul nuw i64 24, %[[V1]]
438// CHECK: %[[V5:.*]] = bitcast i8** %[[V3]] to i8*
439// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 %[[V4]]
440// CHECK: %[[DSTARRAY_END:.*]] = bitcast i8* %[[V6]] to i8**
441// CHECK: br label
442
443// CHECK: %[[DSTADDR_CUR:.*]] = phi i8** [ %[[V3]], {{.*}} ], [ %[[V7:.*]], {{.*}} ]
444// CHECK: %[[DONE:.*]] = icmp eq i8** %[[DSTADDR_CUR]], %[[DSTARRAY_END]]
445// CHECK: br i1 %[[DONE]], label
446
447// CHECK: call void @__default_constructor_8_s16(i8** %[[DSTADDR_CUR]])
448// CHECK: %[[V8:.*]] = bitcast i8** %[[DSTADDR_CUR]] to i8*
449// CHECK: %[[V9:.*]] = getelementptr inbounds i8, i8* %[[V8]], i64 24
450// CHECK: %[[V7]] = bitcast i8* %[[V9]] to i8**
451// CHECK: br label
452
453// CHECK: call void @func(%[[STRUCT_STRONG]]* %[[VLA]])
454// CHECK: %[[V10:.*]] = getelementptr inbounds %[[STRUCT_STRONG]], %[[STRUCT_STRONG]]* %[[VLA]], i64 %[[V1]]
455// CHECK: %[[ARRAYDESTROY_ISEMPTY:.*]] = icmp eq %[[STRUCT_STRONG]]* %[[VLA]], %[[V10]]
456// CHECK: br i1 %[[ARRAYDESTROY_ISEMPTY]], label
457
458// CHECK: %[[ARRAYDESTROY_ELEMENTPAST:.*]] = phi %[[STRUCT_STRONG]]* [ %[[V10]], {{.*}} ], [ %[[ARRAYDESTROY_ELEMENT:.*]], {{.*}} ]
459// CHECK: %[[ARRAYDESTROY_ELEMENT]] = getelementptr inbounds %[[STRUCT_STRONG]], %[[STRUCT_STRONG]]* %[[ARRAYDESTROY_ELEMENTPAST]], i64 -1
460// CHECK: %[[V11:.*]] = bitcast %[[STRUCT_STRONG]]* %[[ARRAYDESTROY_ELEMENT]] to i8**
461// CHECK: call void @__destructor_8_s16(i8** %[[V11]])
462// CHECK: %[[ARRAYDESTROY_DONE:.*]] = icmp eq %[[STRUCT_STRONG]]* %[[ARRAYDESTROY_ELEMENT]], %[[VLA]]
463// CHECK: br i1 %[[ARRAYDESTROY_DONE]], label
464
465// CHECK: ret void
466
467void test_variable_length_array(int n) {
468 Strong a[n];
469 func(a);
470}
471
472// CHECK: define linkonce_odr hidden void @__default_constructor_8_AB8s8n4_s8_AE(
473// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %{{.*}}, i8 0, i64 32, i1 false)
474void test_constructor_destructor_IDArray(void) {
475 IDArray t;
476}
477
478// CHECK: define linkonce_odr hidden void @__default_constructor_8_AB8s24n4_s24_AE(
479void test_constructor_destructor_StructArray(void) {
480 StructArray t;
481}
482
483// Check that IRGen copies the 9-bit bitfield emitting i16 load and store.
484
485// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_s0_t8w2(
486// CHECK: %[[V4:.*]] = bitcast i8** %{{.*}} to i8*
487// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 8
488// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to i8**
489// CHECK: %[[V7:.*]] = bitcast i8** %{{.*}} to i8*
490// CHECK: %[[V8:.*]] = getelementptr inbounds i8, i8* %[[V7]], i64 8
491// CHECK: %[[V9:.*]] = bitcast i8* %[[V8]] to i8**
492// CHECK: %[[V10:.*]] = bitcast i8** %[[V6]] to i16*
493// CHECK: %[[V11:.*]] = bitcast i8** %[[V9]] to i16*
494// CHECK: %[[V12:.*]] = load i16, i16* %[[V11]], align 8
495// CHECK: store i16 %[[V12]], i16* %[[V10]], align 8
496// CHECK: ret void
497
498void test_copy_constructor_Bitfield0(Bitfield0 *a) {
499 Bitfield0 t = *a;
500}
501
502// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w2_s8_t16w4_s24_t32w12_s48_t56w9_tv513w2_tv520w8
503// CHECK: %[[V4:.*]] = load i16, i16* %{{.*}}, align 8
504// CHECK: store i16 %[[V4]], i16* %{{.*}}, align 8
505// CHECK: %[[V21:.*]] = load i32, i32* %{{.*}}, align 8
506// CHECK: store i32 %[[V21]], i32* %{{.*}}, align 8
507// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i64 12, i1 false)
508// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i64 9, i1 false)
509// CHECK: %[[V54:.*]] = bitcast i8** %[[V0:.*]] to %[[STRUCT_BITFIELD1]]*
510// CHECK: %[[I5:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V54]], i32 0, i32 8
511// CHECK: %[[V55:.*]] = bitcast i8** %[[V1:.*]] to %[[STRUCT_BITFIELD1]]*
512// CHECK: %[[I51:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V55]], i32 0, i32 8
513// CHECK: %[[BF_LOAD:.*]] = load volatile i8, i8* %[[I51]], align 8
514// CHECK: %[[BF_SHL:.*]] = shl i8 %[[BF_LOAD]], 5
515// CHECK: %[[BF_ASHR:.*]] = ashr i8 %[[BF_SHL]], 6
516// CHECK: %[[BF_CAST:.*]] = sext i8 %[[BF_ASHR]] to i32
517// CHECK: %[[V56:.*]] = trunc i32 %[[BF_CAST]] to i8
518// CHECK: %[[BF_LOAD2:.*]] = load volatile i8, i8* %[[I5]], align 8
519// CHECK: %[[BF_VALUE:.*]] = and i8 %[[V56]], 3
520// CHECK: %[[BF_SHL3:.*]] = shl i8 %[[BF_VALUE]], 1
521// CHECK: %[[BF_CLEAR:.*]] = and i8 %[[BF_LOAD2]], -7
522// CHECK: %[[BF_SET:.*]] = or i8 %[[BF_CLEAR]], %[[BF_SHL3]]
523// CHECK: store volatile i8 %[[BF_SET]], i8* %[[I5]], align 8
524// CHECK: %[[V57:.*]] = bitcast i8** %[[V0]] to %[[STRUCT_BITFIELD1]]*
525// CHECK: %[[I6:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V57]], i32 0, i32 9
526// CHECK: %[[V58:.*]] = bitcast i8** %[[V1]] to %[[STRUCT_BITFIELD1]]*
527// CHECK: %[[I64:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V58]], i32 0, i32 9
528// CHECK: %[[V59:.*]] = load volatile i8, i8* %[[I64]], align 1
529// CHECK: store volatile i8 %[[V59]], i8* %[[I6]], align 1
530
531void test_copy_constructor_Bitfield1(Bitfield1 *a) {
532 Bitfield1 t = *a;
533}
Akira Hatanaka34fb2642018-03-13 18:58:25 +0000534
Akira Hatanakaceb66522018-03-13 23:37:51 +0000535// CHECK: define void @test_strong_in_union()
536// CHECK: alloca %{{.*}}
537// CHECK-NEXT: ret void
538
539void test_strong_in_union() {
540 U t;
541}
542
Akira Hatanaka34fb2642018-03-13 18:58:25 +0000543#endif /* USESTRUCT */