From: Aditya Nandakumar Date: Wed, 17 May 2017 17:41:55 +0000 (+0000) Subject: [GISel]: Fix undefined behavior in IRTranslator X-Git-Tag: llvmorg-5.0.0-rc1~4866 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=be9299371038c881248296a2051b66c977dbd419;p=platform%2Fupstream%2Fllvm.git [GISel]: Fix undefined behavior in IRTranslator Make sure IRTranslator->MachineIRBuilder->DebugLoc doesn't outlive the DILocation. Clear it at the end of IRTranslator::runOnMachineFunction llvm-svn: 303277 --- diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index 811858f..77dfb13 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -1129,6 +1129,11 @@ void IRTranslator::finalizeFunction() { ValToVReg.clear(); FrameIndices.clear(); MachinePreds.clear(); + // MachineIRBuilder::DebugLoc can outlive the DILocation it holds. Clear it + // to avoid accessing free’d memory (in runOnMachineFunction) and to avoid + // destroying it twice (in ~IRTranslator() and ~LLVMContext()) + EntryBuilder = MachineIRBuilder(); + CurBuilder = MachineIRBuilder(); } bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {