blob: 0bf566395aa995d43523595edff45fc65974cd8d [file] [log] [blame]
Douglas Katzman3459ce22015-10-08 04:24:12 +00001// RUN: %clang_cc1 -emit-llvm -fblocks -debug-info-kind=limited -triple x86_64-apple-darwin10 -fobjc-dispatch-method=mixed -x objective-c < %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
Duncan P. N. Exon Smithb3a66692014-12-15 19:10:08 +000010// 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 !{{.*}})
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
Adrian Prantl49a78562013-07-24 20:34:39 +000018// CHECK: call {{.*}}, !dbg ![[DBG_LINE:[0-9]+]]
19// CHECK-NOT: ret
Adrian Prantl01eb2a52013-07-18 00:28:05 +000020// 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
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000025// CHECK-DAG: [[DBG_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
26// CHECK-DAG: [[COPY_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
Duncan P. N. Exon Smith8cd9d7a2015-08-26 22:50:48 +000027// CHECK-DAG: [[COPY_SP]] = distinct !DISubprogram(name: "__copy_helper_block_"
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000028// CHECK-DAG: [[DESTROY_LINE]] = !DILocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
Duncan P. N. Exon Smith8cd9d7a2015-08-26 22:50:48 +000029// CHECK-DAG: [[DESTROY_SP]] = distinct !DISubprogram(name: "__destroy_helper_block_"
Devang Patel433a11b2011-05-24 00:22:40 +000030typedef 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(^{
Duncan P. N. Exon Smith38a7f112015-07-31 18:59:37 +000064 // CHECK-DAG: ![[SELF]] = !DILocalVariable(name: "self", scope:{{.*}}, line: [[@LINE+4]],
65 // CHECK-DAG: ![[D]] = !DILocalVariable(name: "d", scope:{{.*}}, line: [[@LINE+1]],
Devang Patel433a11b2011-05-24 00:22:40 +000066 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}