Home | History | Annotate | Download | only in CodeGenObjCXX
      1 // RUN: %clang_cc1 -I %S/Inputs -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-arc-exceptions -O2 -disable-llvm-optzns -o - %s | FileCheck %s
      2 
      3 #include "literal-support.h"
      4 
      5 struct X {
      6   X();
      7   ~X();
      8   operator id() const;
      9 };
     10 
     11 struct Y {
     12   Y();
     13   ~Y();
     14   operator id() const;
     15 };
     16 
     17 // CHECK-LABEL: define void @_Z10test_arrayv
     18 void test_array() {
     19   // CHECK: [[OBJECTS:%[a-zA-Z0-9.]+]] = alloca [2 x i8*]
     20 
     21   // Initializing first element
     22   // CHECK: [[ELEMENT0:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 0
     23   // CHECK-NEXT: call void @_ZN1XC1Ev
     24   // CHECK-NEXT: [[OBJECT0:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1XcvP11objc_objectEv
     25   // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[OBJECT0]])
     26   // CHECK: store i8* [[RET0]], i8** [[ELEMENT0]]
     27   
     28   // Initializing the second element
     29   // CHECK: [[ELEMENT1:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 1
     30   // CHECK-NEXT: invoke void @_ZN1YC1Ev
     31   // CHECK: [[OBJECT1:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1YcvP11objc_objectEv
     32   // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[OBJECT1]])
     33   // CHECK: store i8* [[RET1]], i8** [[ELEMENT1]]
     34 
     35   // Build the array
     36   // CHECK: {{invoke.*@objc_msgSend}}
     37   // CHECK: call i8* @objc_retainAutoreleasedReturnValue
     38   id arr = @[ X(), Y() ];
     39 
     40   // Destroy temporaries
     41   // CHECK-NOT: ret void
     42   // CHECK: call void @objc_release
     43   // CHECK-NOT: ret void
     44   // CHECK: invoke void @_ZN1YD1Ev
     45   // CHECK-NOT: ret void
     46   // CHECK: call void @objc_release
     47   // CHECK-NEXT: call void @_ZN1XD1Ev
     48   // CHECK-NOT: ret void
     49   // CHECK: call void @objc_release
     50   // CHECK-NEXT: ret void
     51 
     52   // Check cleanups
     53   // CHECK: call void @objc_release
     54   // CHECK-NOT: call void @objc_release
     55   // CHECK: invoke void @_ZN1YD1Ev
     56   // CHECK: call void @objc_release
     57   // CHECK-NOT: call void @objc_release
     58   // CHECK: invoke void @_ZN1XD1Ev
     59   // CHECK-NOT: call void @objc_release
     60   // CHECK: unreachable
     61 }
     62 
     63 // CHECK-LABEL: define weak_odr void @_Z24test_array_instantiationIiEvv
     64 template<typename T>
     65 void test_array_instantiation() {
     66   // CHECK: [[OBJECTS:%[a-zA-Z0-9.]+]] = alloca [2 x i8*]
     67 
     68   // Initializing first element
     69   // CHECK: [[ELEMENT0:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 0
     70   // CHECK-NEXT: call void @_ZN1XC1Ev
     71   // CHECK-NEXT: [[OBJECT0:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1XcvP11objc_objectEv
     72   // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[OBJECT0]])
     73   // CHECK: store i8* [[RET0]], i8** [[ELEMENT0]]
     74   
     75   // Initializing the second element
     76   // CHECK: [[ELEMENT1:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 1
     77   // CHECK-NEXT: invoke void @_ZN1YC1Ev
     78   // CHECK: [[OBJECT1:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1YcvP11objc_objectEv
     79   // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[OBJECT1]])
     80   // CHECK: store i8* [[RET1]], i8** [[ELEMENT1]]
     81 
     82   // Build the array
     83   // CHECK: {{invoke.*@objc_msgSend}}
     84   // CHECK: call i8* @objc_retainAutoreleasedReturnValue
     85   id arr = @[ X(), Y() ];
     86 
     87   // Destroy temporaries
     88   // CHECK-NOT: ret void
     89   // CHECK: call void @objc_release
     90   // CHECK-NOT: ret void
     91   // CHECK: invoke void @_ZN1YD1Ev
     92   // CHECK-NOT: ret void
     93   // CHECK: call void @objc_release
     94   // CHECK-NEXT: call void @_ZN1XD1Ev
     95   // CHECK-NOT: ret void
     96   // CHECK: call void @objc_release
     97   // CHECK-NEXT: ret void
     98 
     99   // Check cleanups
    100   // CHECK: call void @objc_release
    101   // CHECK-NOT: call void @objc_release
    102   // CHECK: invoke void @_ZN1YD1Ev
    103   // CHECK: call void @objc_release
    104   // CHECK-NOT: call void @objc_release
    105   // CHECK: invoke void @_ZN1XD1Ev
    106   // CHECK-NOT: call void @objc_release
    107   // CHECK: unreachable
    108 }
    109 
    110 template void test_array_instantiation<int>();
    111 
    112