]> granicus.if.org Git - llvm/commitdiff
[GISel]: Fix undefined behavior in IRTranslator
authorAditya Nandakumar <aditya_nandakumar@apple.com>
Wed, 17 May 2017 17:41:55 +0000 (17:41 +0000)
committerAditya Nandakumar <aditya_nandakumar@apple.com>
Wed, 17 May 2017 17:41:55 +0000 (17:41 +0000)
Make sure IRTranslator->MachineIRBuilder->DebugLoc doesn't
outlive the DILocation. Clear it at the end of
IRTranslator::runOnMachineFunction

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303277 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/GlobalISel/IRTranslator.cpp

index 811858f136eb3c37c9a3bc1542bea5c23d8cdebc..77dfb13ac1f2dfded5ebe6ad5036f49eab10c054 100644 (file)
@@ -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) {