summaryrefslogtreecommitdiff
path: root/clang/test/CodeGenObjC/arc-literals.m
blob: 203c2ad1eea17baa504f573746fb506dcd22685f (about) (plain)
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
// 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

#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: define void @test_numeric()
void test_numeric() {
  // CHECK: {{call.*objc_msgSend.*i32 17}}
  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
  id ilit = @17;
  // CHECK: {{call.*objc_msgSend.*i32 25}}
  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
  id ulit = @25u;
  // CHECK: {{call.*objc_msgSend.*i64 42}}
  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
  id ulllit = @42ull;
  // CHECK: {{call.*objc_msgSend.*i8 signext 97}}
  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
  id charlit = @'a';
  // CHECK: call void @objc_release
  // CHECK: call void @objc_release
  // CHECK: call void @objc_release
  // CHECK: call void @objc_release
  // CHECK-NEXT: ret void
}

// CHECK: define void @test_array
void test_array(id a, id b) {
  // Retaining parameters
  // CHECK: call i8* @objc_retain(i8*
  // CHECK: call i8* @objc_retain(i8*

  // Constructing the array
  // CHECK: getelementptr inbounds [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i32 0, i32 0
  // CHECK: store i8*
  // CHECK: getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 1
  // CHECK: store i8*

  // CHECK: {{call i8*.*objc_msgSend.*i64 2}}
  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
  id arr = @[a, b];

  // CHECK: call void @objc_release
  // CHECK: call void @objc_release
  // CHECK: call void @objc_release
  // CHECK-NEXT: ret void
}

// CHECK: define void @test_dictionary
void test_dictionary(id k1, id o1, id k2, id o2) {
  // Retaining parameters
  // CHECK: call i8* @objc_retain(i8*
  // CHECK: call i8* @objc_retain(i8*
  // CHECK: call i8* @objc_retain(i8*
  // CHECK: call i8* @objc_retain(i8*

  // Constructing the arrays
  // CHECK: getelementptr inbounds [2 x i8*]* [[KEYS:%[A-Za-z0-9]+]], i32 0, i32 0
  // CHECK: store i8*
  // CHECK: getelementptr inbounds [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i32 0, i32 0
  // CHECK: store i8*
  // CHECK: getelementptr inbounds [2 x i8*]* [[KEYS]], i32 0, i32 1
  // CHECK: store i8*
  // CHECK: getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 1
  // CHECK: store i8*

  // Constructing the dictionary
  // CHECK: {{call i8.*@objc_msgSend}}
  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
  id dict = @{ k1 : o1, k2 : o2 };

  // CHECK: call void @objc_release
  // CHECK: call void @objc_release
  // CHECK: call void @objc_release
  // CHECK: call void @objc_release
  // CHECK: call void @objc_release
  // CHECK-NEXT: ret void
}

@interface A
@end

@interface B
@property (retain) A* prop;
@end

// CHECK: define void @test_property
void test_property(B *b) {
  // Retain parameter
  // CHECK: call i8* @objc_retain

  // Invoke 'prop'
  // CHECK: load i8** @"\01L_OBJC_SELECTOR_REFERENCES
  // CHECK: {{call.*@objc_msgSend}}
  // CHECK: call i8* @objc_retainAutoreleasedReturnValue

  // Invoke arrayWithObjects:count:
  // CHECK: load i8** @"\01L_OBJC_SELECTOR_REFERENCES
  // CHECK: {{call.*objc_msgSend}}
  // CHECK: call i8* @objc_retainAutoreleasedReturnValue
  id arr = @[ b.prop ];

  // Release b.prop
  // CHECK: call void @objc_release

  // Destroy arr
  // CHECK: call void @objc_release

  // Destroy b
  // CHECK: call void @objc_release
  // CHECK-NEXT: ret void
}