Home | History | Annotate | Download | only in CodeGenObjCXX
      1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -emit-llvm -fobjc-arc -o - %s | FileCheck %s
      2 
      3 id makeObject1() __attribute__((ns_returns_retained));
      4 id makeObject2() __attribute__((ns_returns_retained));
      5 void releaseObject(__attribute__((ns_consumed)) id);
      6 
      7 // CHECK-LABEL: define void @_Z10sanityTestv
      8 void sanityTest() {
      9   // CHECK: [[X:%.*]] = alloca i8*, align 8
     10   // CHECK-NEXT: [[OBJ1:%.*]] = call i8* @_Z11makeObject1v()
     11   // CHECK-NEXT: store i8* [[OBJ1]], i8** [[X]], align 8
     12   id x = makeObject1();
     13 
     14   // CHECK-NEXT: [[OBJ2:%.*]] = call i8* @_Z11makeObject2v()
     15   // CHECK-NEXT: call void @_Z13releaseObjectP11objc_object(i8* [[OBJ2]])
     16   releaseObject(makeObject2());
     17 
     18   // CHECK-NEXT: call void @objc_storeStrong(i8** [[X]], i8* null)
     19   // CHECK-NEXT: ret void
     20 }
     21 
     22 
     23 template <typename T>
     24 T makeObjectT1() __attribute__((ns_returns_retained));
     25 template <typename T>
     26 T makeObjectT2() __attribute__((ns_returns_retained));
     27 
     28 template <typename T>
     29 void releaseObjectT(__attribute__((ns_consumed)) T);  
     30 
     31 // CHECK-LABEL: define void @_Z12templateTestv
     32 void templateTest() {
     33   // CHECK: [[X:%.*]] = alloca i8*, align 8
     34   // CHECK-NEXT: [[OBJ1:%.*]] = call i8* @_Z12makeObjectT1IU8__strongP11objc_objectET_v()
     35   // CHECK-NEXT: store i8* [[OBJ1]], i8** [[X]], align 8
     36   id x = makeObjectT1<id>();
     37 
     38   // CHECK-NEXT: [[OBJ2:%.*]] = call i8* @_Z12makeObjectT2IU8__strongP11objc_objectET_v()
     39   // CHECK-NEXT: call void @_Z13releaseObjectP11objc_object(i8* [[OBJ2]])
     40   releaseObject(makeObjectT2<id>());
     41 
     42   // CHECK-NEXT: [[OBJ3:%.*]] = call i8* @_Z11makeObject1v()
     43   // CHECK-NEXT: call void @_Z14releaseObjectTIU8__strongP11objc_objectEvT_(i8* [[OBJ3]])
     44   releaseObjectT(makeObject1());
     45 
     46   // CHECK-NEXT: call void @objc_storeStrong(i8** [[X]], i8* null)
     47   // CHECK-NEXT: ret void
     48 }
     49