diff options
author | Dan Gohman <gohman@apple.com> | 2011-08-12 00:36:31 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2011-08-12 00:36:31 +0000 |
commit | 126a54f1fa233d9da377a3e9f2ae85ff5fe34d9f (patch) | |
tree | c53a92fc030e5ee51daaa12a9c354dad0e5f0b5a | |
parent | 2fc75d5d602dd9e992661cfda7bae5877817fe5b (diff) | |
download | external_llvm-126a54f1fa233d9da377a3e9f2ae85ff5fe34d9f.zip external_llvm-126a54f1fa233d9da377a3e9f2ae85ff5fe34d9f.tar.gz external_llvm-126a54f1fa233d9da377a3e9f2ae85ff5fe34d9f.tar.bz2 |
Don't convert objc_autoreleaseReturnValue to objc_autorelease if the result
is returned through a bitcast.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137402 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/ObjCARC.cpp | 19 | ||||
-rw-r--r-- | test/Transforms/ObjCARC/rv.ll | 11 |
2 files changed, 24 insertions, 6 deletions
diff --git a/lib/Transforms/Scalar/ObjCARC.cpp b/lib/Transforms/Scalar/ObjCARC.cpp index f2cda41..c74c353 100644 --- a/lib/Transforms/Scalar/ObjCARC.cpp +++ b/lib/Transforms/Scalar/ObjCARC.cpp @@ -1925,12 +1925,19 @@ void ObjCARCOpt::OptimizeAutoreleaseRVCall(Function &F, Instruction *AutoreleaseRV) { // Check for a return of the pointer value. const Value *Ptr = GetObjCArg(AutoreleaseRV); - for (Value::const_use_iterator UI = Ptr->use_begin(), UE = Ptr->use_end(); - UI != UE; ++UI) { - const User *I = *UI; - if (isa<ReturnInst>(I) || GetBasicInstructionClass(I) == IC_RetainRV) - return; - } + SmallVector<const Value *, 2> Users; + Users.push_back(Ptr); + do { + Ptr = Users.pop_back_val(); + for (Value::const_use_iterator UI = Ptr->use_begin(), UE = Ptr->use_end(); + UI != UE; ++UI) { + const User *I = *UI; + if (isa<ReturnInst>(I) || GetBasicInstructionClass(I) == IC_RetainRV) + return; + if (isa<BitCastInst>(I)) + Users.push_back(I); + } + } while (!Users.empty()); Changed = true; ++NumPeeps; diff --git a/test/Transforms/ObjCARC/rv.ll b/test/Transforms/ObjCARC/rv.ll index da53a86..9353a19 100644 --- a/test/Transforms/ObjCARC/rv.ll +++ b/test/Transforms/ObjCARC/rv.ll @@ -329,3 +329,14 @@ define void @test23(i8* %p) { call i8* @objc_autoreleaseReturnValue(i8* %p) ret void } + +; Don't convert autoreleaseRV to autorelease if the result is returned, +; even through a bitcast. + +; CHECK: define {}* @test24( +; CHECK: tail call i8* @objc_autoreleaseReturnValue(i8* %p) +define {}* @test24(i8* %p) { + %t = call i8* @objc_autoreleaseReturnValue(i8* %p) + %s = bitcast i8* %p to {}* + ret {}* %s +} |