From 10a18d55ce457b3fd1a045105f40a1dbb7f58054 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 12 Aug 2011 00:36:31 +0000 Subject: [PATCH] Don't convert objc_autoreleaseReturnValue to objc_autorelease if the result is returned through a bitcast. llvm-svn: 137402 --- llvm/lib/Transforms/Scalar/ObjCARC.cpp | 19 +++++++++++++------ llvm/test/Transforms/ObjCARC/rv.ll | 11 +++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/ObjCARC.cpp b/llvm/lib/Transforms/Scalar/ObjCARC.cpp index f2cda41c9769..c74c353e81a9 100644 --- a/llvm/lib/Transforms/Scalar/ObjCARC.cpp +++ b/llvm/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(I) || GetBasicInstructionClass(I) == IC_RetainRV) - return; - } + SmallVector 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(I) || GetBasicInstructionClass(I) == IC_RetainRV) + return; + if (isa(I)) + Users.push_back(I); + } + } while (!Users.empty()); Changed = true; ++NumPeeps; diff --git a/llvm/test/Transforms/ObjCARC/rv.ll b/llvm/test/Transforms/ObjCARC/rv.ll index da53a86b10fd..9353a19f71a4 100644 --- a/llvm/test/Transforms/ObjCARC/rv.ll +++ b/llvm/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 +}