1// RUN: %clang_cc1 -emit-llvm -fblocks -g  -triple x86_64-apple-darwin10 -fobjc-dispatch-method=mixed -x objective-c < %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 test 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]+]], metadata !{{.*}})
11// CHECK-NEXT: call void @llvm.dbg.declare(metadata %1** %d, metadata ![[D:[0-9]+]], metadata !{{.*}})
12
13// rdar://problem/14386148
14// Test that we don't emit bogus line numbers for the helper functions.
15// Test that we do emit scope info for the helper functions.
16// CHECK: define {{.*}} @__copy_helper_block_{{.*}}(i8*, i8*)
17// CHECK-NOT: ret
18// CHECK: call {{.*}}, !dbg ![[DBG_LINE:[0-9]+]]
19// CHECK-NOT: ret
20// CHECK: load {{.*}}, !dbg ![[COPY_LINE:[0-9]+]]
21// CHECK: define {{.*}} @__destroy_helper_block_{{.*}}(i8*)
22// CHECK-NOT: ret
23// CHECK: load {{.*}}, !dbg ![[DESTROY_LINE:[0-9]+]]
24
25// CHECK-DAG: [[DBG_LINE]] = !MDLocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
26// CHECK-DAG: [[COPY_LINE]] = !MDLocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
27// CHECK-DAG: [[COPY_SP]] = {{.*}}[ DW_TAG_subprogram ]{{.*}}[__copy_helper_block_]
28// CHECK-DAG: [[DESTROY_LINE]] = !MDLocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
29// CHECK-DAG: [[DESTROY_SP]] = {{.*}}[ DW_TAG_subprogram ]{{.*}}[__destroy_helper_block_]
30typedef unsigned int NSUInteger;
31
32@protocol NSObject
33@end
34
35@interface NSObject <NSObject>
36- (id)init;
37+ (id)alloc;
38@end
39
40@interface NSDictionary : NSObject
41- (NSUInteger)count;
42@end
43
44@interface NSMutableDictionary : NSDictionary
45@end
46
47@interface A : NSObject {
48@public
49    int ivar;
50}
51@end
52
53static void run(void (^block)(void))
54{
55    block();
56}
57
58@implementation A
59
60- (id)init
61{
62    if ((self = [super init])) {
63      run(^{
64          // CHECK-DAG: ![[SELF]] = {{.*}} [ DW_TAG_auto_variable ] [self] [line [[@LINE+4]]]
65          // CHECK-DAG: ![[D]] = {{.*}} [d] [line [[@LINE+1]]]
66          NSMutableDictionary *d = [[NSMutableDictionary alloc] init];
67          ivar = 42 + (int)[d count];
68        });
69    }
70    return self;
71}
72
73@end
74
75int main()
76{
77	A *a = [[A alloc] init];
78	return 0;
79}
80