[llvm] r264443 - CodeGen: Fix a use-after-free in TII

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 25 11:38:48 PDT 2016


Author: bogner
Date: Fri Mar 25 13:38:48 2016
New Revision: 264443

URL: http://llvm.org/viewvc/llvm-project?rev=264443&view=rev
Log:
CodeGen: Fix a use-after-free in TII

Found by ASAN with the recycling allocator changes from PR26808.

Modified:
    llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp

Modified: llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp?rev=264443&r1=264442&r2=264443&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp Fri Mar 25 13:38:48 2016
@@ -107,13 +107,15 @@ TargetInstrInfo::ReplaceTailWithBranchTo
   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<MachineOperand, 0>(),
-                 Tail->getDebugLoc());
+    InsertBranch(*MBB, NewDest, nullptr, SmallVector<MachineOperand, 0>(), DL);
   MBB->addSuccessor(NewDest);
 }
 




More information about the llvm-commits mailing list