<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Tim,<div class=""><br class=""></div><div class="">Good catch.</div><div class=""><br class=""></div><div class="">I would suggest a different fix to avoid having a second lookup in the map.</div><div class="">I would restruct the code such that if we hit the “create” patch, we directly return the created vreg.</div><div class=""><br class=""></div><div class="">I.e., something along those line:</div><div class=""><font face="Menlo" style="font-size: 11px;" class=""><br class=""></font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">ValReg = lookup</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">If (ValReg) return ValReg</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class=""><br class=""></font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">// else Create path.</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class=""><br class=""></font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">VReg = createVReg</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">ValReg = VReg</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class=""><br class=""></font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">// ValReg can be invalidated from this point, but we don’t care since we are not going to use it anymore.</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">// blabla if constant</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class=""><br class=""></font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">return VReg;</font><br class=""><div><br class=""></div><div>What do you think?</div><div><br class=""></div><div>Cheers,</div><div>-Quentin<br class=""><blockquote type="cite" class=""><div class="">On Jan 20, 2017, at 3:25 PM, Tim Northover via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Author: tnorthover<br class="">Date: Fri Jan 20 17:25:17 2017<br class="">New Revision: 292675<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=292675&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=292675&view=rev</a><br class="">Log:<br class="">GlobalISel: prevent heap use-after-free when looking up VReg.<br class=""><br class="">Translating the constant can create more VRegs, which can invalidate the<br class="">reference into the DenseMap. So we have to look up the value again after all<br class="">that's happened.<br class=""><br class="">Modified:<br class="">    llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp<br class=""><br class="">Modified: llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp?rev=292675&r1=292674&r2=292675&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp?rev=292675&r1=292674&r2=292675&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp (original)<br class="">+++ llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp Fri Jan 20 17:25:17 2017<br class="">@@ -81,7 +81,9 @@ unsigned IRTranslator::getOrCreateVReg(c<br class="">       }<br class="">     }<br class="">   }<br class="">-  return ValReg;<br class="">+<br class="">+  // Look Val up again in case the reference has been invalidated since.<br class="">+  return ValToVReg[&Val];<br class=""> }<br class=""><br class=""> int IRTranslator::getOrCreateFrameIndex(const AllocaInst &AI) {<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class=""></div></div></blockquote></div><br class=""></div></body></html>