• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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
2
3#include "literal-support.h"
4
5// Check the various selector names we'll be using, in order.
6
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"
13// CHECK: c"prop\00"
14
15// CHECK: define void @test_numeric()
16void test_numeric() {
17  // CHECK: {{call.*objc_msgSend.*i32 17}}
18  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
19  id ilit = @17;
20  // CHECK: {{call.*objc_msgSend.*i32 25}}
21  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
22  id ulit = @25u;
23  // CHECK: {{call.*objc_msgSend.*i64 42}}
24  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
25  id ulllit = @42ull;
26  // CHECK: {{call.*objc_msgSend.*i8 signext 97}}
27  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
28  id charlit = @'a';
29  // CHECK: call void @objc_release
30  // CHECK: call void @objc_release
31  // CHECK: call void @objc_release
32  // CHECK: call void @objc_release
33  // CHECK-NEXT: ret void
34}
35
36// CHECK: define void @test_array
37void test_array(id a, id b) {
38  // Retaining parameters
39  // CHECK: call i8* @objc_retain(i8*
40  // CHECK: call i8* @objc_retain(i8*
41
42  // Constructing the array
43  // CHECK: getelementptr inbounds [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i32 0, i32 0
44  // CHECK: store i8*
45  // CHECK: getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 1
46  // CHECK: store i8*
47
48  // CHECK: {{call i8*.*objc_msgSend.*i64 2}}
49  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
50  id arr = @[a, b];
51
52  // CHECK: call void @objc_release
53  // CHECK: call void @objc_release
54  // CHECK: call void @objc_release
55  // CHECK-NEXT: ret void
56}
57
58// CHECK: define void @test_dictionary
59void test_dictionary(id k1, id o1, id k2, id o2) {
60  // Retaining parameters
61  // CHECK: call i8* @objc_retain(i8*
62  // CHECK: call i8* @objc_retain(i8*
63  // CHECK: call i8* @objc_retain(i8*
64  // CHECK: call i8* @objc_retain(i8*
65
66  // Constructing the arrays
67  // CHECK: getelementptr inbounds [2 x i8*]* [[KEYS:%[A-Za-z0-9]+]], i32 0, i32 0
68  // CHECK: store i8*
69  // CHECK: getelementptr inbounds [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i32 0, i32 0
70  // CHECK: store i8*
71  // CHECK: getelementptr inbounds [2 x i8*]* [[KEYS]], i32 0, i32 1
72  // CHECK: store i8*
73  // CHECK: getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 1
74  // CHECK: store i8*
75
76  // Constructing the dictionary
77  // CHECK: {{call i8.*@objc_msgSend}}
78  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
79  id dict = @{ k1 : o1, k2 : o2 };
80
81  // CHECK: call void @objc_release
82  // CHECK: call void @objc_release
83  // CHECK: call void @objc_release
84  // CHECK: call void @objc_release
85  // CHECK: call void @objc_release
86  // CHECK-NEXT: ret void
87}
88
89@interface A
90@end
91
92@interface B
93@property (retain) A* prop;
94@end
95
96// CHECK: define void @test_property
97void test_property(B *b) {
98  // Retain parameter
99  // CHECK: call i8* @objc_retain
100
101  // Invoke 'prop'
102  // CHECK: load i8** @"\01L_OBJC_SELECTOR_REFERENCES
103  // CHECK: {{call.*@objc_msgSend}}
104  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
105
106  // Invoke arrayWithObjects:count:
107  // CHECK: load i8** @"\01L_OBJC_SELECTOR_REFERENCES
108  // CHECK: {{call.*objc_msgSend}}
109  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
110  id arr = @[ b.prop ];
111
112  // Release b.prop
113  // CHECK: call void @objc_release
114
115  // Destroy arr
116  // CHECK: call void @objc_release
117
118  // Destroy b
119  // CHECK: call void @objc_release
120  // CHECK-NEXT: ret void
121}
122