mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-06 20:10:26 +00:00
e8c161a924
The reason that this occurs is that tail calling objc_autorelease eventually tail calls -[NSObject autorelease] which supports fast autorelease. This can cause us to violate the semantic gaurantees of __autoreleasing variables that assignment to an __autoreleasing variables always yields an object that is placed into the innermost autorelease pool. The fix included in this patch works by: 1. In the peephole optimization function OptimizeIndividualFunctions, always remove tail call from objc_autorelease. 2. Whenever we convert to/from an objc_autorelease, set/unset the tail call keyword as appropriate. *NOTE* I also handled the case where objc_autorelease is converted in OptimizeReturns to an autoreleaseRV which still violates the ARC semantics. I will be removing that in a later patch and I wanted to make sure that the tree is in a consistent state vis-a-vis ARC always. Additionally some test cases are provided and all tests that have tail call marked objc_autorelease keywords have been modified so that tail call has been removed. *NOTE* One test fails due to a separate bug that I am going to commit soon. Thus I marked the check line TMP: instead of CHECK: so make check does not fail. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172287 91177308-0d34-0410-b5e6-96231b3b80d8
85 lines
2.6 KiB
LLVM
85 lines
2.6 KiB
LLVM
; RUN: opt -objc-arc -S < %s | FileCheck %s
|
|
|
|
declare i8* @objc_release(i8* %x)
|
|
declare i8* @objc_retain(i8* %x)
|
|
declare i8* @objc_autorelease(i8* %x)
|
|
declare i8* @objc_autoreleaseReturnValue(i8* %x)
|
|
declare i8* @objc_retainAutoreleasedReturnValue(i8* %x)
|
|
|
|
; Never tail call objc_autorelease.
|
|
define i8* @test0(i8* %x) {
|
|
entry:
|
|
; CHECK: %tmp0 = call i8* @objc_autorelease(i8* %x)
|
|
%tmp0 = call i8* @objc_autorelease(i8* %x)
|
|
; CHECK: %tmp1 = call i8* @objc_autorelease(i8* %x)
|
|
%tmp1 = tail call i8* @objc_autorelease(i8* %x)
|
|
|
|
ret i8* %x
|
|
}
|
|
|
|
; Always tail call autoreleaseReturnValue.
|
|
define i8* @test1(i8* %x) {
|
|
entry:
|
|
; CHECK: %tmp0 = tail call i8* @objc_autoreleaseReturnValue(i8* %x)
|
|
%tmp0 = call i8* @objc_autoreleaseReturnValue(i8* %x)
|
|
; CHECK: %tmp1 = tail call i8* @objc_autoreleaseReturnValue(i8* %x)
|
|
%tmp1 = tail call i8* @objc_autoreleaseReturnValue(i8* %x)
|
|
ret i8* %x
|
|
}
|
|
|
|
; Always tail call objc_retain.
|
|
define i8* @test2(i8* %x) {
|
|
entry:
|
|
; CHECK: %tmp0 = tail call i8* @objc_retain(i8* %x)
|
|
%tmp0 = call i8* @objc_retain(i8* %x)
|
|
; CHECK: %tmp1 = tail call i8* @objc_retain(i8* %x)
|
|
%tmp1 = tail call i8* @objc_retain(i8* %x)
|
|
ret i8* %x
|
|
}
|
|
|
|
define i8* @tmp(i8* %x) {
|
|
ret i8* %x
|
|
}
|
|
|
|
; Always tail call objc_retainAutoreleasedReturnValue.
|
|
define i8* @test3(i8* %x) {
|
|
entry:
|
|
%y = call i8* @tmp(i8* %x)
|
|
; CHECK: %tmp0 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %y)
|
|
%tmp0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %y)
|
|
%z = call i8* @tmp(i8* %x)
|
|
; CHECK: %tmp1 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %z)
|
|
%tmp1 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %z)
|
|
ret i8* %x
|
|
}
|
|
|
|
; By itself, we should never change whether or not objc_release is tail called.
|
|
define i8* @test4(i8* %x) {
|
|
entry:
|
|
; CHECK: %tmp0 = call i8* @objc_release(i8* %x)
|
|
%tmp0 = call i8* @objc_release(i8* %x)
|
|
; CHECK: %tmp1 = tail call i8* @objc_release(i8* %x)
|
|
%tmp1 = tail call i8* @objc_release(i8* %x)
|
|
ret i8* %x
|
|
}
|
|
|
|
; If we convert a tail called @objc_autoreleaseReturnValue to an
|
|
; @objc_autorelease, ensure that the tail call is removed.
|
|
define i8* @test5(i8* %x) {
|
|
entry:
|
|
; TMP: %tmp0 = call i8* @objc_autorelease(i8* %x)
|
|
%tmp0 = tail call i8* @objc_autoreleaseReturnValue(i8* %x)
|
|
ret i8* %tmp0
|
|
}
|
|
|
|
; If we convert a called @objc_autorelease to an @objc_autoreleaseReturnValue,
|
|
; ensure that the tail call is added.
|
|
define i8* @test6(i8* %x) {
|
|
entry:
|
|
; CHECK: %tmp0 = tail call i8* @objc_retain(i8* %x)
|
|
%tmp0 = tail call i8* @objc_retain(i8* %x)
|
|
; CHECK: %tmp1 = tail call i8* @objc_autoreleaseReturnValue(i8* %x)
|
|
%tmp1 = call i8* @objc_autorelease(i8* %x)
|
|
ret i8* %x
|
|
}
|