blob: 999b89dd60f51eb868b400166f3d5dd33771319b [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 Hatanaka7c552652018-04-16 20:23:52 +000073typedef struct {
74 id x;
75 volatile int a[16];
76} VolatileArray ;
77
Akira Hatanaka34fb2642018-03-13 18:58:25 +000078#endif
79
80#ifdef USESTRUCT
81
Akira Hatanaka7275da02018-02-28 07:15:55 +000082StrongSmall getStrongSmall(void);
83StrongOuter getStrongOuter(void);
84void calleeStrongSmall(StrongSmall);
85void func(Strong *);
86
87// CHECK: %[[STRUCT_BITFIELD1:.*]] = type { i8, i8, i8*, i32, i8*, [3 x i32], i8*, double, i8, i8 }
88
89// CHECK: define void @test_constructor_destructor_StrongOuter()
90// CHECK: %[[T:.*]] = alloca %[[STRUCT_STRONGOUTER:.*]], align 8
91// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8**
92// CHECK: call void @__default_constructor_8_s16_s24(i8** %[[V0]])
93// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8**
94// CHECK: call void @__destructor_8_s16_s24(i8** %[[V1]])
95// CHECK: ret void
96
97// CHECK: define linkonce_odr hidden void @__default_constructor_8_s16_s24(i8** %[[DST:.*]])
98// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
99// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
100// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
101// CHECK: call void @__default_constructor_8_s16(i8** %[[V0]])
102// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
103// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 24
104// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
105// CHECK: %[[V4:.*]] = bitcast i8** %[[V3]] to i8*
106// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V4]], i8 0, i64 8, i1 false)
107// CHECK: ret void
108
109// CHECK: define linkonce_odr hidden void @__default_constructor_8_s16(i8** %[[DST:.*]])
110// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
111// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
112// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
113// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
114// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 16
115// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
116// CHECK: %[[V4:.*]] = bitcast i8** %[[V3]] to i8*
117// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V4]], i8 0, i64 8, i1 false)
118// CHECK: ret void
119
120// CHECK: define linkonce_odr hidden void @__destructor_8_s16_s24(i8** %[[DST:.*]])
121// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
122// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
123// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
124// CHECK: call void @__destructor_8_s16(i8** %[[V0]])
125// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
126// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 24
127// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
Pete Cooper2cd35962018-12-18 20:33:00 +0000128// CHECK: call void @llvm.objc.storeStrong(i8** %[[V3]], i8* null)
Akira Hatanaka7275da02018-02-28 07:15:55 +0000129// CHECK: ret void
130
131// CHECK: define linkonce_odr hidden void @__destructor_8_s16(i8** %[[DST:.*]])
132// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
133// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
134// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
135// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
136// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 16
137// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
Pete Cooper2cd35962018-12-18 20:33:00 +0000138// CHECK: call void @llvm.objc.storeStrong(i8** %[[V3]], i8* null)
Akira Hatanaka7275da02018-02-28 07:15:55 +0000139// CHECK: ret void
140
141void test_constructor_destructor_StrongOuter(void) {
142 StrongOuter t;
143}
144
145// CHECK: define void @test_copy_constructor_StrongOuter(%[[STRUCT_STRONGOUTER:.*]]* %[[S:.*]])
146// CHECK: %[[S_ADDR:.*]] = alloca %[[STRUCT_STRONGOUTER]]*, align 8
147// CHECK: %[[T:.*]] = alloca %[[STRUCT_STRONGOUTER]], align 8
148// CHECK: store %[[STRUCT_STRONGOUTER]]* %[[S]], %[[STRUCT_STRONGOUTER]]** %[[S_ADDR]], align 8
149// CHECK: %[[V0:.*]] = load %[[STRUCT_STRONGOUTER]]*, %[[STRUCT_STRONGOUTER]]** %[[S_ADDR]], align 8
150// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8**
151// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[V0]] to i8**
152// CHECK: call void @__copy_constructor_8_8_t0w16_s16_s24_t32w8(i8** %[[V1]], i8** %[[V2]])
153// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8**
154// CHECK: call void @__destructor_8_s16_s24(i8** %[[V3]])
155// CHECK: ret void
156
157// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])
158// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
159// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
160// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
161// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
162// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
163// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
164// CHECK: call void @__copy_constructor_8_8_t0w16_s16(i8** %[[V0]], i8** %[[V1]])
165// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
166// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24
167// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
168// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8*
169// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24
170// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**
171// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000172// CHECK: %[[V9:.*]] = call i8* @llvm.objc.retain(i8* %[[V8]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000173// CHECK: store i8* %[[V9]], i8** %[[V4]], align 8
174// CHECK: %[[V10:.*]] = bitcast i8** %[[V0]] to i8*
175// CHECK: %[[V11:.*]] = getelementptr inbounds i8, i8* %[[V10]], i64 32
176// CHECK: %[[V12:.*]] = bitcast i8* %[[V11]] to i8**
177// CHECK: %[[V13:.*]] = bitcast i8** %[[V1]] to i8*
178// CHECK: %[[V14:.*]] = getelementptr inbounds i8, i8* %[[V13]], i64 32
179// CHECK: %[[V15:.*]] = bitcast i8* %[[V14]] to i8**
180// CHECK: %[[V16:.*]] = bitcast i8** %[[V12]] to i64*
181// CHECK: %[[V17:.*]] = bitcast i8** %[[V15]] to i64*
182// CHECK: %[[V18:.*]] = load i64, i64* %[[V17]], align 8
183// CHECK: store i64 %[[V18]], i64* %[[V16]], align 8
184// CHECK: ret void
185
186// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w16_s16(i8** %[[DST:.*]], i8** %[[SRC:.*]])
187// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
188// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
189// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
190// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
191// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
192// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
193// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
194// CHECK: %[[V3:.*]] = bitcast i8** %[[V1]] to i8*
195// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[V2]], i8* align 8 %[[V3]], i64 16, i1 false)
196// CHECK: %[[V4:.*]] = bitcast i8** %[[V0]] to i8*
197// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 16
198// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to i8**
199// CHECK: %[[V7:.*]] = bitcast i8** %[[V1]] to i8*
200// CHECK: %[[V8:.*]] = getelementptr inbounds i8, i8* %[[V7]], i64 16
201// CHECK: %[[V9:.*]] = bitcast i8* %[[V8]] to i8**
202// CHECK: %[[V10:.*]] = load i8*, i8** %[[V9]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000203// CHECK: %[[V11:.*]] = call i8* @llvm.objc.retain(i8* %[[V10]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000204// CHECK: store i8* %[[V11]], i8** %[[V6]], align 8
205// CHECK: ret void
206
207void test_copy_constructor_StrongOuter(StrongOuter *s) {
208 StrongOuter t = *s;
209}
210
211/// CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])
212// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
213// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
214// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
215// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
216// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
217// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
218// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
219// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24
220// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
221// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8*
222// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24
223// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**
224// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000225// CHECK: call void @llvm.objc.storeStrong(i8** %[[V4]], i8* %[[V8]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000226
227void test_copy_assignment_StrongOuter(StrongOuter *d, StrongOuter *s) {
228 *d = *s;
229}
230
231// CHECK: define void @test_move_constructor_StrongOuter()
232// CHECK: %[[T1:.*]] = getelementptr inbounds %[[STRUCT_BLOCK_BYREF_T:.*]], %[[STRUCT_BLOCK_BYREF_T]]* %{{.*}}, i32 0, i32 7
233// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T1]] to i8**
234// CHECK: call void @__default_constructor_8_s16_s24(i8** %[[V1]])
235// CHECK: %[[T2:.*]] = getelementptr inbounds %[[STRUCT_BLOCK_BYREF_T]], %[[STRUCT_BLOCK_BYREF_T]]* %{{.*}}, i32 0, i32 7
236// CHECK: %[[V9:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T2]] to i8**
237// CHECK: call void @__destructor_8_s16_s24(i8** %[[V9]])
238
239// CHECK: define internal void @__Block_byref_object_copy_(i8*, i8*)
240// CHECK: call void @__move_constructor_8_8_t0w16_s16_s24_t32w8(
241
242// CHECK: define linkonce_odr hidden void @__move_constructor_8_8_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])
243// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
244// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
245// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
246// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
247// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
248// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
249// CHECK: call void @__move_constructor_8_8_t0w16_s16(i8** %[[V0]], i8** %[[V1]])
250// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
251// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24
252// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
253// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8*
254// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24
255// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**
256// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8
257// CHECK: store i8* null, i8** %[[V7]], align 8
258// CHECK: store i8* %[[V8]], i8** %[[V4]], align 8
259
260// CHECK: define internal void @__Block_byref_object_dispose_(i8*)
261// CHECK: call void @__destructor_8_s16_s24(
262
263void test_move_constructor_StrongOuter(void) {
264 __block StrongOuter t;
265 BlockTy b = ^{ (void)t; };
266}
267
268// CHECK: define linkonce_odr hidden void @__move_assignment_8_8_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])
269// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
270// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
271// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
272// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
273// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
274// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
275// CHECK: call void @__move_assignment_8_8_t0w16_s16(i8** %[[V0]], i8** %[[V1]])
276// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
277// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24
278// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
279// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8*
280// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24
281// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**
282// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8
283// CHECK: store i8* null, i8** %[[V7]], align 8
284// CHECK: %[[V9:.*]] = load i8*, i8** %[[V4]], align 8
285// CHECK: store i8* %[[V8]], i8** %[[V4]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000286// CHECK: call void @llvm.objc.release(i8* %[[V9]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000287
288void test_move_assignment_StrongOuter(StrongOuter *p) {
289 *p = getStrongOuter();
290}
291
292// CHECK: define void @test_parameter_StrongSmall([2 x i64] %[[A_COERCE:.*]])
293// CHECK: %[[A:.*]] = alloca %[[STRUCT_STRONG:.*]], align 8
294// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONG]]* %[[A]] to [2 x i64]*
295// CHECK: store [2 x i64] %[[A_COERCE]], [2 x i64]* %[[V0]], align 8
296// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONG]]* %[[A]] to i8**
297// CHECK: call void @__destructor_8_s8(i8** %[[V1]])
298// CHECK: ret void
299
300void test_parameter_StrongSmall(StrongSmall a) {
301}
302
303// CHECK: define void @test_argument_StrongSmall([2 x i64] %[[A_COERCE:.*]])
304// CHECK: %[[A:.*]] = alloca %[[STRUCT_STRONGSMALL:.*]], align 8
305// CHECK: %[[TEMP_LVALUE:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
306// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to [2 x i64]*
307// CHECK: store [2 x i64] %[[A_COERCE]], [2 x i64]* %[[V0]], align 8
308// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TEMP_LVALUE]] to i8**
309// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
310// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V1]], i8** %[[V2]])
311// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TEMP_LVALUE]] to [2 x i64]*
312// CHECK: %[[V4:.*]] = load [2 x i64], [2 x i64]* %[[V3]], align 8
313// CHECK: call void @calleeStrongSmall([2 x i64] %[[V4]])
314// CHECK: %[[V5:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
315// CHECK: call void @__destructor_8_s8(i8** %[[V5]])
316// CHECK: ret void
317
318void test_argument_StrongSmall(StrongSmall a) {
319 calleeStrongSmall(a);
320}
321
322// CHECK: define [2 x i64] @test_return_StrongSmall([2 x i64] %[[A_COERCE:.*]])
323// CHECK: %[[RETVAL:.*]] = alloca %[[STRUCT_STRONGSMALL:.*]], align 8
324// CHECK: %[[A:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
325// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to [2 x i64]*
326// CHECK: store [2 x i64] %[[A_COERCE]], [2 x i64]* %[[V0]], align 8
327// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[RETVAL]] to i8**
328// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
329// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V1]], i8** %[[V2]])
330// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
331// CHECK: call void @__destructor_8_s8(i8** %[[V3]])
332// CHECK: %[[V4:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[RETVAL]] to [2 x i64]*
333// CHECK: %[[V5:.*]] = load [2 x i64], [2 x i64]* %[[V4]], align 8
334// CHECK: ret [2 x i64] %[[V5]]
335
336StrongSmall test_return_StrongSmall(StrongSmall a) {
337 return a;
338}
339
340// CHECK: define void @test_destructor_ignored_result()
341// CHECK: %[[COERCE:.*]] = alloca %[[STRUCT_STRONGSMALL:.*]], align 8
342// CHECK: %[[CALL:.*]] = call [2 x i64] @getStrongSmall()
343// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to [2 x i64]*
344// CHECK: store [2 x i64] %[[CALL]], [2 x i64]* %[[V0]], align 8
345// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to i8**
346// CHECK: call void @__destructor_8_s8(i8** %[[V1]])
347// CHECK: ret void
348
349void test_destructor_ignored_result(void) {
350 getStrongSmall();
351}
352
353// CHECK: define void @test_copy_constructor_StrongBlock(
354// CHECK: call void @__copy_constructor_8_8_sb0(
355// CHECK: call void @__destructor_8_sb0(
356// CHECK: ret void
357
358// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_sb0(i8** %[[DST:.*]], i8** %[[SRC:.*]])
359// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
360// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
361// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
362// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
363// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
364// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
365// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000366// CHECK: %[[V3:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V2]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000367// CHECK: store i8* %[[V3]], i8** %[[V0]], align 8
368// CHECK: ret void
369
370void test_copy_constructor_StrongBlock(StrongBlock *s) {
371 StrongBlock t = *s;
372}
373
374// CHECK: define void @test_copy_assignment_StrongBlock(%[[STRUCT_STRONGBLOCK:.*]]* %[[D:.*]], %[[STRUCT_STRONGBLOCK]]* %[[S:.*]])
375// CHECK: call void @__copy_assignment_8_8_sb0(
376
377// CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_sb0(i8** %[[DST:.*]], i8** %[[SRC:.*]])
378// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
379// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
380// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
381// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
382// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
383// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
384// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000385// CHECK: %[[V3:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V2]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000386// CHECK: %[[V4:.*]] = load i8*, i8** %[[V0]], align 8
387// CHECK: store i8* %[[V3]], i8** %[[V0]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000388// CHECK: call void @llvm.objc.release(i8* %[[V4]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000389// CHECK: ret void
390
391void test_copy_assignment_StrongBlock(StrongBlock *d, StrongBlock *s) {
392 *d = *s;
393}
394
395// CHECK: define void @test_copy_constructor_StrongVolatile0(
396// CHECK: call void @__copy_constructor_8_8_t0w4_sv8(
397// CHECK: call void @__destructor_8_sv8(
398
399// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w4_sv8(
400// CHECK: %[[V8:.*]] = load volatile i8*, i8** %{{.*}}, align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000401// CHECK: %[[V9:.*]] = call i8* @llvm.objc.retain(i8* %[[V8]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000402// CHECK: store volatile i8* %[[V9]], i8** %{{.*}}, align 8
403
404void test_copy_constructor_StrongVolatile0(StrongVolatile *s) {
405 StrongVolatile t = *s;
406}
407
408// CHECK: define void @test_copy_constructor_StrongVolatile1(
409// CHECK: call void @__copy_constructor_8_8_tv0w128_sv16(
410
411void test_copy_constructor_StrongVolatile1(Strong *s) {
412 volatile Strong t = *s;
413}
414
415// CHECK: define void @test_block_capture_Strong()
416// CHECK: call void @__default_constructor_8_s16(
417// CHECK: call void @__copy_constructor_8_8_t0w16_s16(
418// CHECK: call void @__destructor_8_s16(
419// CHECK: call void @__destructor_8_s16(
420// CHECK: ret void
421
Akira Hatanaka9978da32018-08-10 15:09:24 +0000422// CHECK: define linkonce_odr hidden void @__copy_helper_block_8_32n13_8_8_t0w16_s16(i8*, i8*)
Akira Hatanaka7275da02018-02-28 07:15:55 +0000423// CHECK: call void @__copy_constructor_8_8_t0w16_s16(
424// CHECK: ret void
425
Akira Hatanaka9978da32018-08-10 15:09:24 +0000426// CHECK: define linkonce_odr hidden void @__destroy_helper_block_8_32n5_8_s16(
Akira Hatanaka7275da02018-02-28 07:15:55 +0000427// CHECK: call void @__destructor_8_s16(
428// CHECK: ret void
429
430void test_block_capture_Strong(void) {
431 Strong t;
432 BlockTy b = ^(){ (void)t; };
433}
434
435// CHECK: define void @test_variable_length_array(i32 %[[N:.*]])
436// CHECK: %[[N_ADDR:.*]] = alloca i32, align 4
437// CHECK: store i32 %[[N]], i32* %[[N_ADDR]], align 4
438// CHECK: %[[V0:.*]] = load i32, i32* %[[N_ADDR]], align 4
439// CHECK: %[[V1:.*]] = zext i32 %[[V0]] to i64
440// CHECK: %[[VLA:.*]] = alloca %[[STRUCT_STRONG:.*]], i64 %[[V1]], align 8
441// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONG]]* %[[VLA]] to i8**
442// CHECK: %[[V4:.*]] = mul nuw i64 24, %[[V1]]
443// CHECK: %[[V5:.*]] = bitcast i8** %[[V3]] to i8*
444// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 %[[V4]]
445// CHECK: %[[DSTARRAY_END:.*]] = bitcast i8* %[[V6]] to i8**
446// CHECK: br label
447
448// CHECK: %[[DSTADDR_CUR:.*]] = phi i8** [ %[[V3]], {{.*}} ], [ %[[V7:.*]], {{.*}} ]
449// CHECK: %[[DONE:.*]] = icmp eq i8** %[[DSTADDR_CUR]], %[[DSTARRAY_END]]
450// CHECK: br i1 %[[DONE]], label
451
452// CHECK: call void @__default_constructor_8_s16(i8** %[[DSTADDR_CUR]])
453// CHECK: %[[V8:.*]] = bitcast i8** %[[DSTADDR_CUR]] to i8*
454// CHECK: %[[V9:.*]] = getelementptr inbounds i8, i8* %[[V8]], i64 24
455// CHECK: %[[V7]] = bitcast i8* %[[V9]] to i8**
456// CHECK: br label
457
458// CHECK: call void @func(%[[STRUCT_STRONG]]* %[[VLA]])
459// CHECK: %[[V10:.*]] = getelementptr inbounds %[[STRUCT_STRONG]], %[[STRUCT_STRONG]]* %[[VLA]], i64 %[[V1]]
460// CHECK: %[[ARRAYDESTROY_ISEMPTY:.*]] = icmp eq %[[STRUCT_STRONG]]* %[[VLA]], %[[V10]]
461// CHECK: br i1 %[[ARRAYDESTROY_ISEMPTY]], label
462
463// CHECK: %[[ARRAYDESTROY_ELEMENTPAST:.*]] = phi %[[STRUCT_STRONG]]* [ %[[V10]], {{.*}} ], [ %[[ARRAYDESTROY_ELEMENT:.*]], {{.*}} ]
464// CHECK: %[[ARRAYDESTROY_ELEMENT]] = getelementptr inbounds %[[STRUCT_STRONG]], %[[STRUCT_STRONG]]* %[[ARRAYDESTROY_ELEMENTPAST]], i64 -1
465// CHECK: %[[V11:.*]] = bitcast %[[STRUCT_STRONG]]* %[[ARRAYDESTROY_ELEMENT]] to i8**
466// CHECK: call void @__destructor_8_s16(i8** %[[V11]])
467// CHECK: %[[ARRAYDESTROY_DONE:.*]] = icmp eq %[[STRUCT_STRONG]]* %[[ARRAYDESTROY_ELEMENT]], %[[VLA]]
468// CHECK: br i1 %[[ARRAYDESTROY_DONE]], label
469
470// CHECK: ret void
471
472void test_variable_length_array(int n) {
473 Strong a[n];
474 func(a);
475}
476
477// CHECK: define linkonce_odr hidden void @__default_constructor_8_AB8s8n4_s8_AE(
478// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %{{.*}}, i8 0, i64 32, i1 false)
479void test_constructor_destructor_IDArray(void) {
480 IDArray t;
481}
482
483// CHECK: define linkonce_odr hidden void @__default_constructor_8_AB8s24n4_s24_AE(
484void test_constructor_destructor_StructArray(void) {
485 StructArray t;
486}
487
Akira Hatanaka9d343072018-10-02 01:00:44 +0000488// Test that StructArray's field 'd' is copied before entering the loop.
489
490// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w8_AB8s24n4_t8w16_s24_AE(i8** %[[DST:.*]], i8** %[[SRC:.*]])
491// CHECK: entry:
492// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
493// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
494// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
495// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
496// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
497// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
498// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i64*
499// CHECK: %[[V3:.*]] = bitcast i8** %[[V1]] to i64*
500// CHECK: %[[V4:.*]] = load i64, i64* %[[V3]], align 8
501// CHECK: store i64 %[[V4]], i64* %[[V2]], align 8
502
503// CHECK: phi i8**
504// CHECK: phi i8**
505
506// CHECK: phi i8**
507// CHECK: phi i8**
508
509// CHECK-NOT: load i64, i64* %
510// CHECK-NOT: store i64 %
511// CHECK: call void @__copy_constructor_8_8_t0w16_s16(
512
513void test_copy_constructor_StructArray(StructArray a) {
514 StructArray t = a;
515}
516
Akira Hatanaka7275da02018-02-28 07:15:55 +0000517// Check that IRGen copies the 9-bit bitfield emitting i16 load and store.
518
Akira Hatanaka9d343072018-10-02 01:00:44 +0000519// CHECK: define void @test_copy_constructor_Bitfield0(
520
Akira Hatanaka7275da02018-02-28 07:15:55 +0000521// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_s0_t8w2(
522// CHECK: %[[V4:.*]] = bitcast i8** %{{.*}} to i8*
523// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 8
524// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to i8**
525// CHECK: %[[V7:.*]] = bitcast i8** %{{.*}} to i8*
526// CHECK: %[[V8:.*]] = getelementptr inbounds i8, i8* %[[V7]], i64 8
527// CHECK: %[[V9:.*]] = bitcast i8* %[[V8]] to i8**
528// CHECK: %[[V10:.*]] = bitcast i8** %[[V6]] to i16*
529// CHECK: %[[V11:.*]] = bitcast i8** %[[V9]] to i16*
530// CHECK: %[[V12:.*]] = load i16, i16* %[[V11]], align 8
531// CHECK: store i16 %[[V12]], i16* %[[V10]], align 8
532// CHECK: ret void
533
534void test_copy_constructor_Bitfield0(Bitfield0 *a) {
535 Bitfield0 t = *a;
536}
537
538// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w2_s8_t16w4_s24_t32w12_s48_t56w9_tv513w2_tv520w8
539// CHECK: %[[V4:.*]] = load i16, i16* %{{.*}}, align 8
540// CHECK: store i16 %[[V4]], i16* %{{.*}}, align 8
541// CHECK: %[[V21:.*]] = load i32, i32* %{{.*}}, align 8
542// CHECK: store i32 %[[V21]], i32* %{{.*}}, align 8
543// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i64 12, i1 false)
544// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i64 9, i1 false)
545// CHECK: %[[V54:.*]] = bitcast i8** %[[V0:.*]] to %[[STRUCT_BITFIELD1]]*
546// CHECK: %[[I5:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V54]], i32 0, i32 8
547// CHECK: %[[V55:.*]] = bitcast i8** %[[V1:.*]] to %[[STRUCT_BITFIELD1]]*
548// CHECK: %[[I51:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V55]], i32 0, i32 8
549// CHECK: %[[BF_LOAD:.*]] = load volatile i8, i8* %[[I51]], align 8
550// CHECK: %[[BF_SHL:.*]] = shl i8 %[[BF_LOAD]], 5
551// CHECK: %[[BF_ASHR:.*]] = ashr i8 %[[BF_SHL]], 6
552// CHECK: %[[BF_CAST:.*]] = sext i8 %[[BF_ASHR]] to i32
553// CHECK: %[[V56:.*]] = trunc i32 %[[BF_CAST]] to i8
554// CHECK: %[[BF_LOAD2:.*]] = load volatile i8, i8* %[[I5]], align 8
555// CHECK: %[[BF_VALUE:.*]] = and i8 %[[V56]], 3
556// CHECK: %[[BF_SHL3:.*]] = shl i8 %[[BF_VALUE]], 1
557// CHECK: %[[BF_CLEAR:.*]] = and i8 %[[BF_LOAD2]], -7
558// CHECK: %[[BF_SET:.*]] = or i8 %[[BF_CLEAR]], %[[BF_SHL3]]
559// CHECK: store volatile i8 %[[BF_SET]], i8* %[[I5]], align 8
560// CHECK: %[[V57:.*]] = bitcast i8** %[[V0]] to %[[STRUCT_BITFIELD1]]*
561// CHECK: %[[I6:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V57]], i32 0, i32 9
562// CHECK: %[[V58:.*]] = bitcast i8** %[[V1]] to %[[STRUCT_BITFIELD1]]*
563// CHECK: %[[I64:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V58]], i32 0, i32 9
564// CHECK: %[[V59:.*]] = load volatile i8, i8* %[[I64]], align 1
565// CHECK: store volatile i8 %[[V59]], i8* %[[I6]], align 1
566
567void test_copy_constructor_Bitfield1(Bitfield1 *a) {
568 Bitfield1 t = *a;
569}
Akira Hatanaka34fb2642018-03-13 18:58:25 +0000570
Akira Hatanakaceb66522018-03-13 23:37:51 +0000571// CHECK: define void @test_strong_in_union()
572// CHECK: alloca %{{.*}}
573// CHECK-NEXT: ret void
574
575void test_strong_in_union() {
576 U t;
577}
578
Akira Hatanaka7c552652018-04-16 20:23:52 +0000579// CHECK: define void @test_copy_constructor_VolatileArray(
580// CHECK: call void @__copy_constructor_8_8_s0_AB8s4n16_tv64w32_AE(
581
582// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_s0_AB8s4n16_tv64w32_AE(
583// CHECK: %[[ADDR_CUR:.*]] = phi i8**
584// CHECK: %[[ADDR_CUR1:.*]] = phi i8**
585// CHECK: %[[V12:.*]] = bitcast i8** %[[ADDR_CUR]] to i32*
586// CHECK: %[[V13:.*]] = bitcast i8** %[[ADDR_CUR1]] to i32*
587// CHECK: %[[V14:.*]] = load volatile i32, i32* %[[V13]], align 4
588// CHECK: store volatile i32 %[[V14]], i32* %[[V12]], align 4
589
590void test_copy_constructor_VolatileArray(VolatileArray *a) {
591 VolatileArray t = *a;
592}
593
Akira Hatanaka34fb2642018-03-13 18:58:25 +0000594#endif /* USESTRUCT */