arc-bridged-cast.m
3.17 KB
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
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -O2 -disable-llvm-passes -o - %s | FileCheck %s
typedef const void *CFTypeRef;
typedef const struct __CFString *CFStringRef;
@interface NSString
@end
CFTypeRef CFCreateSomething(void);
CFStringRef CFCreateString(void);
CFTypeRef CFGetSomething(void);
CFStringRef CFGetString(void);
id CreateSomething(void);
NSString *CreateNSString(void);
// CHECK-LABEL: define void @bridge_transfer_from_cf
void bridge_transfer_from_cf(int *i) {
// CHECK: store i32 7
*i = 7;
// CHECK: call i8* @CFCreateSomething()
id obj1 = (__bridge_transfer id)CFCreateSomething();
// CHECK-NOT: retain
// CHECK: store i32 11
*i = 11;
// CHECK: call i8* @CFCreateSomething()
// CHECK-NOT: retain
// CHECK: store i32 13
(void)(__bridge_transfer id)CFCreateSomething(), *i = 13;
// CHECK: call void @llvm.objc.release
// CHECK: store i32 17
*i = 17;
// CHECK: call void @llvm.objc.release
// CHECK-NEXT: bitcast
// CHECK-NEXT: call void @llvm.lifetime.end
// CHECK-NEXT: ret void
}
// CHECK-LABEL: define void @bridge_from_cf
void bridge_from_cf(int *i) {
// CHECK: store i32 7
*i = 7;
// CHECK: call i8* @CFCreateSomething()
id obj1 = (__bridge id)CFCreateSomething();
// CHECK: llvm.objc.retainAutoreleasedReturnValue
// CHECK: store i32 11
*i = 11;
// CHECK: call i8* @CFCreateSomething()
// CHECK-NOT: release
// CHECK: store i32 13
(void)(__bridge id)CFCreateSomething(), *i = 13;
// CHECK: store i32 17
*i = 17;
// CHECK: call void @llvm.objc.release
// CHECK-NEXT: bitcast
// CHECK-NEXT: call void @llvm.lifetime.end
// CHECK-NEXT: ret void
}
// CHECK-LABEL: define void @bridge_retained_of_cf
void bridge_retained_of_cf(int *i) {
*i = 7;
// CHECK: call i8* @CreateSomething()
CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething();
// CHECK-NEXT: call i8* @llvm.objc.retainAutoreleasedReturnValue
// CHECK: store i32 11
*i = 11;
// CHECK: call i8* @CreateSomething()
(__bridge_retained CFTypeRef)CreateSomething(), *i = 13;
// CHECK-NEXT: call i8* @llvm.objc.retainAutoreleasedReturnValue
// CHECK: store i32 13
// CHECK: store i32 17
*i = 17;
// CHECK-NEXT: bitcast
// CHECK-NEXT: call void @llvm.lifetime.end
// CHECK-NEXT: ret void
}
// CHECK-LABEL: define void @bridge_of_cf
void bridge_of_cf(int *i) {
// CHECK: store i32 7
*i = 7;
// CHECK: call void @llvm.lifetime.start
// CHECK-NEXT: call i8* @CreateSomething()
CFTypeRef cf1 = (__bridge CFTypeRef)CreateSomething();
// CHECK-NOT: retain
// CHECK: store i32 11
*i = 11;
// CHECK: call i8* @CreateSomething
(__bridge CFTypeRef)CreateSomething(), *i = 13;
// CHECK: store i32 13
// CHECK-NOT: release
// CHECK: store i32 17
*i = 17;
// CHECK-NEXT: bitcast
// CHECK-NEXT: call void @llvm.lifetime.end
// CHECK-NEXT: ret void
}
// CHECK-LABEL: define %struct.__CFString* @bridge_of_paren_expr()
CFStringRef bridge_of_paren_expr() {
// CHECK-NOT: call i8* @llvm.objc.retainAutoreleasedReturnValue(
// CHECK-NOT: call void @llvm.objc.release(
CFStringRef r = (__bridge CFStringRef)(CreateNSString());
r = (__bridge CFStringRef)((NSString *)(CreateNSString()));
return r;
}