1// RUN: %clang_cc1 -emit-llvm -fblocks -g  -triple x86_64-apple-darwin10 -fobjc-dispatch-method=mixed  %s -o - | FileCheck %s
2
3// 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
8// CHECK: %[[BLOCK:.*]] = bitcast i8* %.block_descriptor to <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>*, !dbg
9// 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: call void @llvm.dbg.declare(metadata !{<{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA]]}, metadata ![[SELF:[0-9]+]])
11// CHECK-NEXT: call void @llvm.dbg.declare(metadata !{%1** %d}, metadata ![[D:[0-9]+]])
12// CHECK: ![[SELF]] = {{.*}} [ DW_TAG_auto_variable ] [self] [line 51]
13// CHECK: ![[D]] = {{.*}} [d] [line 49]
14
15typedef unsigned int NSUInteger;
16
17@protocol NSObject
18@end
19
20@interface NSObject <NSObject>
21- (id)init;
22+ (id)alloc;
23@end
24
25@interface NSDictionary : NSObject
26- (NSUInteger)count;
27@end
28
29@interface NSMutableDictionary : NSDictionary
30@end
31
32@interface A : NSObject {
33@public
34    int ivar;
35}
36@end
37
38static void run(void (^block)(void))
39{
40    block();
41}
42
43@implementation A
44
45- (id)init
46{
47    if ((self = [super init])) {
48      run(^{
49          NSMutableDictionary *d = [[NSMutableDictionary alloc] init];
50          ivar = 42 + (int)[d count];
51        });
52    }
53    return self;
54}
55
56@end
57
58int main()
59{
60	A *a = [[A alloc] init];
61	return 0;
62}
63