arc-literals.m
6.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// RUN: %clang_cc1 -I %S/Inputs -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-passes -o - %s | FileCheck %s
#include "literal-support.h"
// Check the various selector names we'll be using, in order.
// CHECK: c"numberWithInt:\00"
// CHECK: c"numberWithUnsignedInt:\00"
// CHECK: c"numberWithUnsignedLongLong:\00"
// CHECK: c"numberWithChar:\00"
// CHECK: c"arrayWithObjects:count:\00"
// CHECK: c"dictionaryWithObjects:forKeys:count:\00"
// CHECK: c"prop\00"
// CHECK-LABEL: define void @test_numeric()
void test_numeric() {
// CHECK: {{call.*objc_msgSend.*i32 17}}
// CHECK: call i8* @llvm.objc.retainAutoreleasedReturnValue
id ilit = @17;
// CHECK: {{call.*objc_msgSend.*i32 25}}
// CHECK: call i8* @llvm.objc.retainAutoreleasedReturnValue
id ulit = @25u;
// CHECK: {{call.*objc_msgSend.*i64 42}}
// CHECK: call i8* @llvm.objc.retainAutoreleasedReturnValue
id ulllit = @42ull;
// CHECK: {{call.*objc_msgSend.*i8 signext 97}}
// CHECK: call i8* @llvm.objc.retainAutoreleasedReturnValue
id charlit = @'a';
// CHECK: call void @llvm.objc.release
// CHECK: call void @llvm.lifetime.end
// CHECK: call void @llvm.objc.release
// CHECK: call void @llvm.lifetime.end
// CHECK: call void @llvm.objc.release
// CHECK: call void @llvm.lifetime.end
// CHECK: call void @llvm.objc.release
// CHECK: call void @llvm.lifetime.end
// CHECK-NEXT: ret void
}
// CHECK-LABEL: define void @test_array
void test_array(id a, id b) {
// CHECK: [[A:%.*]] = alloca i8*,
// CHECK: [[B:%.*]] = alloca i8*,
// Retaining parameters
// CHECK: call i8* @llvm.objc.retain(i8*
// CHECK: call i8* @llvm.objc.retain(i8*
// Constructing the array
// CHECK: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i64 0, i64 0
// CHECK-NEXT: [[V0:%.*]] = load i8*, i8** [[A]],
// CHECK-NEXT: store i8* [[V0]], i8** [[T0]]
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 1
// CHECK-NEXT: [[V1:%.*]] = load i8*, i8** [[B]],
// CHECK-NEXT: store i8* [[V1]], i8** [[T0]]
// CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T:%.*]]*, [[CLASS_T:%.*]]** @"OBJC_CLASSLIST
// CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
// CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8*
// CHECK-NEXT: [[T2:%.*]] = bitcast [2 x i8*]* [[OBJECTS]] to i8**
// CHECK-NEXT: [[T3:%.*]] = call i8* bitcast ({{.*@objc_msgSend.*}})(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i64 2)
// CHECK-NEXT: [[T4:%.*]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[T3]])
// CHECK: call void (...) @llvm.objc.clang.arc.use(i8* [[V0]], i8* [[V1]])
id arr = @[a, b];
// CHECK: call void @llvm.objc.release
// CHECK: call void @llvm.objc.release
// CHECK: call void @llvm.objc.release
// CHECK-NEXT: ret void
}
// CHECK-LABEL: define void @test_dictionary
void test_dictionary(id k1, id o1, id k2, id o2) {
// CHECK: [[K1:%.*]] = alloca i8*,
// CHECK: [[O1:%.*]] = alloca i8*,
// CHECK: [[K2:%.*]] = alloca i8*,
// CHECK: [[O2:%.*]] = alloca i8*,
// Retaining parameters
// CHECK: call i8* @llvm.objc.retain(i8*
// CHECK: call i8* @llvm.objc.retain(i8*
// CHECK: call i8* @llvm.objc.retain(i8*
// CHECK: call i8* @llvm.objc.retain(i8*
// Constructing the arrays
// CHECK: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[KEYS:%[A-Za-z0-9]+]], i64 0, i64 0
// CHECK-NEXT: [[V0:%.*]] = load i8*, i8** [[K1]],
// CHECK-NEXT: store i8* [[V0]], i8** [[T0]]
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i64 0, i64 0
// CHECK-NEXT: [[V1:%.*]] = load i8*, i8** [[O1]],
// CHECK-NEXT: store i8* [[V1]], i8** [[T0]]
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[KEYS]], i64 0, i64 1
// CHECK-NEXT: [[V2:%.*]] = load i8*, i8** [[K2]],
// CHECK-NEXT: store i8* [[V2]], i8** [[T0]]
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 1
// CHECK-NEXT: [[V3:%.*]] = load i8*, i8** [[O2]],
// CHECK-NEXT: store i8* [[V3]], i8** [[T0]]
// Constructing the dictionary
// CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T:%.*]]*, [[CLASS_T:%.*]]** @"OBJC_CLASSLIST
// CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
// CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8*
// CHECK-NEXT: [[T2:%.*]] = bitcast [2 x i8*]* [[OBJECTS]] to i8**
// CHECK-NEXT: [[T3:%.*]] = bitcast [2 x i8*]* [[KEYS]] to i8**
// CHECK-NEXT: [[T4:%.*]] = call i8* bitcast ({{.*@objc_msgSend.*}})(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i8** [[T3]], i64 2)
// CHECK-NEXT: [[T5:%.*]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[T4]])
// CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use(i8* [[V0]], i8* [[V1]], i8* [[V2]], i8* [[V3]])
id dict = @{ k1 : o1, k2 : o2 };
// CHECK: call void @llvm.objc.release
// CHECK: call void @llvm.objc.release
// CHECK: call void @llvm.objc.release
// CHECK: call void @llvm.objc.release
// CHECK: call void @llvm.objc.release
// CHECK-NEXT: ret void
}
@interface A
@end
@interface B
@property (retain) A* prop;
@end
// CHECK-LABEL: define void @test_property
void test_property(B *b) {
// Retain parameter
// CHECK: call i8* @llvm.objc.retain
// CHECK: [[T0:%.*]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[OBJECTS:%.*]], i64 0, i64 0
// Invoke 'prop'
// CHECK: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
// CHECK-NEXT: [[T1:%.*]] = bitcast
// CHECK-NEXT: [[T2:%.*]] = call [[B:%.*]]* bitcast ({{.*}} @objc_msgSend to {{.*}})(i8* [[T1]], i8* [[SEL]])
// CHECK-NEXT: [[T3:%.*]] = bitcast [[B]]* [[T2]] to i8*
// CHECK-NEXT: [[T4:%.*]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[T3]])
// CHECK-NEXT: [[V0:%.*]] = bitcast i8* [[T4]] to [[B]]*
// CHECK-NEXT: [[V1:%.*]] = bitcast [[B]]* [[V0]] to i8*
// Store to array.
// CHECK-NEXT: store i8* [[V1]], i8** [[T0]]
// Invoke arrayWithObjects:count:
// CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T]]*, [[CLASS_T]]** @"OBJC_CLASSLIST
// CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
// CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8*
// CHECK-NEXT: [[T2:%.*]] = bitcast [1 x i8*]* [[OBJECTS]] to i8**
// CHECK-NEXT: [[T3:%.*]] = call i8* bitcast ({{.*}} @objc_msgSend to {{.*}}(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i64 1)
// CHECK-NEXT: call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[T3]])
// CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use(i8* [[V1]])
// CHECK-NEXT: bitcast
// CHECK-NEXT: bitcast
// CHECK-NEXT: store
id arr = @[ b.prop ];
// Release b.prop
// CHECK-NEXT: [[T0:%.*]] = bitcast [[B]]* [[V0]] to i8*
// CHECK-NEXT: call void @llvm.objc.release(i8* [[T0]])
// Destroy arr
// CHECK: call void @llvm.objc.release
// Destroy b
// CHECK: call void @llvm.objc.release
// CHECK-NEXT: ret void
}