blob: f50ddf0d8aeb0ed88969985f63ebcb87ce7c8272 [file] [log] [blame]
Adrian Prantl0f6df002013-03-29 19:20:35 +00001// RUN: %clang_cc1 -emit-llvm -fblocks -g -triple x86_64-apple-darwin10 -fobjc-dispatch-method=mixed %s -o - | FileCheck %s
Devang Patel433a11b2011-05-24 00:22:40 +00002
Adrian Prantl0f6df002013-03-29 19:20:35 +00003// rdar://problem/9279956
4// Test that we generate the proper debug location for a captured self.
5// The second half of this patch is in llvm/tests/DebugInfo/debug-info-blocks.ll
6
7// CHECK: define {{.*}}_block_invoke
Adrian Prantl6aebbb32013-03-29 23:15:55 +00008// CHECK: %[[BLOCK:.*]] = bitcast i8* %.block_descriptor to <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>*, !dbg
Adrian Prantl0f6df002013-03-29 19:20:35 +00009// CHECK-NEXT: store <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %[[BLOCK]], <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA:.*]], align
10// CHECK-NEXT: getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %[[BLOCK]], i32 0, i32 5
11// CHECK-NEXT: call void @llvm.dbg.declare(metadata !{<{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA]]}, metadata ![[SELF:[0-9]+]])
12// CHECK-NEXT: call void @llvm.dbg.declare(metadata !{%1** %d}, metadata ![[D:[0-9]+]])
13// CHECK: ![[SELF]] = {{.*}} [ DW_TAG_auto_variable ] [self] [line 52]
14// CHECK: ![[D]] = {{.*}} [d] [line 50]
Devang Patel433a11b2011-05-24 00:22:40 +000015
16typedef unsigned int NSUInteger;
17
18@protocol NSObject
19@end
20
21@interface NSObject <NSObject>
22- (id)init;
23+ (id)alloc;
24@end
25
26@interface NSDictionary : NSObject
27- (NSUInteger)count;
28@end
29
30@interface NSMutableDictionary : NSDictionary
31@end
32
33@interface A : NSObject {
34@public
35 int ivar;
36}
37@end
38
39static void run(void (^block)(void))
40{
41 block();
42}
43
44@implementation A
45
46- (id)init
47{
48 if ((self = [super init])) {
49 run(^{
50 NSMutableDictionary *d = [[NSMutableDictionary alloc] init];
51 ivar = 42 + (int)[d count];
52 });
53 }
54 return self;
55}
56
57@end
58
59int main()
60{
61 A *a = [[A alloc] init];
62 return 0;
63}