xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjC/debug-info-blocks.m (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc// RUN: %clang_cc1 -emit-llvm -fblocks -g  -triple x86_64-apple-darwin10 -fobjc-dispatch-method=mixed -x objective-c < %s -o - | FileCheck %s
2f4a2713aSLionel Sambuc
3f4a2713aSLionel Sambuc// rdar://problem/9279956
4f4a2713aSLionel Sambuc// Test that we generate the proper debug location for a captured self.
5f4a2713aSLionel Sambuc// The second half of this test is in llvm/tests/DebugInfo/debug-info-blocks.ll
6f4a2713aSLionel Sambuc
7f4a2713aSLionel Sambuc// CHECK: define {{.*}}_block_invoke
8f4a2713aSLionel Sambuc// CHECK: %[[BLOCK:.*]] = bitcast i8* %.block_descriptor to <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>*, !dbg
9f4a2713aSLionel Sambuc// CHECK-NEXT: store <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %[[BLOCK]], <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA:.*]], align
10*0a6a1f1dSLionel Sambuc// CHECK-NEXT: call void @llvm.dbg.declare(metadata <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA]], metadata ![[SELF:[0-9]+]], metadata !{{.*}})
11*0a6a1f1dSLionel Sambuc// CHECK-NEXT: call void @llvm.dbg.declare(metadata %1** %d, metadata ![[D:[0-9]+]], metadata !{{.*}})
12f4a2713aSLionel Sambuc
13f4a2713aSLionel Sambuc// rdar://problem/14386148
14f4a2713aSLionel Sambuc// Test that we don't emit bogus line numbers for the helper functions.
15f4a2713aSLionel Sambuc// Test that we do emit scope info for the helper functions.
16f4a2713aSLionel Sambuc// CHECK: define {{.*}} @__copy_helper_block_{{.*}}(i8*, i8*)
17f4a2713aSLionel Sambuc// CHECK-NOT: ret
18f4a2713aSLionel Sambuc// CHECK: call {{.*}}, !dbg ![[DBG_LINE:[0-9]+]]
19f4a2713aSLionel Sambuc// CHECK-NOT: ret
20f4a2713aSLionel Sambuc// CHECK: load {{.*}}, !dbg ![[COPY_LINE:[0-9]+]]
21f4a2713aSLionel Sambuc// CHECK: define {{.*}} @__destroy_helper_block_{{.*}}(i8*)
22f4a2713aSLionel Sambuc// CHECK-NOT: ret
23f4a2713aSLionel Sambuc// CHECK: load {{.*}}, !dbg ![[DESTROY_LINE:[0-9]+]]
24f4a2713aSLionel Sambuc
25*0a6a1f1dSLionel Sambuc// CHECK-DAG: [[DBG_LINE]] = !MDLocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
26*0a6a1f1dSLionel Sambuc// CHECK-DAG: [[COPY_LINE]] = !MDLocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
27f4a2713aSLionel Sambuc// CHECK-DAG: [[COPY_SP]] = {{.*}}[ DW_TAG_subprogram ]{{.*}}[__copy_helper_block_]
28*0a6a1f1dSLionel Sambuc// CHECK-DAG: [[DESTROY_LINE]] = !MDLocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
29f4a2713aSLionel Sambuc// CHECK-DAG: [[DESTROY_SP]] = {{.*}}[ DW_TAG_subprogram ]{{.*}}[__destroy_helper_block_]
30f4a2713aSLionel Sambuctypedef unsigned int NSUInteger;
31f4a2713aSLionel Sambuc
32f4a2713aSLionel Sambuc@protocol NSObject
33f4a2713aSLionel Sambuc@end
34f4a2713aSLionel Sambuc
35f4a2713aSLionel Sambuc@interface NSObject <NSObject>
36f4a2713aSLionel Sambuc- (id)init;
37f4a2713aSLionel Sambuc+ (id)alloc;
38f4a2713aSLionel Sambuc@end
39f4a2713aSLionel Sambuc
40f4a2713aSLionel Sambuc@interface NSDictionary : NSObject
41f4a2713aSLionel Sambuc- (NSUInteger)count;
42f4a2713aSLionel Sambuc@end
43f4a2713aSLionel Sambuc
44f4a2713aSLionel Sambuc@interface NSMutableDictionary : NSDictionary
45f4a2713aSLionel Sambuc@end
46f4a2713aSLionel Sambuc
47f4a2713aSLionel Sambuc@interface A : NSObject {
48f4a2713aSLionel Sambuc@public
49f4a2713aSLionel Sambuc    int ivar;
50f4a2713aSLionel Sambuc}
51f4a2713aSLionel Sambuc@end
52f4a2713aSLionel Sambuc
53f4a2713aSLionel Sambucstatic void run(void (^block)(void))
54f4a2713aSLionel Sambuc{
55f4a2713aSLionel Sambuc    block();
56f4a2713aSLionel Sambuc}
57f4a2713aSLionel Sambuc
58f4a2713aSLionel Sambuc@implementation A
59f4a2713aSLionel Sambuc
60f4a2713aSLionel Sambuc- (id)init
61f4a2713aSLionel Sambuc{
62f4a2713aSLionel Sambuc    if ((self = [super init])) {
63f4a2713aSLionel Sambuc      run(^{
64f4a2713aSLionel Sambuc          // CHECK-DAG: ![[SELF]] = {{.*}} [ DW_TAG_auto_variable ] [self] [line [[@LINE+4]]]
65f4a2713aSLionel Sambuc          // CHECK-DAG: ![[D]] = {{.*}} [d] [line [[@LINE+1]]]
66f4a2713aSLionel Sambuc          NSMutableDictionary *d = [[NSMutableDictionary alloc] init];
67f4a2713aSLionel Sambuc          ivar = 42 + (int)[d count];
68f4a2713aSLionel Sambuc        });
69f4a2713aSLionel Sambuc    }
70f4a2713aSLionel Sambuc    return self;
71f4a2713aSLionel Sambuc}
72f4a2713aSLionel Sambuc
73f4a2713aSLionel Sambuc@end
74f4a2713aSLionel Sambuc
75f4a2713aSLionel Sambucint main()
76f4a2713aSLionel Sambuc{
77f4a2713aSLionel Sambuc	A *a = [[A alloc] init];
78f4a2713aSLionel Sambuc	return 0;
79f4a2713aSLionel Sambuc}
80