blob: d9ac24edbbc658d0ff9169f1730ba764d99deb12 [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.
Adrian Prantl01eb2a52013-07-18 00:28:05 +00005// The second half of this test is in llvm/tests/DebugInfo/debug-info-blocks.ll
Adrian Prantl0f6df002013-03-29 19:20:35 +00006
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
Adrian Prantl0f6df002013-03-29 19:20:35 +000010// 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]+]])
Devang Patel433a11b2011-05-24 00:22:40 +000012
Adrian Prantl01eb2a52013-07-18 00:28:05 +000013// 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: load {{.*}}, !dbg ![[COPY_LINE:[0-9]+]]
19// CHECK: define {{.*}} @__destroy_helper_block_{{.*}}(i8*)
20// CHECK-NOT: ret
21// CHECK: load {{.*}}, !dbg ![[DESTROY_LINE:[0-9]+]]
22
23// CHECK-DAG: [[COPY_LINE]] = metadata !{i32 0, i32 0, metadata ![[COPY_SP:[0-9]+]], null}
24// CHECK-DAG: [[COPY_SP]] = {{.*}}[ DW_TAG_subprogram ]{{.*}}[__copy_helper_block_]
25// CHECK-DAG: [[DESTROY_LINE]] = metadata !{i32 0, i32 0, metadata ![[DESTROY_SP:[0-9]+]], null}
26// CHECK-DAG: [[DESTROY_SP]] = {{.*}}[ DW_TAG_subprogram ]{{.*}}[__destroy_helper_block_]
Devang Patel433a11b2011-05-24 00:22:40 +000027typedef unsigned int NSUInteger;
28
29@protocol NSObject
30@end
31
32@interface NSObject <NSObject>
33- (id)init;
34+ (id)alloc;
35@end
36
37@interface NSDictionary : NSObject
38- (NSUInteger)count;
39@end
40
41@interface NSMutableDictionary : NSDictionary
42@end
43
44@interface A : NSObject {
45@public
46 int ivar;
47}
48@end
49
50static void run(void (^block)(void))
51{
52 block();
53}
54
55@implementation A
56
57- (id)init
58{
59 if ((self = [super init])) {
60 run(^{
Adrian Prantl01eb2a52013-07-18 00:28:05 +000061 // CHECK-DAG: ![[SELF]] = {{.*}} [ DW_TAG_auto_variable ] [self] [line [[@LINE+4]]]
62 // CHECK-DAG: ![[D]] = {{.*}} [d] [line [[@LINE+1]]]
Devang Patel433a11b2011-05-24 00:22:40 +000063 NSMutableDictionary *d = [[NSMutableDictionary alloc] init];
64 ivar = 42 + (int)[d count];
65 });
66 }
67 return self;
68}
69
70@end
71
72int main()
73{
74 A *a = [[A alloc] init];
75 return 0;
76}