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 ptr,
39 // CHECK: [[B:%.*]] = alloca ptr,
41 // Retaining parameters
42 // CHECK: call ptr @llvm.objc.retain(ptr
43 // CHECK: call ptr @llvm.objc.retain(ptr
45 // Constructing the array
46 // CHECK: [[T0:%.*]] = getelementptr inbounds [2 x ptr], ptr [[OBJECTS:%[A-Za-z0-9]+]], i64 0, i64 0
47 // CHECK-NEXT: [[V0:%.*]] = load ptr, ptr [[A]],
48 // CHECK-NEXT: store ptr [[V0]], ptr [[T0]]
49 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x ptr], ptr [[OBJECTS]], i64 0, i64 1
50 // CHECK-NEXT: [[V1:%.*]] = load ptr, ptr [[B]],
51 // CHECK-NEXT: store ptr [[V1]], ptr [[T0]]
53 // CHECK-NEXT: [[T0:%.*]] = load ptr, ptr @"OBJC_CLASSLIST
54 // CHECK-NEXT: [[SEL:%.*]] = load ptr, ptr @OBJC_SELECTOR_REFERENCES
55 // CHECK-NEXT: [[T3:%.*]] = call ptr @objc_msgSend(ptr [[T0]], ptr [[SEL]], ptr [[OBJECTS]], i64 2) [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
56 // CHECK: call void (...) @llvm.objc.clang.arc.use(ptr [[V0]], ptr [[V1]])
59 // CHECK: call void @llvm.objc.release
60 // CHECK: call void @llvm.objc.release
61 // CHECK: call void @llvm.objc.release
62 // CHECK-NEXT: ret void
65 // CHECK-LABEL: define{{.*}} void @test_dictionary
66 void test_dictionary(id k1, id o1, id k2, id o2) {
67 // CHECK: [[K1:%.*]] = alloca ptr,
68 // CHECK: [[O1:%.*]] = alloca ptr,
69 // CHECK: [[K2:%.*]] = alloca ptr,
70 // CHECK: [[O2:%.*]] = alloca ptr,
72 // Retaining parameters
73 // CHECK: call ptr @llvm.objc.retain(ptr
74 // CHECK: call ptr @llvm.objc.retain(ptr
75 // CHECK: call ptr @llvm.objc.retain(ptr
76 // CHECK: call ptr @llvm.objc.retain(ptr
78 // Constructing the arrays
79 // CHECK: [[T0:%.*]] = getelementptr inbounds [2 x ptr], ptr [[KEYS:%[A-Za-z0-9]+]], i64 0, i64 0
80 // CHECK-NEXT: [[V0:%.*]] = load ptr, ptr [[K1]],
81 // CHECK-NEXT: store ptr [[V0]], ptr [[T0]]
82 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x ptr], ptr [[OBJECTS:%[A-Za-z0-9]+]], i64 0, i64 0
83 // CHECK-NEXT: [[V1:%.*]] = load ptr, ptr [[O1]],
84 // CHECK-NEXT: store ptr [[V1]], ptr [[T0]]
85 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x ptr], ptr [[KEYS]], i64 0, i64 1
86 // CHECK-NEXT: [[V2:%.*]] = load ptr, ptr [[K2]],
87 // CHECK-NEXT: store ptr [[V2]], ptr [[T0]]
88 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x ptr], ptr [[OBJECTS]], i64 0, i64 1
89 // CHECK-NEXT: [[V3:%.*]] = load ptr, ptr [[O2]],
90 // CHECK-NEXT: store ptr [[V3]], ptr [[T0]]
92 // Constructing the dictionary
93 // CHECK-NEXT: [[T0:%.*]] = load ptr, ptr @"OBJC_CLASSLIST
94 // CHECK-NEXT: [[SEL:%.*]] = load ptr, ptr @OBJC_SELECTOR_REFERENCES
95 // CHECK-NEXT: [[T4:%.*]] = call ptr @objc_msgSend(ptr [[T0]], ptr [[SEL]], ptr [[OBJECTS]], ptr [[KEYS]], i64 2) [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
96 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use(ptr [[T4]])
97 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use(ptr [[V0]], ptr [[V1]], ptr [[V2]], ptr [[V3]])
99 id dict = @{ k1 : o1, k2 : o2 };
101 // CHECK: call void @llvm.objc.release
102 // CHECK: call void @llvm.objc.release
103 // CHECK: call void @llvm.objc.release
104 // CHECK: call void @llvm.objc.release
105 // CHECK: call void @llvm.objc.release
106 // CHECK-NEXT: ret void
113 @property (retain) A* prop;
116 // CHECK-LABEL: define{{.*}} void @test_property
117 void test_property(B *b) {
119 // CHECK: call ptr @llvm.objc.retain
121 // CHECK: [[T0:%.*]] = getelementptr inbounds [1 x ptr], ptr [[OBJECTS:%.*]], i64 0, i64 0
124 // CHECK: [[SEL:%.*]] = load ptr, ptr @OBJC_SELECTOR_REFERENCES
125 // CHECK-NEXT: [[V0:%.*]] = call ptr @objc_msgSend(ptr {{.*}}, ptr [[SEL]]) [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
126 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use(ptr [[V0]])
129 // CHECK-NEXT: store ptr [[V0]], ptr [[T0]]
131 // Invoke arrayWithObjects:count:
132 // CHECK-NEXT: [[T0:%.*]] = load ptr, ptr @"OBJC_CLASSLIST
133 // CHECK-NEXT: [[SEL:%.*]] = load ptr, ptr @OBJC_SELECTOR_REFERENCES
134 // CHECK-NEXT: [[T3:%.*]] = call ptr @objc_msgSend(ptr [[T0]], ptr [[SEL]], ptr [[OBJECTS]], i64 1) [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
135 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use(ptr [[T3]])
136 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use(ptr [[V0]])
138 id arr = @[ b.prop ];
141 // CHECK-NEXT: call void @llvm.objc.release(ptr [[V0]])
144 // CHECK: call void @llvm.objc.release
147 // CHECK: call void @llvm.objc.release
148 // CHECK-NEXT: ret void