• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5struct X {
6  X();
7  ~X();
8  operator id() const;
9};
10
11struct Y {
12  Y();
13  ~Y();
14  operator id() const;
15};
16
17// CHECK-LABEL: define void @_Z10test_arrayv
18void test_array() {
19  // CHECK: [[ARR:%[a-zA-Z0-9.]+]] = alloca i8*
20  // CHECK: [[OBJECTS:%[a-zA-Z0-9.]+]] = alloca [2 x i8*]
21
22  // Initializing first element
23  // CHECK: [[PTR1:%.*]] = bitcast i8** [[ARR]] to i8*
24  // CHECK-NEXT: call void @llvm.lifetime.start(i64 8, i8* [[PTR1]])
25  // CHECK: [[ELEMENT0:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 0
26  // CHECK-NEXT: call void @_ZN1XC1Ev
27  // CHECK-NEXT: [[OBJECT0:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1XcvP11objc_objectEv
28  // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[OBJECT0]])
29  // CHECK: store i8* [[RET0]], i8** [[ELEMENT0]]
30
31  // Initializing the second element
32  // CHECK: [[ELEMENT1:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 1
33  // CHECK-NEXT: invoke void @_ZN1YC1Ev
34  // CHECK: [[OBJECT1:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1YcvP11objc_objectEv
35  // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[OBJECT1]])
36  // CHECK: store i8* [[RET1]], i8** [[ELEMENT1]]
37
38  // Build the array
39  // CHECK: {{invoke.*@objc_msgSend}}
40  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
41  id arr = @[ X(), Y() ];
42
43  // Destroy temporaries
44  // CHECK-NOT: ret void
45  // CHECK: call void @objc_release
46  // CHECK-NOT: ret void
47  // CHECK: invoke void @_ZN1YD1Ev
48  // CHECK-NOT: ret void
49  // CHECK: call void @objc_release
50  // CHECK-NEXT: call void @_ZN1XD1Ev
51  // CHECK-NOT: ret void
52  // CHECK: call void @objc_release
53  // CHECK-NEXT: [[PTR2:%.*]] = bitcast i8** [[ARR]] to i8*
54  // CHECK-NEXT: call void @llvm.lifetime.end(i64 8, i8* [[PTR2]])
55  // CHECK-NEXT: ret void
56
57  // Check cleanups
58  // CHECK: call void @objc_release
59  // CHECK-NOT: call void @objc_release
60  // CHECK: invoke void @_ZN1YD1Ev
61  // CHECK: call void @objc_release
62  // CHECK-NOT: call void @objc_release
63  // CHECK: invoke void @_ZN1XD1Ev
64  // CHECK-NOT: call void @objc_release
65  // CHECK: unreachable
66}
67
68// CHECK-LABEL: define weak_odr void @_Z24test_array_instantiationIiEvv
69template<typename T>
70void test_array_instantiation() {
71  // CHECK: [[ARR:%[a-zA-Z0-9.]+]] = alloca i8*
72  // CHECK: [[OBJECTS:%[a-zA-Z0-9.]+]] = alloca [2 x i8*]
73
74  // Initializing first element
75  // CHECK:      [[PTR1:%.*]] = bitcast i8** [[ARR]] to i8*
76  // CHECK-NEXT: call void @llvm.lifetime.start(i64 8, i8* [[PTR1]])
77  // CHECK: [[ELEMENT0:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 0
78  // CHECK-NEXT: call void @_ZN1XC1Ev
79  // CHECK-NEXT: [[OBJECT0:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1XcvP11objc_objectEv
80  // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[OBJECT0]])
81  // CHECK: store i8* [[RET0]], i8** [[ELEMENT0]]
82
83  // Initializing the second element
84  // CHECK: [[ELEMENT1:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 1
85  // CHECK-NEXT: invoke void @_ZN1YC1Ev
86  // CHECK: [[OBJECT1:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1YcvP11objc_objectEv
87  // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[OBJECT1]])
88  // CHECK: store i8* [[RET1]], i8** [[ELEMENT1]]
89
90  // Build the array
91  // CHECK: {{invoke.*@objc_msgSend}}
92  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
93  id arr = @[ X(), Y() ];
94
95  // Destroy temporaries
96  // CHECK-NOT: ret void
97  // CHECK: call void @objc_release
98  // CHECK-NOT: ret void
99  // CHECK: invoke void @_ZN1YD1Ev
100  // CHECK-NOT: ret void
101  // CHECK: call void @objc_release
102  // CHECK-NEXT: call void @_ZN1XD1Ev
103  // CHECK-NOT: ret void
104  // CHECK: call void @objc_release
105  // CHECK-NEXT: [[PTR2]] = bitcast i8** [[ARR]] to i8*
106  // CHECK-NEXT: call void @llvm.lifetime.end(i64 8, i8* [[PTR2]])
107  // CHECK-NEXT: ret void
108
109  // Check cleanups
110  // CHECK: call void @objc_release
111  // CHECK-NOT: call void @objc_release
112  // CHECK: invoke void @_ZN1YD1Ev
113  // CHECK: call void @objc_release
114  // CHECK-NOT: call void @objc_release
115  // CHECK: invoke void @_ZN1XD1Ev
116  // CHECK-NOT: call void @objc_release
117  // CHECK: unreachable
118}
119
120template void test_array_instantiation<int>();
121
122