<div dir="ltr"><div>I'm experiencing a heap use-after-free memory issue after this patch. Is this change (more context provided) intented?</div><div><br></div><div><div>// Construct abstract scopes.</div><div>for (LexicalScope *AScope : LScopes.getAbstractScopesList()) {</div>
<div>  DISubprogram SP(AScope->getScopeNode());</div><div>  if (!SP.isSubprogram())</div><div>    continue;</div><div>  // Collect info for variables that were optimized out.</div><div>  DIArray Variables = SP.getVariables();</div>
<div>  for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {</div><div>    DIVariable DV(Variables.getElement(i));</div><div>    assert(DV && DV.isVariable());</div><div>    if (!ProcessedVars.insert(DV))</div>
<div>      continue;</div><div><div>-   findAbstractVariable(DV, DV.getContext());</div><div>+   getOrCreateAbstractVariable(DV, DV.getContext());</div></div><div>  }</div><div>  constructAbstractSubprogramScopeDIE(TheCU, AScope);</div>
<div>}</div></div><div><br></div><div>It seems like getOrCreateAbstractVariable calls LScopes.getOrCreateAbstractScope which can cause the AbstractScopesList member vector to be resized (via push_back), introducing a modify-container-while-iterating-it bug.</div>
<div><br></div><div>Unfortunately, I don't have a test case for this, any ideas how could I create one?</div><div><br></div><div>Kuba</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

Author: dblaikie<br>Date: Wed Jun  4 18:50:52 2014<br>New Revision: 210221<br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=210221&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=210221&view=rev</a><br>
Log:<br>
DebugInfo: Reapply r209984 (reverted in r210143), asserting that abstract DbgVariables have DIEs.<br>Abstract variables within abstract scopes that are entirely optimized<br>away in their first inlining are omitted because their scope is not<br>

present so the variable is never created. Instead, we should ensure the<br>scope is created so the variable can be added, even if it's been<br>optimized away in its first inlining.<br>This fixes the incorrect debug info in missing-abstract-variable.ll<br>

(added in r210143) and passes an asserts self-hosting build, so<br>hopefully there's not more of these issues left behind... *fingers<br>crossed*.<br>Modified:<br>    llvm/trunk/include/llvm/CodeGen/LexicalScopes.h<br>

    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h<br>    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp<br>    llvm/trunk/test/DebugInfo/missing-abstract-variable.ll</blockquote>

</div>