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