1// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-llvm -o - -DUSESTRUCT %s | FileCheck %s 2 3// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-pch -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 %s | FileCheck %s 5 6#ifndef HEADER 7#define HEADER 8 9typedef void (^BlockTy)(void); 10 11typedef struct { 12 int a[4]; 13} Trivial; 14 15typedef struct { 16 Trivial f0; 17 id f1; 18} Strong; 19 20typedef struct { 21 int i; 22 id f1; 23} StrongSmall; 24 25typedef struct { 26 Strong f0; 27 id f1; 28 double d; 29} StrongOuter; 30 31typedef struct { 32 id f0; 33 Strong f1; 34} StrongOuter2; 35 36typedef struct { 37 int f0; 38 volatile id f1; 39} StrongVolatile; 40 41typedef struct { 42 BlockTy f0; 43} StrongBlock; 44 45typedef struct { 46 int i; 47 id f0[2][2]; 48} IDArray; 49 50typedef struct { 51 double d; 52 Strong f0[2][2]; 53} StructArray; 54 55typedef struct { 56 id f0; 57 int i : 9; 58} Bitfield0; 59 60typedef struct { 61 char c; 62 int i0 : 2; 63 int i1 : 4; 64 id f0; 65 int i2 : 31; 66 int i3 : 1; 67 id f1; 68 int : 0; 69 int a[3]; 70 id f2; 71 double d; 72 int i4 : 1; 73 volatile int i5 : 2; 74 volatile char i6; 75} Bitfield1; 76 77typedef struct { 78 id x; 79 volatile int a[16]; 80} VolatileArray ; 81 82typedef struct { 83 _Bool f0[2]; 84 VolatileArray f1; 85} StructWithBool; 86 87#endif 88 89#ifdef USESTRUCT 90 91StrongSmall getStrongSmall(void); 92StrongOuter getStrongOuter(void); 93StrongOuter2 getStrongOuter2(void); 94void calleeStrongSmall(StrongSmall); 95void func(Strong *); 96 97@interface C 98- (StrongSmall)getStrongSmall; 99- (void)m:(StrongSmall)s; 100+ (StrongSmall)getStrongSmallClass; 101@end 102 103id g0; 104StrongSmall g1, g2; 105 106// CHECK: %[[STRUCT_STRONGSMALL:.*]] = type { i32, i8* } 107// CHECK: %[[STRUCT_STRONGOUTER:.*]] = type { %[[STRUCT_STRONG:.*]], i8*, double } 108// CHECK: %[[STRUCT_STRONG]] = type { %[[STRUCT_TRIVIAL:.*]], i8* } 109// CHECK: %[[STRUCT_TRIVIAL]] = type { [4 x i32] } 110// CHECK: %[[STRUCT_BLOCK_BYREF_T:.*]] = type { i8*, %[[STRUCT_BLOCK_BYREF_T]]*, i32, i32, i8*, i8*, i8*, %[[STRUCT_STRONGOUTER]] } 111// CHECK: %[[STRUCT_STRONGBLOCK:.*]] = type { void ()* } 112// CHECK: %[[STRUCT_BITFIELD1:.*]] = type { i8, i8, i8*, i32, i8*, [3 x i32], i8*, double, i8, i8 } 113 114// CHECK: define{{.*}} void @test_constructor_destructor_StrongOuter() 115// CHECK: %[[T:.*]] = alloca %[[STRUCT_STRONGOUTER]], align 8 116// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8** 117// CHECK: call void @__default_constructor_8_S_s16_s24(i8** %[[V0]]) 118// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8** 119// CHECK: call void @__destructor_8_S_s16_s24(i8** %[[V1]]) 120// CHECK: ret void 121 122// CHECK: define linkonce_odr hidden void @__default_constructor_8_S_s16_s24(i8** %[[DST:.*]]) 123// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 124// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 125// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 126// CHECK: call void @__default_constructor_8_s16(i8** %[[V0]]) 127// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8* 128// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 24 129// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8** 130// CHECK: %[[V4:.*]] = bitcast i8** %[[V3]] to i8* 131// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V4]], i8 0, i64 8, i1 false) 132// CHECK: ret void 133 134// CHECK: define linkonce_odr hidden void @__default_constructor_8_s16(i8** %[[DST:.*]]) 135// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 136// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 137// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 138// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8* 139// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 16 140// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8** 141// CHECK: %[[V4:.*]] = bitcast i8** %[[V3]] to i8* 142// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V4]], i8 0, i64 8, i1 false) 143// CHECK: ret void 144 145// CHECK: define linkonce_odr hidden void @__destructor_8_S_s16_s24(i8** %[[DST:.*]]) 146// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 147// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 148// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 149// CHECK: call void @__destructor_8_s16(i8** %[[V0]]) 150// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8* 151// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 24 152// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8** 153// CHECK: call void @llvm.objc.storeStrong(i8** %[[V3]], i8* null) 154// CHECK: ret void 155 156// CHECK: define linkonce_odr hidden void @__destructor_8_s16(i8** %[[DST:.*]]) 157// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 158// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 159// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 160// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8* 161// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 16 162// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8** 163// CHECK: call void @llvm.objc.storeStrong(i8** %[[V3]], i8* null) 164// CHECK: ret void 165 166void test_constructor_destructor_StrongOuter(void) { 167 StrongOuter t; 168} 169 170// CHECK: define{{.*}} void @test_copy_constructor_StrongOuter(%[[STRUCT_STRONGOUTER]]* %[[S:.*]]) 171// CHECK: %[[S_ADDR:.*]] = alloca %[[STRUCT_STRONGOUTER]]*, align 8 172// CHECK: %[[T:.*]] = alloca %[[STRUCT_STRONGOUTER]], align 8 173// CHECK: store %[[STRUCT_STRONGOUTER]]* %[[S]], %[[STRUCT_STRONGOUTER]]** %[[S_ADDR]], align 8 174// CHECK: %[[V0:.*]] = load %[[STRUCT_STRONGOUTER]]*, %[[STRUCT_STRONGOUTER]]** %[[S_ADDR]], align 8 175// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8** 176// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[V0]] to i8** 177// CHECK: call void @__copy_constructor_8_8_S_t0w16_s16_s24_t32w8(i8** %[[V1]], i8** %[[V2]]) 178// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T]] to i8** 179// CHECK: call void @__destructor_8_S_s16_s24(i8** %[[V3]]) 180// CHECK: ret void 181 182// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_S_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]]) 183// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 184// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8 185// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 186// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 187// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 188// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 189// CHECK: call void @__copy_constructor_8_8_t0w16_s16(i8** %[[V0]], i8** %[[V1]]) 190// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8* 191// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24 192// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8** 193// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8* 194// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24 195// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8** 196// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8 197// CHECK: %[[V9:.*]] = call i8* @llvm.objc.retain(i8* %[[V8]]) 198// CHECK: store i8* %[[V9]], i8** %[[V4]], align 8 199// CHECK: %[[V10:.*]] = bitcast i8** %[[V0]] to i8* 200// CHECK: %[[V11:.*]] = getelementptr inbounds i8, i8* %[[V10]], i64 32 201// CHECK: %[[V12:.*]] = bitcast i8* %[[V11]] to i8** 202// CHECK: %[[V13:.*]] = bitcast i8** %[[V1]] to i8* 203// CHECK: %[[V14:.*]] = getelementptr inbounds i8, i8* %[[V13]], i64 32 204// CHECK: %[[V15:.*]] = bitcast i8* %[[V14]] to i8** 205// CHECK: %[[V16:.*]] = bitcast i8** %[[V12]] to i64* 206// CHECK: %[[V17:.*]] = bitcast i8** %[[V15]] to i64* 207// CHECK: %[[V18:.*]] = load i64, i64* %[[V17]], align 8 208// CHECK: store i64 %[[V18]], i64* %[[V16]], align 8 209// CHECK: ret void 210 211// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w16_s16(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:.*]] = bitcast i8** %[[V1]] to i8* 220// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[V2]], i8* align 8 %[[V3]], i64 16, i1 false) 221// CHECK: %[[V4:.*]] = bitcast i8** %[[V0]] to i8* 222// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 16 223// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to i8** 224// CHECK: %[[V7:.*]] = bitcast i8** %[[V1]] to i8* 225// CHECK: %[[V8:.*]] = getelementptr inbounds i8, i8* %[[V7]], i64 16 226// CHECK: %[[V9:.*]] = bitcast i8* %[[V8]] to i8** 227// CHECK: %[[V10:.*]] = load i8*, i8** %[[V9]], align 8 228// CHECK: %[[V11:.*]] = call i8* @llvm.objc.retain(i8* %[[V10]]) 229// CHECK: store i8* %[[V11]], i8** %[[V6]], align 8 230// CHECK: ret void 231 232void test_copy_constructor_StrongOuter(StrongOuter *s) { 233 StrongOuter t = *s; 234} 235 236/// CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_S_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]]) 237// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 238// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8 239// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 240// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 241// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 242// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 243// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8* 244// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24 245// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8** 246// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8* 247// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24 248// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8** 249// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8 250// CHECK: call void @llvm.objc.storeStrong(i8** %[[V4]], i8* %[[V8]]) 251 252void test_copy_assignment_StrongOuter(StrongOuter *d, StrongOuter *s) { 253 *d = *s; 254} 255 256// CHECK: define{{.*}} void @test_move_constructor_StrongOuter() 257// CHECK: %[[T1:.*]] = getelementptr inbounds %[[STRUCT_BLOCK_BYREF_T]], %[[STRUCT_BLOCK_BYREF_T]]* %{{.*}}, i32 0, i32 7 258// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T1]] to i8** 259// CHECK: call void @__default_constructor_8_S_s16_s24(i8** %[[V1]]) 260// CHECK: %[[T2:.*]] = getelementptr inbounds %[[STRUCT_BLOCK_BYREF_T]], %[[STRUCT_BLOCK_BYREF_T]]* %{{.*}}, i32 0, i32 7 261// CHECK: %[[V9:.*]] = bitcast %[[STRUCT_STRONGOUTER]]* %[[T2]] to i8** 262// CHECK: call void @__destructor_8_S_s16_s24(i8** %[[V9]]) 263 264// CHECK: define internal void @__Block_byref_object_copy_(i8* %0, i8* %1) 265// CHECK: call void @__move_constructor_8_8_S_t0w16_s16_s24_t32w8( 266 267// CHECK: define linkonce_odr hidden void @__move_constructor_8_8_S_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]]) 268// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 269// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8 270// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 271// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 272// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 273// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 274// CHECK: call void @__move_constructor_8_8_t0w16_s16(i8** %[[V0]], i8** %[[V1]]) 275// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8* 276// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24 277// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8** 278// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8* 279// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24 280// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8** 281// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8 282// CHECK: store i8* null, i8** %[[V7]], align 8 283// CHECK: store i8* %[[V8]], i8** %[[V4]], align 8 284 285// CHECK: define internal void @__Block_byref_object_dispose_(i8* %0) 286// CHECK: call void @__destructor_8_S_s16_s24( 287 288void test_move_constructor_StrongOuter(void) { 289 __block StrongOuter t; 290 BlockTy b = ^{ (void)t; }; 291} 292 293// CHECK: define linkonce_odr hidden void @__move_assignment_8_8_S_t0w16_s16_s24_t32w8(i8** %[[DST:.*]], i8** %[[SRC:.*]]) 294// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 295// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8 296// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 297// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 298// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 299// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 300// CHECK: call void @__move_assignment_8_8_t0w16_s16(i8** %[[V0]], i8** %[[V1]]) 301// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8* 302// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 24 303// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8** 304// CHECK: %[[V5:.*]] = bitcast i8** %[[V1]] to i8* 305// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 24 306// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to i8** 307// CHECK: %[[V8:.*]] = load i8*, i8** %[[V7]], align 8 308// CHECK: store i8* null, i8** %[[V7]], align 8 309// CHECK: %[[V9:.*]] = load i8*, i8** %[[V4]], align 8 310// CHECK: store i8* %[[V8]], i8** %[[V4]], align 8 311// CHECK: call void @llvm.objc.release(i8* %[[V9]]) 312 313void test_move_assignment_StrongOuter(StrongOuter *p) { 314 *p = getStrongOuter(); 315} 316 317// CHECK: define linkonce_odr hidden void @__default_constructor_8_s0_S_s24(i8** %[[DST:.*]]) 318// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 319// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 320// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 321// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8* 322// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V1]], i8 0, i64 8, i1 false) 323// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8* 324// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 8 325// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8** 326// CHECK: call void @__default_constructor_8_s16(i8** %[[V4]]) 327 328// CHECK: define linkonce_odr hidden void @__destructor_8_s0_S_s24(i8** %[[DST:.*]]) 329// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 330// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 331// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 332// CHECK: call void @llvm.objc.storeStrong(i8** %[[V0]], i8* null) 333// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8* 334// CHECK: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 8 335// CHECK: %[[V3:.*]] = bitcast i8* %[[V2]] to i8** 336// CHECK: call void @__destructor_8_s16(i8** %[[V3]]) 337 338void test_constructor_destructor_StrongOuter2(void) { 339 StrongOuter2 t; 340} 341 342// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_s0_S_t8w16_s24(i8** %[[DST:.*]], i8** %[[SRC:.*]]) 343// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 344// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8 345// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 346// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 347// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 348// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 349// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8 350// CHECK: %[[V3:.*]] = call i8* @llvm.objc.retain(i8* %[[V2]]) 351// CHECK: store i8* %[[V3]], i8** %[[V0]], align 8 352// CHECK: %[[V4:.*]] = bitcast i8** %[[V0]] to i8* 353// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 8 354// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to i8** 355// CHECK: %[[V7:.*]] = bitcast i8** %[[V1]] to i8* 356// CHECK: %[[V8:.*]] = getelementptr inbounds i8, i8* %[[V7]], i64 8 357// CHECK: %[[V9:.*]] = bitcast i8* %[[V8]] to i8** 358// CHECK: call void @__copy_constructor_8_8_t0w16_s16(i8** %[[V6]], i8** %[[V9]]) 359 360void test_copy_constructor_StrongOuter2(StrongOuter2 *s) { 361 StrongOuter2 t = *s; 362} 363 364// CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_s0_S_t8w16_s24(i8** %[[DST:.*]], i8** %[[SRC:.*]]) 365// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 366// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8 367// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 368// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 369// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 370// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 371// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8 372// CHECK: call void @llvm.objc.storeStrong(i8** %[[V0]], i8* %[[V2]]) 373// CHECK: %[[V3:.*]] = bitcast i8** %[[V0]] to i8* 374// CHECK: %[[V4:.*]] = getelementptr inbounds i8, i8* %[[V3]], i64 8 375// CHECK: %[[V5:.*]] = bitcast i8* %[[V4]] to i8** 376// CHECK: %[[V6:.*]] = bitcast i8** %[[V1]] to i8* 377// CHECK: %[[V7:.*]] = getelementptr inbounds i8, i8* %[[V6]], i64 8 378// CHECK: %[[V8:.*]] = bitcast i8* %[[V7]] to i8** 379// CHECK: call void @__copy_assignment_8_8_t0w16_s16(i8** %[[V5]], i8** %[[V8]]) 380 381void test_copy_assignment_StrongOuter2(StrongOuter2 *d, StrongOuter2 *s) { 382 *d = *s; 383} 384 385// CHECK: define linkonce_odr hidden void @__move_constructor_8_8_s0_S_t8w16_s24(i8** %[[DST:.*]], i8** %[[SRC:.*]]) 386// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 387// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8 388// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 389// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 390// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 391// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 392// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8 393// CHECK: store i8* null, i8** %[[V1]], align 8 394// CHECK: store i8* %[[V2]], i8** %[[V0]], align 8 395// CHECK: %[[V3:.*]] = bitcast i8** %[[V0]] to i8* 396// CHECK: %[[V4:.*]] = getelementptr inbounds i8, i8* %[[V3]], i64 8 397// CHECK: %[[V5:.*]] = bitcast i8* %[[V4]] to i8** 398// CHECK: %[[V6:.*]] = bitcast i8** %[[V1]] to i8* 399// CHECK: %[[V7:.*]] = getelementptr inbounds i8, i8* %[[V6]], i64 8 400// CHECK: %[[V8:.*]] = bitcast i8* %[[V7]] to i8** 401// CHECK: call void @__move_constructor_8_8_t0w16_s16(i8** %[[V5]], i8** %[[V8]]) 402 403void test_move_constructor_StrongOuter2(void) { 404 __block StrongOuter2 t; 405 BlockTy b = ^{ (void)t; }; 406} 407 408// CHECK: define linkonce_odr hidden void @__move_assignment_8_8_s0_S_t8w16_s24(i8** %[[DST:.*]], i8** %[[SRC:.*]]) 409// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 410// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8 411// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 412// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 413// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 414// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 415// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8 416// CHECK: store i8* null, i8** %[[V1]], align 8 417// CHECK: %[[V3:.*]] = load i8*, i8** %[[V0]], align 8 418// CHECK: store i8* %[[V2]], i8** %[[V0]], align 8 419// CHECK: call void @llvm.objc.release(i8* %[[V3]]) 420// CHECK: %[[V4:.*]] = bitcast i8** %[[V0]] to i8* 421// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 8 422// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to i8** 423// CHECK: %[[V7:.*]] = bitcast i8** %[[V1]] to i8* 424// CHECK: %[[V8:.*]] = getelementptr inbounds i8, i8* %[[V7]], i64 8 425// CHECK: %[[V9:.*]] = bitcast i8* %[[V8]] to i8** 426// CHECK: call void @__move_assignment_8_8_t0w16_s16(i8** %[[V6]], i8** %[[V9]]) 427 428void test_move_assignment_StrongOuter2(StrongOuter2 *p) { 429 *p = getStrongOuter2(); 430} 431 432// CHECK: define{{.*}} void @test_parameter_StrongSmall([2 x i64] %[[A_COERCE:.*]]) 433// CHECK: %[[A:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 434// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to [2 x i64]* 435// CHECK: store [2 x i64] %[[A_COERCE]], [2 x i64]* %[[V0]], align 8 436// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8** 437// CHECK: call void @__destructor_8_s8(i8** %[[V1]]) 438// CHECK: ret void 439 440void test_parameter_StrongSmall(StrongSmall a) { 441} 442 443// CHECK: define{{.*}} void @test_argument_StrongSmall([2 x i64] %[[A_COERCE:.*]]) 444// CHECK: %[[A:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 445// CHECK: %[[TEMP_LVALUE:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 446// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to [2 x i64]* 447// CHECK: store [2 x i64] %[[A_COERCE]], [2 x i64]* %[[V0]], align 8 448// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TEMP_LVALUE]] to i8** 449// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8** 450// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V1]], i8** %[[V2]]) 451// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TEMP_LVALUE]] to [2 x i64]* 452// CHECK: %[[V4:.*]] = load [2 x i64], [2 x i64]* %[[V3]], align 8 453// CHECK: call void @calleeStrongSmall([2 x i64] %[[V4]]) 454// CHECK: %[[V5:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8** 455// CHECK: call void @__destructor_8_s8(i8** %[[V5]]) 456// CHECK: ret void 457 458void test_argument_StrongSmall(StrongSmall a) { 459 calleeStrongSmall(a); 460} 461 462// CHECK: define{{.*}} [2 x i64] @test_return_StrongSmall([2 x i64] %[[A_COERCE:.*]]) 463// CHECK: %[[RETVAL:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 464// CHECK: %[[A:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 465// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to [2 x i64]* 466// CHECK: store [2 x i64] %[[A_COERCE]], [2 x i64]* %[[V0]], align 8 467// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[RETVAL]] to i8** 468// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8** 469// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V1]], i8** %[[V2]]) 470// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[A]] to i8** 471// CHECK: call void @__destructor_8_s8(i8** %[[V3]]) 472// CHECK: %[[V4:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[RETVAL]] to [2 x i64]* 473// CHECK: %[[V5:.*]] = load [2 x i64], [2 x i64]* %[[V4]], align 8 474// CHECK: ret [2 x i64] %[[V5]] 475 476StrongSmall test_return_StrongSmall(StrongSmall a) { 477 return a; 478} 479 480// CHECK: define{{.*}} void @test_destructor_ignored_result() 481// CHECK: %[[COERCE:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 482// CHECK: %[[CALL:.*]] = call [2 x i64] @getStrongSmall() 483// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to [2 x i64]* 484// CHECK: store [2 x i64] %[[CALL]], [2 x i64]* %[[V0]], align 8 485// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to i8** 486// CHECK: call void @__destructor_8_s8(i8** %[[V1]]) 487// CHECK: ret void 488 489void test_destructor_ignored_result(void) { 490 getStrongSmall(); 491} 492 493// CHECK: define{{.*}} void @test_destructor_ignored_result2(%{{.*}}* %[[C:.*]]) 494// CHECK: %[[TMP:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 495// CHECK: %[[CALL:.*]] = call [2 x i64]{{.*}}@objc_msgSend 496// CHECK: %[[V5:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to [2 x i64]* 497// CHECK: store [2 x i64] %[[CALL]], [2 x i64]* %[[V5]], align 8 498// CHECK: %[[V6:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8** 499// CHECK: call void @__destructor_8_s8(i8** %[[V6]]) 500 501void test_destructor_ignored_result2(C *c) { 502 [c getStrongSmall]; 503} 504 505// CHECK: define{{.*}} void @test_copy_constructor_StrongBlock( 506// CHECK: call void @__copy_constructor_8_8_sb0( 507// CHECK: call void @__destructor_8_sb0( 508// CHECK: ret void 509 510// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_sb0(i8** %[[DST:.*]], i8** %[[SRC:.*]]) 511// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 512// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8 513// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 514// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 515// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 516// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 517// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8 518// CHECK: %[[V3:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V2]]) 519// CHECK: store i8* %[[V3]], i8** %[[V0]], align 8 520// CHECK: ret void 521 522void test_copy_constructor_StrongBlock(StrongBlock *s) { 523 StrongBlock t = *s; 524} 525 526// CHECK: define{{.*}} void @test_copy_assignment_StrongBlock(%[[STRUCT_STRONGBLOCK]]* %[[D:.*]], %[[STRUCT_STRONGBLOCK]]* %[[S:.*]]) 527// CHECK: call void @__copy_assignment_8_8_sb0( 528 529// CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_sb0(i8** %[[DST:.*]], i8** %[[SRC:.*]]) 530// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 531// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8 532// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 533// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 534// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 535// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 536// CHECK: %[[V2:.*]] = load i8*, i8** %[[V1]], align 8 537// CHECK: %[[V3:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V2]]) 538// CHECK: %[[V4:.*]] = load i8*, i8** %[[V0]], align 8 539// CHECK: store i8* %[[V3]], i8** %[[V0]], align 8 540// CHECK: call void @llvm.objc.release(i8* %[[V4]]) 541// CHECK: ret void 542 543void test_copy_assignment_StrongBlock(StrongBlock *d, StrongBlock *s) { 544 *d = *s; 545} 546 547// CHECK-LABEL: define{{.*}} void @test_copy_assignment_StructWithBool( 548// CHECK: call void @__copy_assignment_8_8_AB0s1n2_tv0w8_AE_S_sv8_AB16s4n16_tv128w32_AE( 549 550// CHECK-LABEL: define linkonce_odr hidden void @__copy_assignment_8_8_AB0s1n2_tv0w8_AE_S_sv8_AB16s4n16_tv128w32_AE( 551// CHECK: %[[ADDR_CUR:.*]] = phi i8** 552// CHECK: %[[ADDR_CUR1:.*]] = phi i8** 553 554// CHECK: %[[V4:.*]] = bitcast i8** %[[ADDR_CUR]] to i8* 555// CHECK: %[[V5:.*]] = bitcast i8** %[[ADDR_CUR1]] to i8* 556// CHECK: %[[V6:.*]] = load volatile i8, i8* %[[V5]], align 1 557// CHECK: %[[TOBOOL:.*]] = trunc i8 %[[V6]] to i1 558// CHECK: %[[FROMBOOL:.*]] = zext i1 %[[TOBOOL]] to i8 559// CHECK: store volatile i8 %[[FROMBOOL]], i8* %[[V4]], align 1 560 561void test_copy_assignment_StructWithBool(StructWithBool *d, StructWithBool *s) { 562 *d = *s; 563} 564 565// CHECK: define{{.*}} void @test_copy_constructor_StrongVolatile0( 566// CHECK: call void @__copy_constructor_8_8_t0w4_sv8( 567// CHECK-NOT: call 568// CHECK: call void @__destructor_8_sv8( 569// CHECK-NOT: call 570 571// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w4_sv8( 572// CHECK: %[[V8:.*]] = load volatile i8*, i8** %{{.*}}, align 8 573// CHECK: %[[V9:.*]] = call i8* @llvm.objc.retain(i8* %[[V8]]) 574// CHECK: store volatile i8* %[[V9]], i8** %{{.*}}, align 8 575 576void test_copy_constructor_StrongVolatile0(StrongVolatile *s) { 577 StrongVolatile t = *s; 578} 579 580// CHECK: define{{.*}} void @test_copy_constructor_StrongVolatile1( 581// CHECK: call void @__copy_constructor_8_8_tv0w128_sv16( 582 583void test_copy_constructor_StrongVolatile1(Strong *s) { 584 volatile Strong t = *s; 585} 586 587// CHECK: define{{.*}} void @test_block_capture_Strong() 588// CHECK: call void @__default_constructor_8_s16( 589// CHECK: call void @__copy_constructor_8_8_t0w16_s16( 590// CHECK: call void @__destructor_8_s16( 591// CHECK: call void @__destructor_8_s16( 592// CHECK: ret void 593 594// CHECK: define linkonce_odr hidden void @__copy_helper_block_8_32n13_8_8_t0w16_s16(i8* %0, i8* %1) 595// CHECK: call void @__copy_constructor_8_8_t0w16_s16( 596// CHECK: ret void 597 598// CHECK: define linkonce_odr hidden void @__destroy_helper_block_8_32n5_8_s16( 599// CHECK: call void @__destructor_8_s16( 600// CHECK: ret void 601 602void test_block_capture_Strong(void) { 603 Strong t; 604 BlockTy b = ^(){ (void)t; }; 605} 606 607// CHECK: define{{.*}} void @test_variable_length_array(i32 %[[N:.*]]) 608// CHECK: %[[N_ADDR:.*]] = alloca i32, align 4 609// CHECK: store i32 %[[N]], i32* %[[N_ADDR]], align 4 610// CHECK: %[[V0:.*]] = load i32, i32* %[[N_ADDR]], align 4 611// CHECK: %[[V1:.*]] = zext i32 %[[V0]] to i64 612// CHECK: %[[VLA:.*]] = alloca %[[STRUCT_STRONG]], i64 %[[V1]], align 8 613// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONG]]* %[[VLA]] to i8** 614// CHECK: %[[V4:.*]] = mul nuw i64 24, %[[V1]] 615// CHECK: %[[V5:.*]] = bitcast i8** %[[V3]] to i8* 616// CHECK: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 %[[V4]] 617// CHECK: %[[DSTARRAY_END:.*]] = bitcast i8* %[[V6]] to i8** 618// CHECK: br label 619 620// CHECK: %[[DSTADDR_CUR:.*]] = phi i8** [ %[[V3]], {{.*}} ], [ %[[V7:.*]], {{.*}} ] 621// CHECK: %[[DONE:.*]] = icmp eq i8** %[[DSTADDR_CUR]], %[[DSTARRAY_END]] 622// CHECK: br i1 %[[DONE]], label 623 624// CHECK: call void @__default_constructor_8_s16(i8** %[[DSTADDR_CUR]]) 625// CHECK: %[[V8:.*]] = bitcast i8** %[[DSTADDR_CUR]] to i8* 626// CHECK: %[[V9:.*]] = getelementptr inbounds i8, i8* %[[V8]], i64 24 627// CHECK: %[[V7]] = bitcast i8* %[[V9]] to i8** 628// CHECK: br label 629 630// CHECK: call void @func(%[[STRUCT_STRONG]]* %[[VLA]]) 631// CHECK: %[[V10:.*]] = getelementptr inbounds %[[STRUCT_STRONG]], %[[STRUCT_STRONG]]* %[[VLA]], i64 %[[V1]] 632// CHECK: %[[ARRAYDESTROY_ISEMPTY:.*]] = icmp eq %[[STRUCT_STRONG]]* %[[VLA]], %[[V10]] 633// CHECK: br i1 %[[ARRAYDESTROY_ISEMPTY]], label 634 635// CHECK: %[[ARRAYDESTROY_ELEMENTPAST:.*]] = phi %[[STRUCT_STRONG]]* [ %[[V10]], {{.*}} ], [ %[[ARRAYDESTROY_ELEMENT:.*]], {{.*}} ] 636// CHECK: %[[ARRAYDESTROY_ELEMENT]] = getelementptr inbounds %[[STRUCT_STRONG]], %[[STRUCT_STRONG]]* %[[ARRAYDESTROY_ELEMENTPAST]], i64 -1 637// CHECK: %[[V11:.*]] = bitcast %[[STRUCT_STRONG]]* %[[ARRAYDESTROY_ELEMENT]] to i8** 638// CHECK: call void @__destructor_8_s16(i8** %[[V11]]) 639// CHECK: %[[ARRAYDESTROY_DONE:.*]] = icmp eq %[[STRUCT_STRONG]]* %[[ARRAYDESTROY_ELEMENT]], %[[VLA]] 640// CHECK: br i1 %[[ARRAYDESTROY_DONE]], label 641 642// CHECK: ret void 643 644void test_variable_length_array(int n) { 645 Strong a[n]; 646 func(a); 647} 648 649// CHECK: define linkonce_odr hidden void @__default_constructor_8_AB8s8n4_s8_AE( 650// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %{{.*}}, i8 0, i64 32, i1 false) 651void test_constructor_destructor_IDArray(void) { 652 IDArray t; 653} 654 655// CHECK: define linkonce_odr hidden void @__default_constructor_8_AB8s24n4_S_s24_AE( 656void test_constructor_destructor_StructArray(void) { 657 StructArray t; 658} 659 660// Test that StructArray's field 'd' is copied before entering the loop. 661 662// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w8_AB8s24n4_S_t8w16_s24_AE(i8** %[[DST:.*]], i8** %[[SRC:.*]]) 663// CHECK: entry: 664// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8 665// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8 666// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 667// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 668// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 669// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 670// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i64* 671// CHECK: %[[V3:.*]] = bitcast i8** %[[V1]] to i64* 672// CHECK: %[[V4:.*]] = load i64, i64* %[[V3]], align 8 673// CHECK: store i64 %[[V4]], i64* %[[V2]], align 8 674 675// CHECK: phi i8** 676// CHECK: phi i8** 677 678// CHECK: phi i8** 679// CHECK: phi i8** 680 681// CHECK-NOT: load i64, i64* % 682// CHECK-NOT: store i64 % 683// CHECK: call void @__copy_constructor_8_8_t0w16_s16( 684 685void test_copy_constructor_StructArray(StructArray a) { 686 StructArray t = a; 687} 688 689// Check that IRGen copies the 9-bit bitfield emitting i16 load and store. 690 691// CHECK: define{{.*}} void @test_copy_constructor_Bitfield0( 692 693// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_s0_t8w2( 694// CHECK: %[[V4:.*]] = bitcast i8** %{{.*}} to i8* 695// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 8 696// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to i8** 697// CHECK: %[[V7:.*]] = bitcast i8** %{{.*}} to i8* 698// CHECK: %[[V8:.*]] = getelementptr inbounds i8, i8* %[[V7]], i64 8 699// CHECK: %[[V9:.*]] = bitcast i8* %[[V8]] to i8** 700// CHECK: %[[V10:.*]] = bitcast i8** %[[V6]] to i16* 701// CHECK: %[[V11:.*]] = bitcast i8** %[[V9]] to i16* 702// CHECK: %[[V12:.*]] = load i16, i16* %[[V11]], align 8 703// CHECK: store i16 %[[V12]], i16* %[[V10]], align 8 704// CHECK: ret void 705 706void test_copy_constructor_Bitfield0(Bitfield0 *a) { 707 Bitfield0 t = *a; 708} 709 710// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w2_s8_t16w4_s24_t32w12_s48_t56w9_tv513w2_tv520w8 711// CHECK: %[[V4:.*]] = load i16, i16* %{{.*}}, align 8 712// CHECK: store i16 %[[V4]], i16* %{{.*}}, align 8 713// CHECK: %[[V21:.*]] = load i32, i32* %{{.*}}, align 8 714// CHECK: store i32 %[[V21]], i32* %{{.*}}, align 8 715// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i64 12, i1 false) 716// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i64 9, i1 false) 717// CHECK: %[[V54:.*]] = bitcast i8** %[[V0:.*]] to %[[STRUCT_BITFIELD1]]* 718// CHECK: %[[I5:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V54]], i32 0, i32 8 719// CHECK: %[[V55:.*]] = bitcast i8** %[[V1:.*]] to %[[STRUCT_BITFIELD1]]* 720// CHECK: %[[I51:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V55]], i32 0, i32 8 721// CHECK: %[[BF_LOAD:.*]] = load volatile i8, i8* %[[I51]], align 8 722// CHECK: %[[BF_SHL:.*]] = shl i8 %[[BF_LOAD]], 5 723// CHECK: %[[BF_ASHR:.*]] = ashr i8 %[[BF_SHL]], 6 724// CHECK: %[[BF_CAST:.*]] = sext i8 %[[BF_ASHR]] to i32 725// CHECK: %[[V56:.*]] = trunc i32 %[[BF_CAST]] to i8 726// CHECK: %[[BF_LOAD2:.*]] = load volatile i8, i8* %[[I5]], align 8 727// CHECK: %[[BF_VALUE:.*]] = and i8 %[[V56]], 3 728// CHECK: %[[BF_SHL3:.*]] = shl i8 %[[BF_VALUE]], 1 729// CHECK: %[[BF_CLEAR:.*]] = and i8 %[[BF_LOAD2]], -7 730// CHECK: %[[BF_SET:.*]] = or i8 %[[BF_CLEAR]], %[[BF_SHL3]] 731// CHECK: store volatile i8 %[[BF_SET]], i8* %[[I5]], align 8 732// CHECK: %[[V57:.*]] = bitcast i8** %[[V0]] to %[[STRUCT_BITFIELD1]]* 733// CHECK: %[[I6:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V57]], i32 0, i32 9 734// CHECK: %[[V58:.*]] = bitcast i8** %[[V1]] to %[[STRUCT_BITFIELD1]]* 735// CHECK: %[[I64:.*]] = getelementptr inbounds %[[STRUCT_BITFIELD1]], %[[STRUCT_BITFIELD1]]* %[[V58]], i32 0, i32 9 736// CHECK: %[[V59:.*]] = load volatile i8, i8* %[[I64]], align 1 737// CHECK: store volatile i8 %[[V59]], i8* %[[I6]], align 1 738 739void test_copy_constructor_Bitfield1(Bitfield1 *a) { 740 Bitfield1 t = *a; 741} 742 743// CHECK: define{{.*}} void @test_copy_constructor_VolatileArray( 744// CHECK: call void @__copy_constructor_8_8_s0_AB8s4n16_tv64w32_AE( 745 746// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_s0_AB8s4n16_tv64w32_AE( 747// CHECK: %[[ADDR_CUR:.*]] = phi i8** 748// CHECK: %[[ADDR_CUR1:.*]] = phi i8** 749// CHECK: %[[V12:.*]] = bitcast i8** %[[ADDR_CUR]] to i32* 750// CHECK: %[[V13:.*]] = bitcast i8** %[[ADDR_CUR1]] to i32* 751// CHECK: %[[V14:.*]] = load volatile i32, i32* %[[V13]], align 4 752// CHECK: store volatile i32 %[[V14]], i32* %[[V12]], align 4 753 754void test_copy_constructor_VolatileArray(VolatileArray *a) { 755 VolatileArray t = *a; 756} 757 758// CHECK: define{{.*}} void @test_compound_literal0( 759// CHECK: %[[P:.*]] = alloca %[[STRUCT_STRONGSMALL]]*, align 8 760// CHECK: %[[_COMPOUNDLITERAL:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 761// CHECK: %[[CLEANUP_COND:.*]] = alloca i1, align 1 762// CHECK: %[[_COMPOUNDLITERAL1:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 763// CHECK: %[[CLEANUP_COND4:.*]] = alloca i1, align 1 764 765// CHECK: %[[I:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]], i32 0, i32 0 766// CHECK: store i32 1, i32* %[[I]], align 8 767// CHECK: %[[F1:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]], i32 0, i32 1 768// CHECK: store i8* null, i8** %[[F1]], align 8 769// CHECK: store i1 true, i1* %[[CLEANUP_COND]], align 1 770 771// CHECK: %[[I2:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]], i32 0, i32 0 772// CHECK: store i32 2, i32* %[[I2]], align 8 773// CHECK: %[[F13:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]], i32 0, i32 1 774// CHECK: store i8* null, i8** %[[F13]], align 8 775// CHECK: store i1 true, i1* %[[CLEANUP_COND4]], align 1 776 777// CHECK: %[[COND:.*]] = phi %[[STRUCT_STRONGSMALL]]* [ %[[_COMPOUNDLITERAL]], %{{.*}} ], [ %[[_COMPOUNDLITERAL1]], %{{.*}} ] 778// CHECK: store %[[STRUCT_STRONGSMALL]]* %[[COND]], %[[STRUCT_STRONGSMALL]]** %[[P]], align 8 779// CHECK: call void @func( 780 781// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]] to i8** 782// CHECK: call void @__destructor_8_s8(i8** %[[V1]]) 783 784// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]] to i8** 785// CHECK: call void @__destructor_8_s8(i8** %[[V2]]) 786 787void test_compound_literal0(int c) { 788 StrongSmall *p = c ? &(StrongSmall){ 1, 0 } : &(StrongSmall){ 2, 0 }; 789 func(0); 790} 791 792// Check that there is only one destructor call, which destructs 't'. 793 794// CHECK: define{{.*}} void @test_compound_literal1( 795// CHECK: %[[T:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 796 797// CHECK: %[[I:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[T]], i32 0, i32 0 798// CHECK: store i32 1, i32* %[[I]], align 8 799// CHECK: %[[F1:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[T]], i32 0, i32 1 800// CHECK: store i8* null, i8** %[[F1]], align 8 801 802// CHECK: %[[I1:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[T]], i32 0, i32 0 803// CHECK: store i32 2, i32* %[[I1]], align 8 804// CHECK: %[[F12:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[T]], i32 0, i32 1 805// CHECK: store i8* null, i8** %[[F12]], align 8 806 807// CHECK: call void @func( 808// CHECK-NOT: call void 809// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[T]] to i8** 810// CHECK: call void @__destructor_8_s8(i8** %[[V1]]) 811// CHECK-NOT: call void 812 813void test_compound_literal1(int c) { 814 StrongSmall t = c ? (StrongSmall){ 1, 0 } : (StrongSmall){ 2, 0 }; 815 func(0); 816} 817 818// CHECK: define{{.*}} void @test_compound_literal2( 819// CHECK: %[[P_ADDR:.*]] = alloca %[[STRUCT_STRONGSMALL]]*, align 8 820// CHECK: %[[_COMPOUNDLITERAL:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 821// CHECK: %[[CLEANUP_COND:.*]] = alloca i1, align 1 822// CHECK: %[[_COMPOUNDLITERAL1:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 823// CHECK: %[[CLEANUP_COND4:.*]] = alloca i1, align 1 824// CHECK: %[[V0:.*]] = load %[[STRUCT_STRONGSMALL]]*, %[[STRUCT_STRONGSMALL]]** %[[P_ADDR]], align 8 825 826// CHECK: %[[I:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]], i32 0, i32 0 827// CHECK: store i32 1, i32* %[[I]], align 8 828// CHECK: %[[F1:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]], i32 0, i32 1 829// CHECK: store i8* null, i8** %[[F1]], align 8 830// CHECK: store i1 true, i1* %[[CLEANUP_COND]], align 1 831// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[V0]] to i8** 832// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]] to i8** 833// CHECK: call void @__copy_assignment_8_8_t0w4_s8(i8** %[[V2]], i8** %[[V3]]) 834 835// CHECK: %[[I2:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]], i32 0, i32 0 836// CHECK: store i32 2, i32* %[[I2]], align 8 837// CHECK: %[[F13:.*]] = getelementptr inbounds %[[STRUCT_STRONGSMALL]], %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]], i32 0, i32 1 838// CHECK: store i8* null, i8** %[[F13]], align 8 839// CHECK: store i1 true, i1* %[[CLEANUP_COND4]], align 1 840// CHECK: %[[V4:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[V0]] to i8** 841// CHECK: %[[V5:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]] to i8** 842// CHECK: call void @__copy_assignment_8_8_t0w4_s8(i8** %[[V4]], i8** %[[V5]]) 843 844// CHECK: call void @func( 845 846// CHECK: %[[V6:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL1]] to i8** 847// CHECK: call void @__destructor_8_s8(i8** %[[V6]]) 848 849// CHECK: %[[V7:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[_COMPOUNDLITERAL]] to i8** 850// CHECK: call void @__destructor_8_s8(i8** %[[V7]]) 851 852void test_compound_literal2(int c, StrongSmall *p) { 853 *p = c ? (StrongSmall){ 1, 0 } : (StrongSmall){ 2, 0 }; 854 func(0); 855} 856 857// CHECK: define{{.*}} void @test_member_access( 858// CHECK: %[[TMP:.*]] = alloca %[[STRUCT_STRONGSMALL]], 859// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8** 860// CHECK: call void @__destructor_8_s8(i8** %[[V3]]) 861// CHECK: call void @func( 862 863void test_member_access(void) { 864 g0 = getStrongSmall().f1; 865 func(0); 866} 867 868// CHECK: define{{.*}} void @test_member_access2(%{{.*}}* %[[C:.*]]) 869// CHECK: %[[COERCE:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 870// CHECK: %[[V8:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to i8** 871// CHECK: call void @__destructor_8_s8(i8** %[[V8]]) 872// CHECK: call void @func( 873 874void test_member_access2(C *c) { 875 g0 = [c getStrongSmall].f1; 876 func(0); 877} 878 879// CHECK: define{{.*}} void @test_member_access3( 880// CHECK: %[[COERCE:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 881// CHECK: %[[V8:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to i8** 882// CHECK: call void @__destructor_8_s8(i8** %[[V8]]) 883// CHECK: call void @func( 884 885void test_member_access3(void) { 886 g0 = [C getStrongSmallClass].f1; 887 func(0); 888} 889 890// CHECK: define{{.*}} void @test_member_access4() 891// CHECK: %[[COERCE:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 892// CHECK: %[[V5:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[COERCE]] to i8** 893// CHECK: call void @__destructor_8_s8(i8** %[[V5]]) 894// CHECK: call void @func( 895 896void test_member_access4(void) { 897 g0 = ^{ StrongSmall s; return s; }().f1; 898 func(0); 899} 900 901// CHECK: define{{.*}} void @test_volatile_variable_reference( 902// CHECK: %[[AGG_TMP_ENSURED:.*]] = alloca %[[STRUCT_STRONGSMALL]], 903// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[AGG_TMP_ENSURED]] to i8** 904// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %{{.*}} to i8** 905// CHECK: call void @__copy_constructor_8_8_tv0w32_sv8(i8** %[[V1]], i8** %[[V2]]) 906// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[AGG_TMP_ENSURED]] to i8** 907// CHECK: call void @__destructor_8_s8(i8** %[[V3]]) 908// CHECK: call void @func( 909 910void test_volatile_variable_reference(volatile StrongSmall *a) { 911 (void)*a; 912 func(0); 913} 914 915struct ZeroBitfield { 916 int : 0; 917 id strong; 918}; 919 920 921// CHECK: define linkonce_odr hidden void @__default_constructor_8_sv0 922// CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_sv0 923void test_zero_bitfield() { 924 struct ZeroBitfield volatile a, b; 925 a = b; 926} 927 928// CHECK-LABEL: define{{.*}} i8* @test_conditional0( 929// CHECK: %[[TMP:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 930 931// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8** 932// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V1]], i8** bitcast (%[[STRUCT_STRONGSMALL]]* @g2 to i8**)) 933 934// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8** 935// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V2]], i8** bitcast (%[[STRUCT_STRONGSMALL]]* @g1 to i8**)) 936 937// CHECK: %[[V5:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8** 938// CHECK: call void @__destructor_8_s8(i8** %[[V5]]) 939// CHECK: @llvm.objc.autoreleaseReturnValue 940 941id test_conditional0(int c) { 942 return (c ? g2 : g1).f1; 943} 944 945// CHECK-LABEL: define{{.*}} i8* @test_conditional1( 946// CHECK-NOT: call void @__destructor 947 948id test_conditional1(int c) { 949 calleeStrongSmall(c ? g2 : g1); 950} 951 952// CHECK-LABEL: define{{.*}} i8* @test_assignment0( 953// CHECK: %[[TMP:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 954// CHECK: call void @__copy_assignment_8_8_t0w4_s8(i8** bitcast (%[[STRUCT_STRONGSMALL]]* @g2 to i8**), i8** bitcast (%[[STRUCT_STRONGSMALL]]* @g1 to i8**)) 955// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8** 956// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V0]], i8** bitcast (%[[STRUCT_STRONGSMALL]]* @g2 to i8**)) 957// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8** 958// CHECK: call void @__destructor_8_s8(i8** %[[V3]]) 959 960id test_assignment0(void) { 961 return (g2 = g1).f1; 962} 963 964// CHECK-LABEL: define{{.*}} i8* @test_assignment1( 965// CHECK-NOT: call void @__destructor 966 967id test_assignment1(void) { 968 calleeStrongSmall(g2 = g1); 969} 970 971// CHECK-LABEL: define{{.*}} void @test_null_reveiver( 972// CHECK: %[[AGG_TMP:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8 973// CHECK: br i1 974 975// CHECK: %[[V7:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[AGG_TMP]] to [2 x i64]* 976// CHECK: %[[V8:.*]] = load [2 x i64], [2 x i64]* %[[V7]], align 8 977// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void ({{.*}}, [2 x i64] %[[V8]]) 978// CHECK: br 979 980// CHECK: %[[V9:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[AGG_TMP]] to i8** 981// CHECK: call void @__destructor_8_s8(i8** %[[V9]]) #4 982// CHECK: br 983 984void test_null_reveiver(C *c) { 985 [c m:getStrongSmall()]; 986} 987 988#endif /* USESTRUCT */ 989