From 6955b2c2f5057301533fecd2c28a0155fa49a29b Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Fri, 20 Jan 2017 23:25:17 +0000 Subject: [PATCH] GlobalISel: prevent heap use-after-free when looking up VReg. 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/GlobalISel/IRTranslator.cpp b/lib/CodeGen/GlobalISel/IRTranslator.cpp index 1cfe5345c65..ba6db371139 100644 --- a/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -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) { -- 2.40.0