blob: e142a0bceb8ff9449cd62e66410c177abcfe313b [file] [log] [blame]
Douglas Katzman3459ce22015-10-08 04:24:12 +00001// RUN: %clang_cc1 -fblocks -debug-info-kind=limited -emit-llvm -triple x86_64-apple-darwin -o - %s | FileCheck %s
Adrian Prantl51936dd2013-03-14 17:53:33 +00002//
3// Test that debug location is generated for a captured "self" inside
4// a block.
5//
6// This test is split into two parts, this one for the frontend, and
7// then llvm/test/DebugInfo/debug-info-block-captured-self.ll to
8// ensure that DW_AT_location is generated for the captured self.
9@class T;
10@interface S
11@end
12@interface Mode
13-(int) count;
14@end
15@interface Context
16@end
17@interface ViewController
18@property (nonatomic, readwrite, strong) Context *context;
19@end
20typedef enum {
21 Unknown = 0,
22} State;
23@interface Main : ViewController
24{
25 T * t1;
26 T * t2;
27}
28@property(readwrite, nonatomic) State state;
29@end
30@implementation Main
31- (id) initWithContext:(Context *) context
32{
33 t1 = [self.context withBlock:^(id obj){
34 id *mode1;
35 t2 = [mode1 withBlock:^(id object){
36 Mode *mode2 = object;
37 if ([mode2 count] != 0) {
38 self.state = 0;
39 }
40 }];
41 }];
42}
43@end
44// The important part of this test is that there is a dbg.value
45// intrinsic associated with the implicit .block_descriptor argument
46// of the block. We also test that this value gets alloca'd, so the
47// register llocator won't accidentally kill it.
48
49// outer block:
50// CHECK: define internal void {{.*}}_block_invoke{{.*}}
51
52// inner block:
53// CHECK: define internal void {{.*}}_block_invoke{{.*}}
Adrian Prantl0f6df002013-03-29 19:20:35 +000054// CHECK: %[[MEM1:.*]] = alloca i8*, align 8
55// CHECK-NEXT: %[[MEM2:.*]] = alloca i8*, align 8
John McCall7f416cc2015-09-08 08:05:57 +000056// CHECK-NEXT: [[DBGADDR:%.*]] = alloca [[BLOCK_T:<{.*}>]]*, align 8
Adrian Prantl0f6df002013-03-29 19:20:35 +000057// CHECK: store i8* [[BLOCK_DESC:%.*]], i8** %[[MEM1]], align 8
David Blaikiea953f282015-02-27 21:19:58 +000058// CHECK: %[[TMP0:.*]] = load i8*, i8** %[[MEM1]]
Duncan P. N. Exon Smithb3a66692014-12-15 19:10:08 +000059// CHECK: call void @llvm.dbg.value(metadata i8* %[[TMP0]], i64 0, metadata ![[BDMD:[0-9]+]], metadata !{{.*}})
60// CHECK: call void @llvm.dbg.declare(metadata i8* [[BLOCK_DESC]], metadata ![[BDMD:[0-9]+]], metadata !{{.*}})
John McCall7f416cc2015-09-08 08:05:57 +000061// CHECK: store [[BLOCK_T]]* {{%.*}}, [[BLOCK_T]]** [[DBGADDR]], align 8
62// CHECK: call void @llvm.dbg.declare(metadata [[BLOCK_T]]** [[DBGADDR]], metadata ![[SELF:.*]], metadata !{{.*}})
Adrian Prantl0f6df002013-03-29 19:20:35 +000063// make sure we are still in the same function
64// CHECK: define {{.*}}__copy_helper_block_
65// Metadata
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000066// CHECK: ![[MAIN:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Main"
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000067// CHECK-SAME: line: 23,
Duncan P. N. Exon Smith9dd4e4e2015-04-29 16:40:08 +000068// CHECK: ![[PMAIN:.*]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[MAIN]],
Duncan P. N. Exon Smith38a7f112015-07-31 18:59:37 +000069// CHECK: ![[BDMD]] = !DILocalVariable(name: ".block_descriptor", arg:
70// CHECK: ![[SELF]] = !DILocalVariable(name: "self"
71// CHECK-NOT: arg:
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000072// CHECK-SAME: line: 40,