blob: 183e91b6ec57e603d920647e2c593a96ba2fbd53 [file] [log] [blame]
Adrian Prantl836e7c92013-03-14 17:53:33 +00001// 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{{.*}}
Adrian Prantl9b97adf2013-03-29 19:20:35 +000054// CHECK: %[[MEM1:.*]] = alloca i8*, align 8
55// CHECK-NEXT: %[[MEM2:.*]] = alloca i8*, align 8
56// CHECK: store i8* [[BLOCK_DESC:%.*]], i8** %[[MEM1]], align 8
57// CHECK: %[[TMP0:.*]] = load i8** %[[MEM1]]
58// CHECK: call void @llvm.dbg.value(metadata !{i8* %[[TMP0]]}, i64 0, metadata ![[BDMD:[0-9]+]])
59// CHECK: call void @llvm.dbg.declare(metadata !{i8* [[BLOCK_DESC]]}, metadata ![[BDMD:[0-9]+]])
60// CHECK: %[[TMP1:.*]] = bitcast
61// CHECK-NEXT: store
Adrian Prantl9b97adf2013-03-29 19:20:35 +000062// CHECK: call void @llvm.dbg.declare(metadata !{<{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** {{.*}}}, metadata ![[SELF:.*]])
63// make sure we are still in the same function
64// CHECK: define {{.*}}__copy_helper_block_
65// Metadata
66// CHECK: ![[MAIN:.*]] = {{.*}}!"Main"{{.*}}DW_TAG_structure_type{{.*}}line 23
67// CHECK: ![[PMAIN:.*]] = {{.*}}![[MAIN]]} ; [ DW_TAG_pointer_type ]{{.*}}from Main
68// CHECK: ![[BDMD]] = metadata {{.*}}.block_descriptor
69// CHECK: ![[SELF]] = {{.*}}![[PMAIN]]{{.*}}[ DW_TAG_auto_variable ] [self] [line 40]