]> granicus.if.org Git - llvm/commitdiff
GlobalISel: prevent heap use-after-free when looking up VReg.
authorTim Northover <tnorthover@apple.com>
Fri, 20 Jan 2017 23:25:17 +0000 (23:25 +0000)
committerTim Northover <tnorthover@apple.com>
Fri, 20 Jan 2017 23:25:17 +0000 (23:25 +0000)
Translating the constant can create more VRegs, which can invalidate the
reference into the DenseMap. So we have to look up the value again after all
that's happened.

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

lib/CodeGen/GlobalISel/IRTranslator.cpp

index 1cfe5345c650071b924086861d328399709497e2..ba6db371139e8728ce88d12574bac90a72eb582d 100644 (file)
@@ -81,7 +81,9 @@ unsigned IRTranslator::getOrCreateVReg(const Value &Val) {
       }
     }
   }
-  return ValReg;
+
+  // Look Val up again in case the reference has been invalidated since.
+  return ValToVReg[&Val];
 }
 
 int IRTranslator::getOrCreateFrameIndex(const AllocaInst &AI) {