blob: f5f4437b7b59f03c769cd26b435cb22f07310354 [file] [log] [blame]
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001// RUN: %clang_cc1 -emit-llvm -fblocks -g -triple x86_64-apple-darwin10 -fobjc-dispatch-method=mixed -x objective-c < %s -o - | FileCheck %s
Devang Patel1ebb6f292011-05-24 00:22:40 +00002
Adrian Prantl9b97adf2013-03-29 19:20:35 +00003// rdar://problem/9279956
4// Test that we generate the proper debug location for a captured self.
Adrian Prantlb3f111b2013-07-18 00:28:05 +00005// The second half of this test is in llvm/tests/DebugInfo/debug-info-blocks.ll
Adrian Prantl9b97adf2013-03-29 19:20:35 +00006
7// CHECK: define {{.*}}_block_invoke
Adrian Prantlc22856d2013-03-29 23:15:55 +00008// CHECK: %[[BLOCK:.*]] = bitcast i8* %.block_descriptor to <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>*, !dbg
Adrian Prantl9b97adf2013-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
Stephen Hines0e2c34f2015-03-23 12:09:02 -070010// 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 Patel1ebb6f292011-05-24 00:22:40 +000012
Adrian Prantlb3f111b2013-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 Prantlb6cdc962013-07-24 20:34:39 +000018// CHECK: call {{.*}}, !dbg ![[DBG_LINE:[0-9]+]]
19// CHECK-NOT: ret
Adrian Prantlb3f111b2013-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
Stephen Hines0e2c34f2015-03-23 12:09:02 -070025// 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]+]])
Adrian Prantlb3f111b2013-07-18 00:28:05 +000027// CHECK-DAG: [[COPY_SP]] = {{.*}}[ DW_TAG_subprogram ]{{.*}}[__copy_helper_block_]
Stephen Hines0e2c34f2015-03-23 12:09:02 -070028// CHECK-DAG: [[DESTROY_LINE]] = !MDLocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
Adrian Prantlb3f111b2013-07-18 00:28:05 +000029// CHECK-DAG: [[DESTROY_SP]] = {{.*}}[ DW_TAG_subprogram ]{{.*}}[__destroy_helper_block_]
Devang Patel1ebb6f292011-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(^{
Adrian Prantlb3f111b2013-07-18 00:28:05 +000064 // CHECK-DAG: ![[SELF]] = {{.*}} [ DW_TAG_auto_variable ] [self] [line [[@LINE+4]]]
65 // CHECK-DAG: ![[D]] = {{.*}} [d] [line [[@LINE+1]]]
Devang Patel1ebb6f292011-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}