[llvm] r292675 - GlobalISel: prevent heap use-after-free when looking up VReg.

Tim Northover via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 20 15:25:17 PST 2017


Author: tnorthover
Date: Fri Jan 20 17:25:17 2017
New Revision: 292675

URL: http://llvm.org/viewvc/llvm-project?rev=292675&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp

Modified: llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp?rev=292675&r1=292674&r2=292675&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp Fri Jan 20 17:25:17 2017
@@ -81,7 +81,9 @@ unsigned IRTranslator::getOrCreateVReg(c
       }
     }
   }
-  return ValReg;
+
+  // Look Val up again in case the reference has been invalidated since.
+  return ValToVReg[&Val];
 }
 
 int IRTranslator::getOrCreateFrameIndex(const AllocaInst &AI) {




More information about the llvm-commits mailing list