Home | History | Annotate | Download | only in CodeGenObjC
      1 // RUN: %clang_cc1 -fblocks -debug-info-kind=limited -emit-llvm -triple x86_64-apple-darwin -o - %s | FileCheck %s
      2 //
      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
     20 typedef 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{{.*}}
     54 // CHECK:        %[[MEM1:.*]] = alloca i8*, align 8
     55 // CHECK-NEXT:   %[[MEM2:.*]] = alloca i8*, align 8
     56 // CHECK-NEXT:   [[DBGADDR:%.*]] = alloca [[BLOCK_T:<{.*}>]]*, align 8
     57 // CHECK:        store i8* [[BLOCK_DESC:%.*]], i8** %[[MEM1]], align 8
     58 // CHECK:        %[[TMP0:.*]] = load i8*, i8** %[[MEM1]]
     59 // 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 !{{.*}})
     61 // CHECK:        store [[BLOCK_T]]* {{%.*}}, [[BLOCK_T]]** [[DBGADDR]], align 8
     62 // CHECK:        call void @llvm.dbg.declare(metadata [[BLOCK_T]]** [[DBGADDR]], metadata ![[SELF:.*]], metadata !{{.*}})
     63 // make sure we are still in the same function
     64 // CHECK: define {{.*}}__copy_helper_block_
     65 // Metadata
     66 // CHECK: ![[MAIN:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Main"
     67 // CHECK-SAME:                            line: 23,
     68 // CHECK: ![[PMAIN:.*]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[MAIN]],
     69 // CHECK: ![[BDMD]] = !DILocalVariable(name: ".block_descriptor", arg:
     70 // CHECK: ![[SELF]] = !DILocalVariable(name: "self"
     71 // CHECK-NOT:                          arg:
     72 // CHECK-SAME:                         line: 40,
     73