1 // RUN: %clang_cc1 -no-opaque-pointers -triple arm64-apple-ios9 -fobjc-runtime=ios-9.0 -fobjc-arc -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK
2 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-apple-macosx10 -fobjc-runtime=ios-9.0 -fobjc-arc -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK
8 void test_assign(void) {
9 __unsafe_unretained id x;
12 // CHECK-LABEL: define{{.*}} void @test_assign()
13 // CHECK: [[X:%.*]] = alloca i8*
14 // CHECK: [[T0:%.*]] = call [[A:.*]]* @makeA() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.unsafeClaimAutoreleasedReturnValue) ]
15 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use({{.*}} [[T0]])
16 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A]]* [[T0]] to i8*
17 // CHECK-NEXT: store i8* [[T1]], i8** [[X]]
18 // CHECK-NEXT: bitcast
19 // CHECK-NEXT: lifetime.end
20 // CHECK-NEXT: ret void
22 void test_assign_assign(void) {
23 __unsafe_unretained id x, y;
26 // CHECK-LABEL: define{{.*}} void @test_assign_assign()
27 // CHECK: [[X:%.*]] = alloca i8*
28 // CHECK: [[Y:%.*]] = alloca i8*
29 // CHECK: [[T0:%.*]] = call [[A]]* @makeA() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.unsafeClaimAutoreleasedReturnValue) ]
30 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use({{.*}} [[T0]])
31 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A]]* [[T0]] to i8*
32 // CHECK-NEXT: store i8* [[T1]], i8** [[Y]]
33 // CHECK-NEXT: store i8* [[T1]], i8** [[X]]
34 // CHECK-NEXT: bitcast
35 // CHECK-NEXT: lifetime.end
36 // CHECK-NEXT: bitcast
37 // CHECK-NEXT: lifetime.end
38 // CHECK-NEXT: ret void
40 void test_strong_assign_assign(void) {
42 __unsafe_unretained id y;
45 // CHECK-LABEL: define{{.*}} void @test_strong_assign_assign()
46 // CHECK: [[X:%.*]] = alloca i8*
47 // CHECK: [[Y:%.*]] = alloca i8*
48 // CHECK: [[T0:%.*]] = call [[A]]* @makeA() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]
49 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use({{.*}} [[T0]])
50 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A]]* [[T0]] to i8*
51 // CHECK-NEXT: store i8* [[T1]], i8** [[Y]]
52 // CHECK-NEXT: [[OLD:%.*]] = load i8*, i8** [[X]]
53 // CHECK-NEXT: store i8* [[T1]], i8** [[X]]
54 // CHECK-NEXT: call void @llvm.objc.release(i8* [[OLD]]
55 // CHECK-NEXT: bitcast
56 // CHECK-NEXT: lifetime.end
57 // CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[X]]
58 // CHECK-NEXT: call void @llvm.objc.release(i8* [[T0]])
59 // CHECK-NEXT: bitcast
60 // CHECK-NEXT: lifetime.end
61 // CHECK-NEXT: ret void
63 void test_assign_strong_assign(void) {
64 __unsafe_unretained id x;
68 // CHECK-LABEL: define{{.*}} void @test_assign_strong_assign()
69 // CHECK: [[X:%.*]] = alloca i8*
70 // CHECK: [[Y:%.*]] = alloca i8*
71 // CHECK: [[T0:%.*]] = call [[A]]* @makeA() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]
72 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use({{.*}} [[T0]])
73 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A]]* [[T0]] to i8*
74 // CHECK-NEXT: [[OLD:%.*]] = load i8*, i8** [[Y]]
75 // CHECK-NEXT: store i8* [[T1]], i8** [[Y]]
76 // CHECK-NEXT: call void @llvm.objc.release(i8* [[OLD]]
77 // CHECK-NEXT: store i8* [[T1]], i8** [[X]]
78 // CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[Y]]
79 // CHECK-NEXT: call void @llvm.objc.release(i8* [[T0]])
80 // CHECK-NEXT: bitcast
81 // CHECK-NEXT: lifetime.end
82 // CHECK-NEXT: bitcast
83 // CHECK-NEXT: lifetime.end
84 // CHECK-NEXT: ret void
86 void test_init(void) {
87 __unsafe_unretained id x = makeA();
89 // CHECK-LABEL: define{{.*}} void @test_init()
90 // CHECK: [[X:%.*]] = alloca i8*
91 // CHECK: [[T0:%.*]] = call [[A]]* @makeA() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.unsafeClaimAutoreleasedReturnValue) ]
92 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use({{.*}} [[T0]])
93 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A]]* [[T0]] to i8*
94 // CHECK-NEXT: store i8* [[T1]], i8** [[X]]
95 // CHECK-NEXT: bitcast
96 // CHECK-NEXT: lifetime.end
97 // CHECK-NEXT: ret void
99 void test_init_assignment(void) {
100 __unsafe_unretained id x;
101 __unsafe_unretained id y = x = makeA();
103 // CHECK-LABEL: define{{.*}} void @test_init_assignment()
104 // CHECK: [[X:%.*]] = alloca i8*
105 // CHECK: [[Y:%.*]] = alloca i8*
106 // CHECK: [[T0:%.*]] = call [[A]]* @makeA() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.unsafeClaimAutoreleasedReturnValue) ]
107 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use({{.*}} [[T0]])
108 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A]]* [[T0]] to i8*
109 // CHECK-NEXT: store i8* [[T1]], i8** [[X]]
110 // CHECK-NEXT: store i8* [[T1]], i8** [[Y]]
111 // CHECK-NEXT: bitcast
112 // CHECK-NEXT: lifetime.end
113 // CHECK-NEXT: bitcast
114 // CHECK-NEXT: lifetime.end
115 // CHECK-NEXT: ret void
117 void test_strong_init_assignment(void) {
118 __unsafe_unretained id x;
119 __strong id y = x = makeA();
121 // CHECK-LABEL: define{{.*}} void @test_strong_init_assignment()
122 // CHECK: [[X:%.*]] = alloca i8*
123 // CHECK: [[Y:%.*]] = alloca i8*
124 // CHECK: [[T0:%.*]] = call [[A]]* @makeA() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]
125 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use({{.*}} [[T0]])
126 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A]]* [[T0]] to i8*
127 // CHECK-NEXT: store i8* [[T1]], i8** [[X]]
128 // CHECK-NEXT: store i8* [[T1]], i8** [[Y]]
129 // CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[Y]]
130 // CHECK-NEXT: call void @llvm.objc.release(i8* [[T0]])
131 // CHECK-NEXT: bitcast
132 // CHECK-NEXT: lifetime.end
133 // CHECK-NEXT: bitcast
134 // CHECK-NEXT: lifetime.end
135 // CHECK-NEXT: ret void
137 void test_init_strong_assignment(void) {
139 __unsafe_unretained id y = x = makeA();
141 // CHECK-LABEL: define{{.*}} void @test_init_strong_assignment()
142 // CHECK: [[X:%.*]] = alloca i8*
143 // CHECK: [[Y:%.*]] = alloca i8*
144 // CHECK: [[T0:%.*]] = call [[A]]* @makeA() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.retainAutoreleasedReturnValue) ]
145 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use({{.*}} [[T0]])
146 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A]]* [[T0]] to i8*
147 // CHECK-NEXT: [[OLD:%.*]] = load i8*, i8** [[X]]
148 // CHECK-NEXT: store i8* [[T1]], i8** [[X]]
149 // CHECK-NEXT: call void @llvm.objc.release(i8* [[OLD]])
150 // CHECK-NEXT: store i8* [[T1]], i8** [[Y]]
151 // CHECK-NEXT: bitcast
152 // CHECK-NEXT: lifetime.end
153 // CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[X]]
154 // CHECK-NEXT: call void @llvm.objc.release(i8* [[T0]])
155 // CHECK-NEXT: bitcast
156 // CHECK-NEXT: lifetime.end
157 // CHECK-NEXT: ret void
159 void test_ignored(void) {
162 // CHECK-LABEL: define{{.*}} void @test_ignored()
163 // CHECK: [[T0:%.*]] = call [[A]]* @makeA() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.unsafeClaimAutoreleasedReturnValue) ]
164 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use({{.*}} [[T0]])
165 // CHECK-NEXT: ret void
167 void test_cast_to_void(void) {
170 // CHECK-LABEL: define{{.*}} void @test_cast_to_void()
171 // CHECK: [[T0:%.*]] = call [[A]]* @makeA() [ "clang.arc.attachedcall"(i8* (i8*)* @llvm.objc.unsafeClaimAutoreleasedReturnValue) ]
172 // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use({{.*}} [[T0]])
173 // CHECK-NEXT: ret void
175 // This is always at the end of the module.
177 // CHECK-OPTIMIZED: !llvm.module.flags = !{!0,
178 // CHECK-OPTIMIZED: !0 = !{i32 1, !"clang.arc.retainAutoreleasedReturnValueMarker", !"mov{{.*}}marker for objc_retainAutoreleaseReturnValue"}