1 // RUN: %clang_cc1 -I %S/Inputs -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-passes -no-enable-noundef-analysis -o - %s | FileCheck %s
3 #include "literal-support.h"
5 // Check the various selector names we'll be using, in order.
7 // CHECK: c"numberWithInt:\00"
8 // CHECK: c"numberWithUnsignedInt:\00"
9 // CHECK: c"numberWithUnsignedLongLong:\00"
10 // CHECK: c"numberWithChar:\00"
11 // CHECK: c"arrayWithObjects:count:\00"
12 // CHECK: c"dictionaryWithObjects:forKeys:count:\00"
15 // CHECK-LABEL: define{{.*}} void @test_numeric()
16 void test_numeric(void) {
17 // CHECK: {{call.*objc_msgSend.*i32 17.* [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]}}
19 // CHECK: {{call.*objc_msgSend.*i32 25.* [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]}}
21 // CHECK: {{call.*objc_msgSend.*i64 42.* [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]}}
23 // CHECK: {{call.*objc_msgSend.*i8 signext 97.* [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]}}
25 // CHECK: call void @llvm.objc.release
26 // CHECK: call void @llvm.lifetime.end
27 // CHECK: call void @llvm.objc.release
28 // CHECK: call void @llvm.lifetime.end
29 // CHECK: call void @llvm.objc.release
30 // CHECK: call void @llvm.lifetime.end
31 // CHECK: call void @llvm.objc.release
32 // CHECK: call void @llvm.lifetime.end
33 // CHECK-NEXT: ret void
36 // CHECK-LABEL: define{{.*}} void @test_array
37 void test_array(id a, id b) {
38 // CHECK: [[A:%.*]] = alloca i8*,
39 // CHECK: [[B:%.*]] = alloca i8*,
41 // Retaining parameters
42 // CHECK: call i8* @llvm.objc.retain(i8*
43 // CHECK: call i8* @llvm.objc.retain(i8*
45 // Constructing the array
46 // CHECK: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i64 0, i64 0
47 // CHECK-NEXT: [[V0:%.*]] = load i8*, i8** [[A]],
48 // CHECK-NEXT: store i8* [[V0]], i8** [[T0]]
49 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 1
50 // CHECK-NEXT: [[V1:%.*]] = load i8*, i8** [[B]],
51 // CHECK-NEXT: store i8* [[V1]], i8** [[T0]]
53 // CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T:%.*]]*, [[CLASS_T:%.*]]** @"OBJC_CLASSLIST
54 // CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8*
55 // CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
56 // CHECK-NEXT: [[T2:%.*]] = bitcast [2 x i8*]* [[OBJECTS]] to i8**
57 // CHECK-NEXT: [[T3:%.*]] = call i8* bitcast ({{.*@objc_msgSend.*}})(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i64 2) [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]
58 // CHECK: call void (...) @llvm.objc.clang.arc.use(i8* [[V0]], i8* [[V1]])
61 // CHECK: call void @llvm.objc.release
62 // CHECK: call void @llvm.objc.release
63 // CHECK: call void @llvm.objc.release
64 // CHECK-NEXT: ret void
67 // CHECK-LABEL: define{{.*}} void @test_dictionary
68 void test_dictionary(id k1, id o1, id k2, id o2) {
69 // CHECK: [[K1:%.*]] = alloca i8*,
70 // CHECK: [[O1:%.*]] = alloca i8*,
71 // CHECK: [[K2:%.*]] = alloca i8*,
72 // CHECK: [[O2:%.*]] = alloca i8*,
74 // Retaining parameters
75 // CHECK: call i8* @llvm.objc.retain(i8*
76 // CHECK: call i8* @llvm.objc.retain(i8*
77 // CHECK: call i8* @llvm.objc.retain(i8*
78 // CHECK: call i8* @llvm.objc.retain(i8*
80 // Constructing the arrays
81 // CHECK: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[KEYS:%[A-Za-z0-9]+]], i64 0, i64 0
82 // CHECK-NEXT: [[V0:%.*]] = load i8*, i8** [[K1]],
83 // CHECK-NEXT: store i8* [[V0]], i8** [[T0]]
84 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i64 0, i64 0
85 // CHECK-NEXT: [[V1:%.*]] = load i8*, i8** [[O1]],
86 // CHECK-NEXT: store i8* [[V1]], i8** [[T0]]
87 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[KEYS]], i64 0, i64 1
88 // CHECK-NEXT: [[V2:%.*]] = load i8*, i8** [[K2]],
89 // CHECK-NEXT: store i8* [[V2]], i8** [[T0]]
90 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 1
91 // CHECK-NEXT: [[V3:%.*]] = load i8*, i8** [[O2]],
92 // CHECK-NEXT: store i8* [[V3]], i8** [[T0]]
94 // Constructing the dictionary
95 // CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T:%.*]]*, [[CLASS_T:%.*]]** @"OBJC_CLASSLIST
96 // CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8*
97 // CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
98 // CHECK-NEXT: [[T2:%.*]] = bitcast [2 x i8*]* [[OBJECTS]] to i8**
99 // CHECK-NEXT: [[T3:%.*]] = bitcast [2 x i8*]* [[KEYS]] to i8**
100 // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast ({{.*@objc_msgSend.*}})(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i8** [[T3]], i64 2) [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]
101 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use(i8* [[T4]])
102 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use(i8* [[V0]], i8* [[V1]], i8* [[V2]], i8* [[V3]])
104 id dict = @{ k1 : o1, k2 : o2 };
106 // CHECK: call void @llvm.objc.release
107 // CHECK: call void @llvm.objc.release
108 // CHECK: call void @llvm.objc.release
109 // CHECK: call void @llvm.objc.release
110 // CHECK: call void @llvm.objc.release
111 // CHECK-NEXT: ret void
118 @property (retain) A* prop;
121 // CHECK-LABEL: define{{.*}} void @test_property
122 void test_property(B *b) {
124 // CHECK: call i8* @llvm.objc.retain
126 // CHECK: [[T0:%.*]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[OBJECTS:%.*]], i64 0, i64 0
129 // CHECK: [[T1:%.*]] = bitcast
130 // CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
131 // CHECK-NEXT: [[V0:%.*]] = call [[B:%.*]]* bitcast ({{.*}} @objc_msgSend to {{.*}})(i8* [[T1]], i8* [[SEL]]) [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]
132 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use([[B]]* [[V0]])
133 // CHECK-NEXT: [[V1:%.*]] = bitcast [[B]]* [[V0]] to i8*
136 // CHECK-NEXT: store i8* [[V1]], i8** [[T0]]
138 // Invoke arrayWithObjects:count:
139 // CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T]]*, [[CLASS_T]]** @"OBJC_CLASSLIST
140 // CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8*
141 // CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
142 // CHECK-NEXT: [[T2:%.*]] = bitcast [1 x i8*]* [[OBJECTS]] to i8**
143 // CHECK-NEXT: [[T3:%.*]] = call i8* bitcast ({{.*}} @objc_msgSend to {{.*}}(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i64 1) [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]
144 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use(i8* [[T3]])
145 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use(i8* [[V1]])
146 // CHECK-NEXT: bitcast
147 // CHECK-NEXT: bitcast
149 id arr = @[ b.prop ];
152 // CHECK-NEXT: [[T0:%.*]] = bitcast [[B]]* [[V0]] to i8*
153 // CHECK-NEXT: call void @llvm.objc.release(i8* [[T0]])
156 // CHECK: call void @llvm.objc.release
159 // CHECK: call void @llvm.objc.release
160 // CHECK-NEXT: ret void