1 ; RUN: opt -basic-aa -objc-arc -S < %s | FileCheck %s
3 target datalayout = "e-p:64:64:64"
5 declare i8* @llvm.objc.retain(i8*)
6 declare i8* @llvm.objc.retainAutorelease(i8*)
7 declare void @llvm.objc.release(i8*)
8 declare i8* @llvm.objc.autorelease(i8*)
10 declare void @llvm.objc.clang.arc.use(...)
11 declare void @llvm.objc.clang.arc.noop.use(...)
13 declare void @test0_helper(i8*, i8**)
14 declare void @can_release(i8*)
16 ; Ensure that we honor clang.arc.use as a use and don't miscompile
17 ; the reduced test case from <rdar://13195034>.
19 ; CHECK-LABEL: define void @test0(
20 ; CHECK: @llvm.objc.retain(i8* %x)
21 ; CHECK-NEXT: store i8* %y, i8** %temp0
22 ; CHECK-NEXT: @llvm.objc.retain(i8* %y)
23 ; CHECK-NEXT: call void @test0_helper
24 ; CHECK-NEXT: [[VAL1:%.*]] = load i8*, i8** %temp0
25 ; CHECK-NEXT: @llvm.objc.retain(i8* [[VAL1]])
26 ; CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use(i8* %y)
27 ; CHECK-NEXT: @llvm.objc.release(i8* %y)
28 ; CHECK-NEXT: store i8* [[VAL1]], i8** %temp1
29 ; CHECK-NEXT: call void @test0_helper
30 ; CHECK-NEXT: [[VAL2:%.*]] = load i8*, i8** %temp1
31 ; CHECK-NEXT: @llvm.objc.retain(i8* [[VAL2]])
32 ; CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use(i8* [[VAL1]])
33 ; CHECK-NEXT: @llvm.objc.release(i8* [[VAL1]])
34 ; CHECK-NEXT: @llvm.objc.autorelease(i8* %x)
35 ; CHECK-NEXT: store i8* %x, i8** %out
36 ; CHECK-NEXT: @llvm.objc.retain(i8* %x)
37 ; CHECK-NEXT: @llvm.objc.release(i8* [[VAL2]])
38 ; CHECK-NEXT: @llvm.objc.release(i8* %x)
39 ; CHECK-NEXT: ret void
41 define void @test0(i8** %out, i8* %x, i8* %y) {
43 %temp0 = alloca i8*, align 8
44 %temp1 = alloca i8*, align 8
45 %0 = call i8* @llvm.objc.retain(i8* %x) nounwind
46 %1 = call i8* @llvm.objc.retain(i8* %y) nounwind
47 store i8* %y, i8** %temp0
48 call void @test0_helper(i8* %x, i8** %temp0)
49 %val1 = load i8*, i8** %temp0
50 %2 = call i8* @llvm.objc.retain(i8* %val1) nounwind
51 call void (...) @llvm.objc.clang.arc.use(i8* %y) nounwind
52 call void @llvm.objc.release(i8* %y) nounwind
53 store i8* %val1, i8** %temp1
54 call void @test0_helper(i8* %x, i8** %temp1)
55 %val2 = load i8*, i8** %temp1
56 %3 = call i8* @llvm.objc.retain(i8* %val2) nounwind
57 call void (...) @llvm.objc.clang.arc.use(i8* %val1) nounwind
58 call void @llvm.objc.release(i8* %val1) nounwind
59 %4 = call i8* @llvm.objc.retain(i8* %x) nounwind
60 %5 = call i8* @llvm.objc.autorelease(i8* %x) nounwind
61 store i8* %x, i8** %out
62 call void @llvm.objc.release(i8* %val2) nounwind
63 call void @llvm.objc.release(i8* %x) nounwind
67 ; CHECK-LABEL: define void @test0a(
68 ; CHECK: @llvm.objc.retain(i8* %x)
69 ; CHECK-NEXT: store i8* %y, i8** %temp0
70 ; CHECK-NEXT: @llvm.objc.retain(i8* %y)
71 ; CHECK-NEXT: call void @test0_helper
72 ; CHECK-NEXT: [[VAL1:%.*]] = load i8*, i8** %temp0
73 ; CHECK-NEXT: @llvm.objc.retain(i8* [[VAL1]])
74 ; CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use(i8* %y)
75 ; CHECK-NEXT: @llvm.objc.release(i8* %y)
76 ; CHECK-NEXT: store i8* [[VAL1]], i8** %temp1
77 ; CHECK-NEXT: call void @test0_helper
78 ; CHECK-NEXT: [[VAL2:%.*]] = load i8*, i8** %temp1
79 ; CHECK-NEXT: @llvm.objc.retain(i8* [[VAL2]])
80 ; CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use(i8* [[VAL1]])
81 ; CHECK-NEXT: @llvm.objc.release(i8* [[VAL1]])
82 ; CHECK-NEXT: @llvm.objc.autorelease(i8* %x)
83 ; CHECK-NEXT: @llvm.objc.release(i8* [[VAL2]])
84 ; CHECK-NEXT: store i8* %x, i8** %out
85 ; CHECK-NEXT: ret void
87 define void @test0a(i8** %out, i8* %x, i8* %y) {
89 %temp0 = alloca i8*, align 8
90 %temp1 = alloca i8*, align 8
91 %0 = call i8* @llvm.objc.retain(i8* %x) nounwind
92 %1 = call i8* @llvm.objc.retain(i8* %y) nounwind
93 store i8* %y, i8** %temp0
94 call void @test0_helper(i8* %x, i8** %temp0)
95 %val1 = load i8*, i8** %temp0
96 %2 = call i8* @llvm.objc.retain(i8* %val1) nounwind
97 call void (...) @llvm.objc.clang.arc.use(i8* %y) nounwind
98 call void @llvm.objc.release(i8* %y) nounwind, !clang.imprecise_release !0
99 store i8* %val1, i8** %temp1
100 call void @test0_helper(i8* %x, i8** %temp1)
101 %val2 = load i8*, i8** %temp1
102 %3 = call i8* @llvm.objc.retain(i8* %val2) nounwind
103 call void (...) @llvm.objc.clang.arc.use(i8* %val1) nounwind
104 call void @llvm.objc.release(i8* %val1) nounwind, !clang.imprecise_release !0
105 %4 = call i8* @llvm.objc.retain(i8* %x) nounwind
106 %5 = call i8* @llvm.objc.autorelease(i8* %x) nounwind
107 store i8* %x, i8** %out
108 call void @llvm.objc.release(i8* %val2) nounwind, !clang.imprecise_release !0
109 call void @llvm.objc.release(i8* %x) nounwind, !clang.imprecise_release !0
113 ; ARC optimizer should be able to safely remove the retain/release pair as the
114 ; call to @llvm.objc.clang.arc.noop.use is a no-op.
116 ; CHECK-LABEL: define void @test_arc_noop_use(
117 ; CHECK-NEXT: call void @can_release(i8* %x)
118 ; CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use(
119 ; CHECK-NEXT: ret void
121 define void @test_arc_noop_use(i8** %out, i8* %x) {
122 call i8* @llvm.objc.retain(i8* %x)
123 call void @can_release(i8* %x)
124 call void (...) @llvm.objc.clang.arc.noop.use(i8* %x)
125 call void @llvm.objc.release(i8* %x), !clang.imprecise_release !0