1 ; RUN: opt -objc-arc -S < %s | FileCheck %s
3 declare void @llvm.objc.release(i8* %x)
4 declare i8* @llvm.objc.retain(i8* %x)
5 declare i8* @llvm.objc.autorelease(i8* %x)
6 declare i8* @llvm.objc.autoreleaseReturnValue(i8* %x)
7 declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %x)
8 declare i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %x)
11 ; Never tail call objc_autorelease.
13 ; CHECK: define i8* @test0(i8* %x) [[NUW:#[0-9]+]] {
14 ; CHECK: %tmp0 = call i8* @llvm.objc.autorelease(i8* %x) [[NUW]]
15 ; CHECK: %tmp1 = call i8* @llvm.objc.autorelease(i8* %x) [[NUW]]
17 define i8* @test0(i8* %x) nounwind {
19 %tmp0 = call i8* @llvm.objc.autorelease(i8* %x)
20 %tmp1 = tail call i8* @llvm.objc.autorelease(i8* %x)
25 ; Always tail call autoreleaseReturnValue.
27 ; CHECK: define i8* @test1(i8* %x) [[NUW]] {
28 ; CHECK: %tmp0 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %x) [[NUW]]
29 ; CHECK: %tmp1 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %x) [[NUW]]
31 define i8* @test1(i8* %x) nounwind {
33 %tmp0 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %x)
34 %tmp1 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %x)
38 ; Always tail call objc_retain.
40 ; CHECK: define i8* @test2(i8* %x) [[NUW]] {
41 ; CHECK: %tmp0 = tail call i8* @llvm.objc.retain(i8* %x) [[NUW]]
42 ; CHECK: %tmp1 = tail call i8* @llvm.objc.retain(i8* %x) [[NUW]]
44 define i8* @test2(i8* %x) nounwind {
46 %tmp0 = call i8* @llvm.objc.retain(i8* %x)
47 %tmp1 = tail call i8* @llvm.objc.retain(i8* %x)
51 ; Always tail call objc_retainAutoreleasedReturnValue unless it's annotated with
53 ; CHECK: define i8* @test3(i8* %x) [[NUW]] {
54 ; CHECK: %tmp0 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %y) [[NUW]]
55 ; CHECK: %tmp1 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %z) [[NUW]]
56 ; CHECK: %tmp2 = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %z2) [[NUW]]
58 define i8* @test3(i8* %x) nounwind {
60 %y = call i8* @tmp(i8* %x)
61 %tmp0 = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %y)
62 %z = call i8* @tmp(i8* %x)
63 %tmp1 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %z)
64 %z2 = call i8* @tmp(i8* %x)
65 %tmp2 = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %z2)
69 ; By itself, we should never change whether or not objc_release is tail called.
71 ; CHECK: define void @test4(i8* %x) [[NUW]] {
72 ; CHECK: call void @llvm.objc.release(i8* %x) [[NUW]]
73 ; CHECK: tail call void @llvm.objc.release(i8* %x) [[NUW]]
75 define void @test4(i8* %x) nounwind {
77 call void @llvm.objc.release(i8* %x)
78 tail call void @llvm.objc.release(i8* %x)
82 ; If we convert a tail called @llvm.objc.autoreleaseReturnValue to an
83 ; @llvm.objc.autorelease, ensure that the tail call is removed.
84 ; CHECK: define i8* @test5(i8* %x) [[NUW]] {
85 ; CHECK: %tmp0 = call i8* @llvm.objc.autorelease(i8* %x) [[NUW]]
87 define i8* @test5(i8* %x) nounwind {
89 %tmp0 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %x)
93 ; Always tail call llvm.objc.unsafeClaimAutoreleasedReturnValue.
94 ; CHECK: define i8* @test6(i8* %x) [[NUW]] {
95 ; CHECK: %tmp0 = tail call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %y) [[NUW]]
96 ; CHECK: %tmp1 = tail call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %z) [[NUW]]
98 define i8* @test6(i8* %x) nounwind {
100 %y = call i8* @tmp(i8* %x)
101 %tmp0 = call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %y)
102 %z = call i8* @tmp(i8* %x)
103 %tmp1 = tail call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %z)
107 ; CHECK: attributes [[NUW]] = { nounwind }