blob: 19cc1037c4cad879726d43e76c13b7ddd4c8c671 [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 {
Akira Hatanaka8b8d3622019-03-29 00:23:20 +000033 id f0;
34 Strong f1;
35} StrongOuter2;
36
37typedef struct {
Akira Hatanaka7275da02018-02-28 07:15:55 +000038 int f0;
39 volatile id f1;
40} StrongVolatile;
41
42typedef struct {
43 BlockTy f0;
44} StrongBlock;
45
46typedef struct {
47 int i;
48 id f0[2][2];
49} IDArray;
50
51typedef struct {
52 double d;
53 Strong f0[2][2];
54} StructArray;
55
56typedef struct {
57 id f0;
58 int i : 9;
59} Bitfield0;
60
61typedef struct {
62 char c;
63 int i0 : 2;
64 int i1 : 4;
65 id f0;
66 int i2 : 31;
67 int i3 : 1;
68 id f1;
69 int : 0;
70 int a[3];
71 id f2;
72 double d;
73 int i4 : 1;
74 volatile int i5 : 2;
75 volatile char i6;
76} Bitfield1;
77
Akira Hatanaka7c552652018-04-16 20:23:52 +000078typedef struct {
79 id x;
80 volatile int a[16];
81} VolatileArray ;
82
Akira Hatanaka34fb2642018-03-13 18:58:25 +000083#endif
84
85#ifdef USESTRUCT
86
Akira Hatanaka7275da02018-02-28 07:15:55 +000087StrongSmall getStrongSmall(void);
88StrongOuter getStrongOuter(void);
Akira Hatanaka8b8d3622019-03-29 00:23:20 +000089StrongOuter2 getStrongOuter2(void);
Akira Hatanaka7275da02018-02-28 07:15:55 +000090void calleeStrongSmall(StrongSmall);
91void func(Strong *);
92
Akira Hatanaka3b56e392019-06-27 21:16:19 +000093// CHECK: %[[STRUCT_STRONGOUTER:.*]] = type { %[[STRUCT_STRONG:.*]], i8*, double }
94// CHECK: %[[STRUCT_STRONG]] = type { %[[STRUCT_TRIVIAL:.*]], i8* }
95// CHECK: %[[STRUCT_TRIVIAL]] = type { [4 x i32] }
96// CHECK: %[[STRUCT_BLOCK_BYREF_T:.*]] = type { i8*, %[[STRUCT_BLOCK_BYREF_T]]*, i32, i32, i8*, i8*, i8*, %[[STRUCT_STRONGOUTER]] }
97// CHECK: %[[STRUCT_STRONGSMALL:.*]] = type { i32, i8* }
98// CHECK: %[[STRUCT_STRONGBLOCK:.*]] = type { void ()* }
Akira Hatanaka7275da02018-02-28 07:15:55 +000099// CHECK: %[[STRUCT_BITFIELD1:.*]] = type { i8, i8, i8*, i32, i8*, [3 x i32], i8*, double, i8, i8 }
100
101// CHECK: define void @test_constructor_destructor_StrongOuter()
Akira Hatanaka3b56e392019-06-27 21:16:19 +0000102// CHECK: %[[T:.*]] = alloca %[[STRUCT_STRONGOUTER]], align 8
Akira Hatanaka7275da02018-02-28 07:15:55 +0000103// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8**
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000104// CHECK: call void @__default_constructor_8_S_s16_s24(i8** %[[V0]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000105// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8**
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000106// CHECK: call void @__destructor_8_S_s16_s24(i8** %[[V1]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000107// CHECK: ret void
108
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000109// CHECK: define linkonce_odr hidden void @__default_constructor_8_S_s16_s24(i8** %[[DST:.*]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000110// 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: call void @__default_constructor_8_s16(i8** %[[V0]])
114// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
115// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 24
116// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
117// CHECK: %[[V4:.*]] = bitcast i8** %[[V3]] to i8*
118// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V4]], i8 0, i64 8, i1 false)
119// CHECK: ret void
120
121// CHECK: define linkonce_odr hidden void @__default_constructor_8_s16(i8** %[[DST:.*]])
122// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
123// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
124// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
125// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
126// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 16
127// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
128// CHECK: %[[V4:.*]] = bitcast i8** %[[V3]] to i8*
129// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V4]], i8 0, i64 8, i1 false)
130// CHECK: ret void
131
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000132// CHECK: define linkonce_odr hidden void @__destructor_8_S_s16_s24(i8** %[[DST:.*]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000133// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
134// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
135// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
136// CHECK: call void @__destructor_8_s16(i8** %[[V0]])
137// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
138// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 24
139// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
Pete Cooper2cd35962018-12-18 20:33:00 +0000140// CHECK: call void @llvm.objc.storeStrong(i8** %[[V3]], i8* null)
Akira Hatanaka7275da02018-02-28 07:15:55 +0000141// CHECK: ret void
142
143// CHECK: define linkonce_odr hidden void @__destructor_8_s16(i8** %[[DST:.*]])
144// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
145// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
146// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
147// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
148// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 16
149// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
Pete Cooper2cd35962018-12-18 20:33:00 +0000150// CHECK: call void @llvm.objc.storeStrong(i8** %[[V3]], i8* null)
Akira Hatanaka7275da02018-02-28 07:15:55 +0000151// CHECK: ret void
152
153void test_constructor_destructor_StrongOuter(void) {
154 StrongOuter t;
155}
156
Akira Hatanaka3b56e392019-06-27 21:16:19 +0000157// CHECK: define void @test_copy_constructor_StrongOuter(%[[STRUCT_STRONGOUTER]]* %[[S:.*]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000158// CHECK: %[[S_ADDR:.*]] = alloca %[[STRUCT_STRONGOUTER]]*, align 8
159// CHECK: %[[T:.*]] = alloca %[[STRUCT_STRONGOUTER]], align 8
160// CHECK: store %[[STRUCT_STRONGOUTER]]* %[[S]], %[[STRUCT_STRONGOUTER]]** %[[S_ADDR]], align 8
161// CHECK: %[[V0:.*]] = load %[[STRUCT_STRONGOUTER]]*, %[[STRUCT_STRONGOUTER]]** %[[S_ADDR]], align 8
162// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8**
163// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[V0]] to i8**
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000164// CHECK: call void @__copy_constructor_8_8_S_t0w16_s16_s24_t32w8(i8** %[[V1]], i8** %[[V2]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000165// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8**
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000166// CHECK: call void @__destructor_8_S_s16_s24(i8** %[[V3]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000167// CHECK: ret void
168
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000169// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_S_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000170// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
171// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
172// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
173// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
174// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
175// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
176// CHECK: call void @__copy_constructor_8_8_t0w16_s16(i8** %[[V0]], i8** %[[V1]])
177// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
178// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24
179// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
180// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8*
181// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24
182// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**
183// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000184// CHECK: %[[V9:.*]] = call i8* @llvm.objc.retain(i8* %[[V8]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000185// CHECK: store i8* %[[V9]], i8** %[[V4]], align 8
186// CHECK: %[[V10:.*]] = bitcast i8** %[[V0]] to i8*
187// CHECK: %[[V11:.*]] = getelementptr inbounds i8, i8* %[[V10]], i64 32
188// CHECK: %[[V12:.*]] = bitcast i8* %[[V11]] to i8**
189// CHECK: %[[V13:.*]] = bitcast i8** %[[V1]] to i8*
190// CHECK: %[[V14:.*]] = getelementptr inbounds i8, i8* %[[V13]], i64 32
191// CHECK: %[[V15:.*]] = bitcast i8* %[[V14]] to i8**
192// CHECK: %[[V16:.*]] = bitcast i8** %[[V12]] to i64*
193// CHECK: %[[V17:.*]] = bitcast i8** %[[V15]] to i64*
194// CHECK: %[[V18:.*]] = load i64, i64* %[[V17]], align 8
195// CHECK: store i64 %[[V18]], i64* %[[V16]], align 8
196// CHECK: ret void
197
198// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w16_s16(i8** %[[DST:.*]], i8** %[[SRC:.*]])
199// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
200// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
201// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
202// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
203// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
204// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
205// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
206// CHECK: %[[V3:.*]] = bitcast i8** %[[V1]] to i8*
207// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[V2]], i8* align 8 %[[V3]], i64 16, i1 false)
208// CHECK: %[[V4:.*]] = bitcast i8** %[[V0]] to i8*
209// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 16
210// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to i8**
211// CHECK: %[[V7:.*]] = bitcast i8** %[[V1]] to i8*
212// CHECK: %[[V8:.*]] = getelementptr inbounds i8, i8* %[[V7]], i64 16
213// CHECK: %[[V9:.*]] = bitcast i8* %[[V8]] to i8**
214// CHECK: %[[V10:.*]] = load i8*, i8** %[[V9]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000215// CHECK: %[[V11:.*]] = call i8* @llvm.objc.retain(i8* %[[V10]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000216// CHECK: store i8* %[[V11]], i8** %[[V6]], align 8
217// CHECK: ret void
218
219void test_copy_constructor_StrongOuter(StrongOuter *s) {
220 StrongOuter t = *s;
221}
222
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000223/// CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_S_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000224// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
225// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
226// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
227// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
228// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
229// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
230// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
231// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24
232// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
233// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8*
234// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24
235// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**
236// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000237// CHECK: call void @llvm.objc.storeStrong(i8** %[[V4]], i8* %[[V8]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000238
239void test_copy_assignment_StrongOuter(StrongOuter *d, StrongOuter *s) {
240 *d = *s;
241}
242
243// CHECK: define void @test_move_constructor_StrongOuter()
Akira Hatanaka3b56e392019-06-27 21:16:19 +0000244// CHECK: %[[T1:.*]] = getelementptr inbounds %[[STRUCT_BLOCK_BYREF_T]], %[[STRUCT_BLOCK_BYREF_T]]* %{{.*}}, i32 0, i32 7
Akira Hatanaka7275da02018-02-28 07:15:55 +0000245// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T1]] to i8**
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000246// CHECK: call void @__default_constructor_8_S_s16_s24(i8** %[[V1]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000247// CHECK: %[[T2:.*]] = getelementptr inbounds %[[STRUCT_BLOCK_BYREF_T]], %[[STRUCT_BLOCK_BYREF_T]]* %{{.*}}, i32 0, i32 7
248// CHECK: %[[V9:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T2]] to i8**
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000249// CHECK: call void @__destructor_8_S_s16_s24(i8** %[[V9]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000250
251// CHECK: define internal void @__Block_byref_object_copy_(i8*, i8*)
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000252// CHECK: call void @__move_constructor_8_8_S_t0w16_s16_s24_t32w8(
Akira Hatanaka7275da02018-02-28 07:15:55 +0000253
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000254// CHECK: define linkonce_odr hidden void @__move_constructor_8_8_S_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000255// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
256// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
257// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
258// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
259// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
260// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
261// CHECK: call void @__move_constructor_8_8_t0w16_s16(i8** %[[V0]], i8** %[[V1]])
262// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
263// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24
264// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
265// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8*
266// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24
267// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**
268// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8
269// CHECK: store i8* null, i8** %[[V7]], align 8
270// CHECK: store i8* %[[V8]], i8** %[[V4]], align 8
271
272// CHECK: define internal void @__Block_byref_object_dispose_(i8*)
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000273// CHECK: call void @__destructor_8_S_s16_s24(
Akira Hatanaka7275da02018-02-28 07:15:55 +0000274
275void test_move_constructor_StrongOuter(void) {
276 __block StrongOuter t;
277 BlockTy b = ^{ (void)t; };
278}
279
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000280// CHECK: define linkonce_odr hidden void @__move_assignment_8_8_S_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000281// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
282// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
283// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
284// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
285// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
286// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
287// CHECK: call void @__move_assignment_8_8_t0w16_s16(i8** %[[V0]], i8** %[[V1]])
288// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
289// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24
290// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
291// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8*
292// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24
293// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**
294// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8
295// CHECK: store i8* null, i8** %[[V7]], align 8
296// CHECK: %[[V9:.*]] = load i8*, i8** %[[V4]], align 8
297// CHECK: store i8* %[[V8]], i8** %[[V4]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000298// CHECK: call void @llvm.objc.release(i8* %[[V9]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000299
300void test_move_assignment_StrongOuter(StrongOuter *p) {
301 *p = getStrongOuter();
302}
303
Akira Hatanaka8b8d3622019-03-29 00:23:20 +0000304// CHECK: define linkonce_odr hidden void @__default_constructor_8_s0_S_s24(i8** %[[DST:.*]])
305// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
306// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
307// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
308// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
309// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V1]], i8 0, i64 8, i1 false)
310// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
311// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 8
312// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
313// CHECK: call void @__default_constructor_8_s16(i8** %[[V4]])
314
315// CHECK: define linkonce_odr hidden void @__destructor_8_s0_S_s24(i8** %[[DST:.*]])
316// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
317// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
318// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
319// CHECK: call void @llvm.objc.storeStrong(i8** %[[V0]], i8* null)
320// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
321// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 8
322// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**
323// CHECK: call void @__destructor_8_s16(i8** %[[V3]])
324
325void test_constructor_destructor_StrongOuter2(void) {
326 StrongOuter2 t;
327}
328
329// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_s0_S_t8w16_s24(i8** %[[DST:.*]], i8** %[[SRC:.*]])
330// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
331// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
332// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
333// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
334// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
335// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
336// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8
337// CHECK: %[[V3:.*]] = call i8* @llvm.objc.retain(i8* %[[V2]])
338// CHECK: store i8* %[[V3]], i8** %[[V0]], align 8
339// CHECK: %[[V4:.*]] = bitcast i8** %[[V0]] to i8*
340// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 8
341// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to i8**
342// CHECK: %[[V7:.*]] = bitcast i8** %[[V1]] to i8*
343// CHECK: %[[V8:.*]] = getelementptr inbounds i8, i8* %[[V7]], i64 8
344// CHECK: %[[V9:.*]] = bitcast i8* %[[V8]] to i8**
345// CHECK: call void @__copy_constructor_8_8_t0w16_s16(i8** %[[V6]], i8** %[[V9]])
346
347void test_copy_constructor_StrongOuter2(StrongOuter2 *s) {
348 StrongOuter2 t = *s;
349}
350
351// CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_s0_S_t8w16_s24(i8** %[[DST:.*]], i8** %[[SRC:.*]])
352// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
353// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
354// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
355// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
356// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
357// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
358// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8
359// CHECK: call void @llvm.objc.storeStrong(i8** %[[V0]], i8* %[[V2]])
360// CHECK: %[[V3:.*]] = bitcast i8** %[[V0]] to i8*
361// CHECK: %[[V4:.*]] = getelementptr inbounds i8, i8* %[[V3]], i64 8
362// CHECK: %[[V5:.*]] = bitcast i8* %[[V4]] to i8**
363// CHECK: %[[V6:.*]] = bitcast i8** %[[V1]] to i8*
364// CHECK: %[[V7:.*]] = getelementptr inbounds i8, i8* %[[V6]], i64 8
365// CHECK: %[[V8:.*]] = bitcast i8* %[[V7]] to i8**
366// CHECK: call void @__copy_assignment_8_8_t0w16_s16(i8** %[[V5]], i8** %[[V8]])
367
368void test_copy_assignment_StrongOuter2(StrongOuter2 *d, StrongOuter2 *s) {
369 *d = *s;
370}
371
372// CHECK: define linkonce_odr hidden void @__move_constructor_8_8_s0_S_t8w16_s24(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: store i8* null, i8** %[[V1]], align 8
381// CHECK: store i8* %[[V2]], i8** %[[V0]], align 8
382// CHECK: %[[V3:.*]] = bitcast i8** %[[V0]] to i8*
383// CHECK: %[[V4:.*]] = getelementptr inbounds i8, i8* %[[V3]], i64 8
384// CHECK: %[[V5:.*]] = bitcast i8* %[[V4]] to i8**
385// CHECK: %[[V6:.*]] = bitcast i8** %[[V1]] to i8*
386// CHECK: %[[V7:.*]] = getelementptr inbounds i8, i8* %[[V6]], i64 8
387// CHECK: %[[V8:.*]] = bitcast i8* %[[V7]] to i8**
388// CHECK: call void @__move_constructor_8_8_t0w16_s16(i8** %[[V5]], i8** %[[V8]])
389
390void test_move_constructor_StrongOuter2(void) {
391 __block StrongOuter2 t;
392 BlockTy b = ^{ (void)t; };
393}
394
395// CHECK: define linkonce_odr hidden void @__move_assignment_8_8_s0_S_t8w16_s24(i8** %[[DST:.*]], i8** %[[SRC:.*]])
396// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
397// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
398// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
399// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
400// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
401// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
402// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8
403// CHECK: store i8* null, i8** %[[V1]], align 8
404// CHECK: %[[V3:.*]] = load i8*, i8** %[[V0]], align 8
405// CHECK: store i8* %[[V2]], i8** %[[V0]], align 8
406// CHECK: call void @llvm.objc.release(i8* %[[V3]])
407// CHECK: %[[V4:.*]] = bitcast i8** %[[V0]] to i8*
408// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 8
409// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to i8**
410// CHECK: %[[V7:.*]] = bitcast i8** %[[V1]] to i8*
411// CHECK: %[[V8:.*]] = getelementptr inbounds i8, i8* %[[V7]], i64 8
412// CHECK: %[[V9:.*]] = bitcast i8* %[[V8]] to i8**
413// CHECK: call void @__move_assignment_8_8_t0w16_s16(i8** %[[V6]], i8** %[[V9]])
414
415void test_move_assignment_StrongOuter2(StrongOuter2 *p) {
416 *p = getStrongOuter2();
417}
418
Akira Hatanaka7275da02018-02-28 07:15:55 +0000419// CHECK: define void @test_parameter_StrongSmall([2 x i64] %[[A_COERCE:.*]])
Akira Hatanaka3b56e392019-06-27 21:16:19 +0000420// CHECK: %[[A:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
421// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to [2 x i64]*
Akira Hatanaka7275da02018-02-28 07:15:55 +0000422// CHECK: store [2 x i64] %[[A_COERCE]], [2 x i64]* %[[V0]], align 8
Akira Hatanaka3b56e392019-06-27 21:16:19 +0000423// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
Akira Hatanaka7275da02018-02-28 07:15:55 +0000424// CHECK: call void @__destructor_8_s8(i8** %[[V1]])
425// CHECK: ret void
426
427void test_parameter_StrongSmall(StrongSmall a) {
428}
429
430// CHECK: define void @test_argument_StrongSmall([2 x i64] %[[A_COERCE:.*]])
Akira Hatanaka3b56e392019-06-27 21:16:19 +0000431// CHECK: %[[A:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
Akira Hatanaka7275da02018-02-28 07:15:55 +0000432// CHECK: %[[TEMP_LVALUE:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
433// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to [2 x i64]*
434// CHECK: store [2 x i64] %[[A_COERCE]], [2 x i64]* %[[V0]], align 8
435// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TEMP_LVALUE]] to i8**
436// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
437// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V1]], i8** %[[V2]])
438// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TEMP_LVALUE]] to [2 x i64]*
439// CHECK: %[[V4:.*]] = load [2 x i64], [2 x i64]* %[[V3]], align 8
440// CHECK: call void @calleeStrongSmall([2 x i64] %[[V4]])
441// CHECK: %[[V5:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
442// CHECK: call void @__destructor_8_s8(i8** %[[V5]])
443// CHECK: ret void
444
445void test_argument_StrongSmall(StrongSmall a) {
446 calleeStrongSmall(a);
447}
448
449// CHECK: define [2 x i64] @test_return_StrongSmall([2 x i64] %[[A_COERCE:.*]])
Akira Hatanaka3b56e392019-06-27 21:16:19 +0000450// CHECK: %[[RETVAL:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
Akira Hatanaka7275da02018-02-28 07:15:55 +0000451// CHECK: %[[A:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
452// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to [2 x i64]*
453// CHECK: store [2 x i64] %[[A_COERCE]], [2 x i64]* %[[V0]], align 8
454// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[RETVAL]] to i8**
455// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
456// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V1]], i8** %[[V2]])
457// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8**
458// CHECK: call void @__destructor_8_s8(i8** %[[V3]])
459// CHECK: %[[V4:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[RETVAL]] to [2 x i64]*
460// CHECK: %[[V5:.*]] = load [2 x i64], [2 x i64]* %[[V4]], align 8
461// CHECK: ret [2 x i64] %[[V5]]
462
463StrongSmall test_return_StrongSmall(StrongSmall a) {
464 return a;
465}
466
467// CHECK: define void @test_destructor_ignored_result()
Akira Hatanaka3b56e392019-06-27 21:16:19 +0000468// CHECK: %[[COERCE:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
Akira Hatanaka7275da02018-02-28 07:15:55 +0000469// CHECK: %[[CALL:.*]] = call [2 x i64] @getStrongSmall()
470// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to [2 x i64]*
471// CHECK: store [2 x i64] %[[CALL]], [2 x i64]* %[[V0]], align 8
472// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to i8**
473// CHECK: call void @__destructor_8_s8(i8** %[[V1]])
474// CHECK: ret void
475
476void test_destructor_ignored_result(void) {
477 getStrongSmall();
478}
479
480// CHECK: define void @test_copy_constructor_StrongBlock(
481// CHECK: call void @__copy_constructor_8_8_sb0(
482// CHECK: call void @__destructor_8_sb0(
483// CHECK: ret void
484
485// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_sb0(i8** %[[DST:.*]], i8** %[[SRC:.*]])
486// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
487// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
488// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
489// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
490// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
491// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
492// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000493// CHECK: %[[V3:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V2]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000494// CHECK: store i8* %[[V3]], i8** %[[V0]], align 8
495// CHECK: ret void
496
497void test_copy_constructor_StrongBlock(StrongBlock *s) {
498 StrongBlock t = *s;
499}
500
Akira Hatanaka3b56e392019-06-27 21:16:19 +0000501// CHECK: define void @test_copy_assignment_StrongBlock(%[[STRUCT_STRONGBLOCK]]* %[[D:.*]], %[[STRUCT_STRONGBLOCK]]* %[[S:.*]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000502// CHECK: call void @__copy_assignment_8_8_sb0(
503
504// CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_sb0(i8** %[[DST:.*]], i8** %[[SRC:.*]])
505// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
506// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
507// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
508// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
509// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
510// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
511// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000512// CHECK: %[[V3:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V2]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000513// CHECK: %[[V4:.*]] = load i8*, i8** %[[V0]], align 8
514// CHECK: store i8* %[[V3]], i8** %[[V0]], align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000515// CHECK: call void @llvm.objc.release(i8* %[[V4]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000516// CHECK: ret void
517
518void test_copy_assignment_StrongBlock(StrongBlock *d, StrongBlock *s) {
519 *d = *s;
520}
521
522// CHECK: define void @test_copy_constructor_StrongVolatile0(
523// CHECK: call void @__copy_constructor_8_8_t0w4_sv8(
524// CHECK: call void @__destructor_8_sv8(
525
526// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w4_sv8(
527// CHECK: %[[V8:.*]] = load volatile i8*, i8** %{{.*}}, align 8
Pete Cooper2cd35962018-12-18 20:33:00 +0000528// CHECK: %[[V9:.*]] = call i8* @llvm.objc.retain(i8* %[[V8]])
Akira Hatanaka7275da02018-02-28 07:15:55 +0000529// CHECK: store volatile i8* %[[V9]], i8** %{{.*}}, align 8
530
531void test_copy_constructor_StrongVolatile0(StrongVolatile *s) {
532 StrongVolatile t = *s;
533}
534
535// CHECK: define void @test_copy_constructor_StrongVolatile1(
536// CHECK: call void @__copy_constructor_8_8_tv0w128_sv16(
537
538void test_copy_constructor_StrongVolatile1(Strong *s) {
539 volatile Strong t = *s;
540}
541
542// CHECK: define void @test_block_capture_Strong()
543// CHECK: call void @__default_constructor_8_s16(
544// CHECK: call void @__copy_constructor_8_8_t0w16_s16(
545// CHECK: call void @__destructor_8_s16(
546// CHECK: call void @__destructor_8_s16(
547// CHECK: ret void
548
Akira Hatanaka9978da32018-08-10 15:09:24 +0000549// CHECK: define linkonce_odr hidden void @__copy_helper_block_8_32n13_8_8_t0w16_s16(i8*, i8*)
Akira Hatanaka7275da02018-02-28 07:15:55 +0000550// CHECK: call void @__copy_constructor_8_8_t0w16_s16(
551// CHECK: ret void
552
Akira Hatanaka9978da32018-08-10 15:09:24 +0000553// CHECK: define linkonce_odr hidden void @__destroy_helper_block_8_32n5_8_s16(
Akira Hatanaka7275da02018-02-28 07:15:55 +0000554// CHECK: call void @__destructor_8_s16(
555// CHECK: ret void
556
557void test_block_capture_Strong(void) {
558 Strong t;
559 BlockTy b = ^(){ (void)t; };
560}
561
562// CHECK: define void @test_variable_length_array(i32 %[[N:.*]])
563// CHECK: %[[N_ADDR:.*]] = alloca i32, align 4
564// CHECK: store i32 %[[N]], i32* %[[N_ADDR]], align 4
565// CHECK: %[[V0:.*]] = load i32, i32* %[[N_ADDR]], align 4
566// CHECK: %[[V1:.*]] = zext i32 %[[V0]] to i64
Akira Hatanaka3b56e392019-06-27 21:16:19 +0000567// CHECK: %[[VLA:.*]] = alloca %[[STRUCT_STRONG]], i64 %[[V1]], align 8
Akira Hatanaka7275da02018-02-28 07:15:55 +0000568// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONG]]* %[[VLA]] to i8**
569// CHECK: %[[V4:.*]] = mul nuw i64 24, %[[V1]]
570// CHECK: %[[V5:.*]] = bitcast i8** %[[V3]] to i8*
571// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 %[[V4]]
572// CHECK: %[[DSTARRAY_END:.*]] = bitcast i8* %[[V6]] to i8**
573// CHECK: br label
574
575// CHECK: %[[DSTADDR_CUR:.*]] = phi i8** [ %[[V3]], {{.*}} ], [ %[[V7:.*]], {{.*}} ]
576// CHECK: %[[DONE:.*]] = icmp eq i8** %[[DSTADDR_CUR]], %[[DSTARRAY_END]]
577// CHECK: br i1 %[[DONE]], label
578
579// CHECK: call void @__default_constructor_8_s16(i8** %[[DSTADDR_CUR]])
580// CHECK: %[[V8:.*]] = bitcast i8** %[[DSTADDR_CUR]] to i8*
581// CHECK: %[[V9:.*]] = getelementptr inbounds i8, i8* %[[V8]], i64 24
582// CHECK: %[[V7]] = bitcast i8* %[[V9]] to i8**
583// CHECK: br label
584
585// CHECK: call void @func(%[[STRUCT_STRONG]]* %[[VLA]])
586// CHECK: %[[V10:.*]] = getelementptr inbounds %[[STRUCT_STRONG]], %[[STRUCT_STRONG]]* %[[VLA]], i64 %[[V1]]
587// CHECK: %[[ARRAYDESTROY_ISEMPTY:.*]] = icmp eq %[[STRUCT_STRONG]]* %[[VLA]], %[[V10]]
588// CHECK: br i1 %[[ARRAYDESTROY_ISEMPTY]], label
589
590// CHECK: %[[ARRAYDESTROY_ELEMENTPAST:.*]] = phi %[[STRUCT_STRONG]]* [ %[[V10]], {{.*}} ], [ %[[ARRAYDESTROY_ELEMENT:.*]], {{.*}} ]
591// CHECK: %[[ARRAYDESTROY_ELEMENT]] = getelementptr inbounds %[[STRUCT_STRONG]], %[[STRUCT_STRONG]]* %[[ARRAYDESTROY_ELEMENTPAST]], i64 -1
592// CHECK: %[[V11:.*]] = bitcast %[[STRUCT_STRONG]]* %[[ARRAYDESTROY_ELEMENT]] to i8**
593// CHECK: call void @__destructor_8_s16(i8** %[[V11]])
594// CHECK: %[[ARRAYDESTROY_DONE:.*]] = icmp eq %[[STRUCT_STRONG]]* %[[ARRAYDESTROY_ELEMENT]], %[[VLA]]
595// CHECK: br i1 %[[ARRAYDESTROY_DONE]], label
596
597// CHECK: ret void
598
599void test_variable_length_array(int n) {
600 Strong a[n];
601 func(a);
602}
603
604// CHECK: define linkonce_odr hidden void @__default_constructor_8_AB8s8n4_s8_AE(
605// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %{{.*}}, i8 0, i64 32, i1 false)
606void test_constructor_destructor_IDArray(void) {
607 IDArray t;
608}
609
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000610// CHECK: define linkonce_odr hidden void @__default_constructor_8_AB8s24n4_S_s24_AE(
Akira Hatanaka7275da02018-02-28 07:15:55 +0000611void test_constructor_destructor_StructArray(void) {
612 StructArray t;
613}
614
Akira Hatanaka9d343072018-10-02 01:00:44 +0000615// Test that StructArray's field 'd' is copied before entering the loop.
616
Shoaib Meenai155e26f2019-03-28 17:01:20 +0000617// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w8_AB8s24n4_S_t8w16_s24_AE(i8** %[[DST:.*]], i8** %[[SRC:.*]])
Akira Hatanaka9d343072018-10-02 01:00:44 +0000618// CHECK: entry:
619// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
620// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
621// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
622// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
623// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
624// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
625// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i64*
626// CHECK: %[[V3:.*]] = bitcast i8** %[[V1]] to i64*
627// CHECK: %[[V4:.*]] = load i64, i64* %[[V3]], align 8
628// CHECK: store i64 %[[V4]], i64* %[[V2]], align 8
629
630// CHECK: phi i8**
631// CHECK: phi i8**
632
633// CHECK: phi i8**
634// CHECK: phi i8**
635
636// CHECK-NOT: load i64, i64* %
637// CHECK-NOT: store i64 %
638// CHECK: call void @__copy_constructor_8_8_t0w16_s16(
639
640void test_copy_constructor_StructArray(StructArray a) {
641 StructArray t = a;
642}
643
Akira Hatanaka7275da02018-02-28 07:15:55 +0000644// Check that IRGen copies the 9-bit bitfield emitting i16 load and store.
645
Akira Hatanaka9d343072018-10-02 01:00:44 +0000646// CHECK: define void @test_copy_constructor_Bitfield0(
647
Akira Hatanaka7275da02018-02-28 07:15:55 +0000648// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_s0_t8w2(
649// CHECK: %[[V4:.*]] = bitcast i8** %{{.*}} to i8*
650// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 8
651// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to i8**
652// CHECK: %[[V7:.*]] = bitcast i8** %{{.*}} to i8*
653// CHECK: %[[V8:.*]] = getelementptr inbounds i8, i8* %[[V7]], i64 8
654// CHECK: %[[V9:.*]] = bitcast i8* %[[V8]] to i8**
655// CHECK: %[[V10:.*]] = bitcast i8** %[[V6]] to i16*
656// CHECK: %[[V11:.*]] = bitcast i8** %[[V9]] to i16*
657// CHECK: %[[V12:.*]] = load i16, i16* %[[V11]], align 8
658// CHECK: store i16 %[[V12]], i16* %[[V10]], align 8
659// CHECK: ret void
660
661void test_copy_constructor_Bitfield0(Bitfield0 *a) {
662 Bitfield0 t = *a;
663}
664
665// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w2_s8_t16w4_s24_t32w12_s48_t56w9_tv513w2_tv520w8
666// CHECK: %[[V4:.*]] = load i16, i16* %{{.*}}, align 8
667// CHECK: store i16 %[[V4]], i16* %{{.*}}, align 8
668// CHECK: %[[V21:.*]] = load i32, i32* %{{.*}}, align 8
669// CHECK: store i32 %[[V21]], i32* %{{.*}}, align 8
670// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i64 12, i1 false)
671// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i64 9, i1 false)
672// CHECK: %[[V54:.*]] = bitcast i8** %[[V0:.*]] to %[[STRUCT_BITFIELD1]]*
673// CHECK: %[[I5:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V54]], i32 0, i32 8
674// CHECK: %[[V55:.*]] = bitcast i8** %[[V1:.*]] to %[[STRUCT_BITFIELD1]]*
675// CHECK: %[[I51:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V55]], i32 0, i32 8
676// CHECK: %[[BF_LOAD:.*]] = load volatile i8, i8* %[[I51]], align 8
677// CHECK: %[[BF_SHL:.*]] = shl i8 %[[BF_LOAD]], 5
678// CHECK: %[[BF_ASHR:.*]] = ashr i8 %[[BF_SHL]], 6
679// CHECK: %[[BF_CAST:.*]] = sext i8 %[[BF_ASHR]] to i32
680// CHECK: %[[V56:.*]] = trunc i32 %[[BF_CAST]] to i8
681// CHECK: %[[BF_LOAD2:.*]] = load volatile i8, i8* %[[I5]], align 8
682// CHECK: %[[BF_VALUE:.*]] = and i8 %[[V56]], 3
683// CHECK: %[[BF_SHL3:.*]] = shl i8 %[[BF_VALUE]], 1
684// CHECK: %[[BF_CLEAR:.*]] = and i8 %[[BF_LOAD2]], -7
685// CHECK: %[[BF_SET:.*]] = or i8 %[[BF_CLEAR]], %[[BF_SHL3]]
686// CHECK: store volatile i8 %[[BF_SET]], i8* %[[I5]], align 8
687// CHECK: %[[V57:.*]] = bitcast i8** %[[V0]] to %[[STRUCT_BITFIELD1]]*
688// CHECK: %[[I6:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V57]], i32 0, i32 9
689// CHECK: %[[V58:.*]] = bitcast i8** %[[V1]] to %[[STRUCT_BITFIELD1]]*
690// CHECK: %[[I64:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V58]], i32 0, i32 9
691// CHECK: %[[V59:.*]] = load volatile i8, i8* %[[I64]], align 1
692// CHECK: store volatile i8 %[[V59]], i8* %[[I6]], align 1
693
694void test_copy_constructor_Bitfield1(Bitfield1 *a) {
695 Bitfield1 t = *a;
696}
Akira Hatanaka34fb2642018-03-13 18:58:25 +0000697
Akira Hatanakaceb66522018-03-13 23:37:51 +0000698// CHECK: define void @test_strong_in_union()
699// CHECK: alloca %{{.*}}
700// CHECK-NEXT: ret void
701
702void test_strong_in_union() {
703 U t;
704}
705
Akira Hatanaka7c552652018-04-16 20:23:52 +0000706// CHECK: define void @test_copy_constructor_VolatileArray(
707// CHECK: call void @__copy_constructor_8_8_s0_AB8s4n16_tv64w32_AE(
708
709// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_s0_AB8s4n16_tv64w32_AE(
710// CHECK: %[[ADDR_CUR:.*]] = phi i8**
711// CHECK: %[[ADDR_CUR1:.*]] = phi i8**
712// CHECK: %[[V12:.*]] = bitcast i8** %[[ADDR_CUR]] to i32*
713// CHECK: %[[V13:.*]] = bitcast i8** %[[ADDR_CUR1]] to i32*
714// CHECK: %[[V14:.*]] = load volatile i32, i32* %[[V13]], align 4
715// CHECK: store volatile i32 %[[V14]], i32* %[[V12]], align 4
716
717void test_copy_constructor_VolatileArray(VolatileArray *a) {
718 VolatileArray t = *a;
719}
720
Akira Hatanaka34fb2642018-03-13 18:58:25 +0000721#endif /* USESTRUCT */