xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjCXX/literals.mm (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// 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*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc#include "literal-support.h"
4*f4a2713aSLionel Sambuc
5*f4a2713aSLionel Sambucstruct X {
6*f4a2713aSLionel Sambuc  X();
7*f4a2713aSLionel Sambuc  ~X();
8*f4a2713aSLionel Sambuc  operator id() const;
9*f4a2713aSLionel Sambuc};
10*f4a2713aSLionel Sambuc
11*f4a2713aSLionel Sambucstruct Y {
12*f4a2713aSLionel Sambuc  Y();
13*f4a2713aSLionel Sambuc  ~Y();
14*f4a2713aSLionel Sambuc  operator id() const;
15*f4a2713aSLionel Sambuc};
16*f4a2713aSLionel Sambuc
17*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @_Z10test_arrayv
18*f4a2713aSLionel Sambucvoid test_array() {
19*f4a2713aSLionel Sambuc  // CHECK: [[OBJECTS:%[a-zA-Z0-9.]+]] = alloca [2 x i8*]
20*f4a2713aSLionel Sambuc
21*f4a2713aSLionel Sambuc  // Initializing first element
22*f4a2713aSLionel Sambuc  // CHECK: [[ELEMENT0:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 0
23*f4a2713aSLionel Sambuc  // CHECK-NEXT: call void @_ZN1XC1Ev
24*f4a2713aSLionel Sambuc  // CHECK-NEXT: [[OBJECT0:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1XcvP11objc_objectEv
25*f4a2713aSLionel Sambuc  // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[OBJECT0]])
26*f4a2713aSLionel Sambuc  // CHECK: store i8* [[RET0]], i8** [[ELEMENT0]]
27*f4a2713aSLionel Sambuc
28*f4a2713aSLionel Sambuc  // Initializing the second element
29*f4a2713aSLionel Sambuc  // CHECK: [[ELEMENT1:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 1
30*f4a2713aSLionel Sambuc  // CHECK-NEXT: invoke void @_ZN1YC1Ev
31*f4a2713aSLionel Sambuc  // CHECK: [[OBJECT1:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1YcvP11objc_objectEv
32*f4a2713aSLionel Sambuc  // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[OBJECT1]])
33*f4a2713aSLionel Sambuc  // CHECK: store i8* [[RET1]], i8** [[ELEMENT1]]
34*f4a2713aSLionel Sambuc
35*f4a2713aSLionel Sambuc  // Build the array
36*f4a2713aSLionel Sambuc  // CHECK: {{invoke.*@objc_msgSend}}
37*f4a2713aSLionel Sambuc  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
38*f4a2713aSLionel Sambuc  id arr = @[ X(), Y() ];
39*f4a2713aSLionel Sambuc
40*f4a2713aSLionel Sambuc  // Destroy temporaries
41*f4a2713aSLionel Sambuc  // CHECK-NOT: ret void
42*f4a2713aSLionel Sambuc  // CHECK: call void @objc_release
43*f4a2713aSLionel Sambuc  // CHECK-NOT: ret void
44*f4a2713aSLionel Sambuc  // CHECK: invoke void @_ZN1YD1Ev
45*f4a2713aSLionel Sambuc  // CHECK-NOT: ret void
46*f4a2713aSLionel Sambuc  // CHECK: call void @objc_release
47*f4a2713aSLionel Sambuc  // CHECK-NEXT: call void @_ZN1XD1Ev
48*f4a2713aSLionel Sambuc  // CHECK-NOT: ret void
49*f4a2713aSLionel Sambuc  // CHECK: call void @objc_release
50*f4a2713aSLionel Sambuc  // CHECK-NEXT: ret void
51*f4a2713aSLionel Sambuc
52*f4a2713aSLionel Sambuc  // Check cleanups
53*f4a2713aSLionel Sambuc  // CHECK: call void @objc_release
54*f4a2713aSLionel Sambuc  // CHECK-NOT: call void @objc_release
55*f4a2713aSLionel Sambuc  // CHECK: invoke void @_ZN1YD1Ev
56*f4a2713aSLionel Sambuc  // CHECK: call void @objc_release
57*f4a2713aSLionel Sambuc  // CHECK-NOT: call void @objc_release
58*f4a2713aSLionel Sambuc  // CHECK: invoke void @_ZN1XD1Ev
59*f4a2713aSLionel Sambuc  // CHECK-NOT: call void @objc_release
60*f4a2713aSLionel Sambuc  // CHECK: unreachable
61*f4a2713aSLionel Sambuc}
62*f4a2713aSLionel Sambuc
63*f4a2713aSLionel Sambuc// CHECK-LABEL: define weak_odr void @_Z24test_array_instantiationIiEvv
64*f4a2713aSLionel Sambuctemplate<typename T>
65*f4a2713aSLionel Sambucvoid test_array_instantiation() {
66*f4a2713aSLionel Sambuc  // CHECK: [[OBJECTS:%[a-zA-Z0-9.]+]] = alloca [2 x i8*]
67*f4a2713aSLionel Sambuc
68*f4a2713aSLionel Sambuc  // Initializing first element
69*f4a2713aSLionel Sambuc  // CHECK: [[ELEMENT0:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 0
70*f4a2713aSLionel Sambuc  // CHECK-NEXT: call void @_ZN1XC1Ev
71*f4a2713aSLionel Sambuc  // CHECK-NEXT: [[OBJECT0:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1XcvP11objc_objectEv
72*f4a2713aSLionel Sambuc  // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[OBJECT0]])
73*f4a2713aSLionel Sambuc  // CHECK: store i8* [[RET0]], i8** [[ELEMENT0]]
74*f4a2713aSLionel Sambuc
75*f4a2713aSLionel Sambuc  // Initializing the second element
76*f4a2713aSLionel Sambuc  // CHECK: [[ELEMENT1:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 1
77*f4a2713aSLionel Sambuc  // CHECK-NEXT: invoke void @_ZN1YC1Ev
78*f4a2713aSLionel Sambuc  // CHECK: [[OBJECT1:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1YcvP11objc_objectEv
79*f4a2713aSLionel Sambuc  // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[OBJECT1]])
80*f4a2713aSLionel Sambuc  // CHECK: store i8* [[RET1]], i8** [[ELEMENT1]]
81*f4a2713aSLionel Sambuc
82*f4a2713aSLionel Sambuc  // Build the array
83*f4a2713aSLionel Sambuc  // CHECK: {{invoke.*@objc_msgSend}}
84*f4a2713aSLionel Sambuc  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
85*f4a2713aSLionel Sambuc  id arr = @[ X(), Y() ];
86*f4a2713aSLionel Sambuc
87*f4a2713aSLionel Sambuc  // Destroy temporaries
88*f4a2713aSLionel Sambuc  // CHECK-NOT: ret void
89*f4a2713aSLionel Sambuc  // CHECK: call void @objc_release
90*f4a2713aSLionel Sambuc  // CHECK-NOT: ret void
91*f4a2713aSLionel Sambuc  // CHECK: invoke void @_ZN1YD1Ev
92*f4a2713aSLionel Sambuc  // CHECK-NOT: ret void
93*f4a2713aSLionel Sambuc  // CHECK: call void @objc_release
94*f4a2713aSLionel Sambuc  // CHECK-NEXT: call void @_ZN1XD1Ev
95*f4a2713aSLionel Sambuc  // CHECK-NOT: ret void
96*f4a2713aSLionel Sambuc  // CHECK: call void @objc_release
97*f4a2713aSLionel Sambuc  // CHECK-NEXT: ret void
98*f4a2713aSLionel Sambuc
99*f4a2713aSLionel Sambuc  // Check cleanups
100*f4a2713aSLionel Sambuc  // CHECK: call void @objc_release
101*f4a2713aSLionel Sambuc  // CHECK-NOT: call void @objc_release
102*f4a2713aSLionel Sambuc  // CHECK: invoke void @_ZN1YD1Ev
103*f4a2713aSLionel Sambuc  // CHECK: call void @objc_release
104*f4a2713aSLionel Sambuc  // CHECK-NOT: call void @objc_release
105*f4a2713aSLionel Sambuc  // CHECK: invoke void @_ZN1XD1Ev
106*f4a2713aSLionel Sambuc  // CHECK-NOT: call void @objc_release
107*f4a2713aSLionel Sambuc  // CHECK: unreachable
108*f4a2713aSLionel Sambuc}
109*f4a2713aSLionel Sambuc
110*f4a2713aSLionel Sambuctemplate void test_array_instantiation<int>();
111*f4a2713aSLionel Sambuc
112