1// RUN: %clang_cc1 -fblocks -g -emit-llvm -triple x86_64-apple-darwin -o - %s | FileCheck %s 2// 3// Test that debug location is generated for a captured "self" inside 4// a block. 5// 6// This test is split into two parts, this one for the frontend, and 7// then llvm/test/DebugInfo/debug-info-block-captured-self.ll to 8// ensure that DW_AT_location is generated for the captured self. 9@class T; 10@interface S 11@end 12@interface Mode 13-(int) count; 14@end 15@interface Context 16@end 17@interface ViewController 18@property (nonatomic, readwrite, strong) Context *context; 19@end 20typedef enum { 21 Unknown = 0, 22} State; 23@interface Main : ViewController 24{ 25 T * t1; 26 T * t2; 27} 28@property(readwrite, nonatomic) State state; 29@end 30@implementation Main 31- (id) initWithContext:(Context *) context 32{ 33 t1 = [self.context withBlock:^(id obj){ 34 id *mode1; 35 t2 = [mode1 withBlock:^(id object){ 36 Mode *mode2 = object; 37 if ([mode2 count] != 0) { 38 self.state = 0; 39 } 40 }]; 41 }]; 42} 43@end 44// The important part of this test is that there is a dbg.value 45// intrinsic associated with the implicit .block_descriptor argument 46// of the block. We also test that this value gets alloca'd, so the 47// register llocator won't accidentally kill it. 48 49// outer block: 50// CHECK: define internal void {{.*}}_block_invoke{{.*}} 51 52// inner block: 53// CHECK: define internal void {{.*}}_block_invoke{{.*}} 54// CHECK: [[MEM1:%.*]] = alloca i8*, align 8 55// CHECK-NEXT: [[MEM2:%.*]] = alloca i8*, align 8 56// CHECK-NEXT: [[MEM3:%.*]] = alloca %{{.*}}*, align 8 57// CHECK: store i8* [[BLOCK_DESC:%.*]], i8** [[MEM1]], align 8 58// CHECK: [[TMP0:%.*]] = load i8** [[MEM1]] 59// CHECK: call void @llvm.dbg.value(metadata !{i8* [[TMP0]]}, i64 0, metadata [[BDMD:![0-9]+]]) 60// CHECK: call void @llvm.dbg.declare(metadata !{i8* [[BLOCK_DESC]]}, metadata [[BDMD:![0-9]+]]) 61// CHECK: [[TMP1:%.*]] = bitcast 62// CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* [[TMP1]] 63// CHECK-NEXT: [[TMP3:%.*]] = load %0** [[TMP2]] 64// CHECK-NEXT: store {{.*}}* [[TMP3]], %{{.*}}** [[MEM3]], align 8 65// CHECK: [[BDMD]] = metadata {{.*}}.block_descriptor 66