From: Justin Bogner Date: Fri, 25 Mar 2016 18:38:48 +0000 (+0000) Subject: CodeGen: Fix a use-after-free in TII X-Git-Tag: llvmorg-3.9.0-rc1~10883 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec5ea36891ae3b755a59e309962f820968656da9;p=platform%2Fupstream%2Fllvm.git CodeGen: Fix a use-after-free in TII Found by ASAN with the recycling allocator changes from PR26808. llvm-svn: 264443 --- diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp index eccd1e8..86517d9 100644 --- a/llvm/lib/CodeGen/TargetInstrInfo.cpp +++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp @@ -107,13 +107,15 @@ TargetInstrInfo::ReplaceTailWithBranchTo(MachineBasicBlock::iterator Tail, while (!MBB->succ_empty()) MBB->removeSuccessor(MBB->succ_begin()); + // Save off the debug loc before erasing the instruction. + DebugLoc DL = Tail->getDebugLoc(); + // Remove all the dead instructions from the end of MBB. MBB->erase(Tail, MBB->end()); // If MBB isn't immediately before MBB, insert a branch to it. if (++MachineFunction::iterator(MBB) != MachineFunction::iterator(NewDest)) - InsertBranch(*MBB, NewDest, nullptr, SmallVector(), - Tail->getDebugLoc()); + InsertBranch(*MBB, NewDest, nullptr, SmallVector(), DL); MBB->addSuccessor(NewDest); }