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