<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 19, 2014 at 11:18 AM, Frédéric Riss <span dir="ltr"><<a href="mailto:friss@apple.com" target="_blank">friss@apple.com</a>></span> wrote:<br><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"><div style="word-wrap:break-word"><br><div><div><div><blockquote type="cite"><div>On Nov 19, 2014, at 11:05 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 19, 2014 at 10:53 AM, Frederic Riss <span dir="ltr"><<a href="mailto:friss@apple.com" target="_blank">friss@apple.com</a>></span> wrote:<br><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: friss<br>
Date: Wed Nov 19 12:53:46 2014<br>
New Revision: 222373<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=222373&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=222373&view=rev</a><br>
Log:<br>
Fix a temporary MDNode leak.<br>
<br>
While emitting debug information for function forward decalrations, we<br>
create DISubprogram objects that aran't stored in the AllSubprograms<br>
list, and thus won't get finalized by the DIBuilder. During the DIBuilder<br>
finalize(), the temporary MDNode allocated for the DISubprogram<br>
Variables field gets RAUWd with a non temporary DIArray. For the forward<br>
declarations, simply delete that temporary node before we delete the<br>
parent node, so that it doesn't leak.<br>
<br>
Modified:<br>
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=222373&r1=222372&r2=222373&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=222373&r1=222372&r2=222373&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Nov 19 12:53:46 2014<br>
@@ -3398,6 +3398,13 @@ void CGDebugInfo::finalize() {<br>
VH = p.second;<br>
else<br>
VH = it->second;<br>
+<br>
+ // Functions have a fake temporary MDNode operand that is supposed<br>
+ // to get RAUWed upon DIBuilder finalization. Do not leak these<br>
+ // nodes for the temporary functions we are about to delete.<br>
+ if (FwdDecl.isSubprogram())<br>
+ llvm::MDNode::deleteTemporary(llvm::DISubprogram(FwdDecl).getVariablesNodes());<br></blockquote><div><br>Should we avoid creating a variables node for declarations in the first place?</div></div></div></div></div></blockquote><div><br></div></div></div><div>I wondered about that also. I couldn’t find a nice way to rework DIBuilder.cpp:createFunctionHelper() to make that happen, except for duplicating the code and removing the helper altogether. If you have any ideas (or if you think just separating totally createFunction and createTempFunctionFwdDecl is cleaner), let me know. </div></div></div></blockquote><div><br>Would it work for the callers to just pass in that field? Something like this:<br><br><br><div>diff --git lib/IR/DIBuilder.cpp lib/IR/DIBuilder.cpp</div><div>index 204817f..4fe2be6 100644</div><div>--- lib/IR/DIBuilder.cpp</div><div>+++ lib/IR/DIBuilder.cpp</div><div>@@ -937,11 +937,10 @@ createFunctionHelper(LLVMContext &VMContext, DIDescriptor Context, StringRef Nam</div><div> StringRef LinkageName, DIFile File, unsigned LineNo,</div><div> DICompositeType Ty, bool isLocalToUnit, bool isDefinition,</div><div> unsigned ScopeLine, unsigned Flags, bool isOptimized,</div><div>- Function *Fn, MDNode *TParams, MDNode *Decl,</div><div>+ Function *Fn, MDNode *TParams, MDNode *Decl, MDNode *Vars,</div><div> std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) {</div><div> assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&</div><div> "function types should be subroutines");</div><div>- Value *TElts[] = {HeaderBuilder::get(DW_TAG_base_type).get(VMContext)};</div><div> Value *Elts[] = {</div><div> HeaderBuilder::get(dwarf::DW_TAG_subprogram)</div><div> .concat(Name)</div><div>@@ -957,7 +956,7 @@ createFunctionHelper(LLVMContext &VMContext, DIDescriptor Context, StringRef Nam</div><div> .concat(ScopeLine)</div><div> .get(VMContext),</div><div> File.getFileNode(), DIScope(getNonCompileUnitScope(Context)).getRef(), Ty,</div><div>- nullptr, Fn, TParams, Decl, MDNode::getTemporary(VMContext, TElts)};</div><div>+ nullptr, Fn, TParams, Decl, Vars};</div><div> </div><div> DISubprogram S(CreateFunc(Elts));</div><div> assert(S.isSubprogram() &&</div><div>@@ -976,6 +975,7 @@ DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,</div><div> return createFunctionHelper(VMContext, Context, Name, LinkageName, File,</div><div> LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,</div><div> Flags, isOptimized, Fn, TParams, Decl,</div><div>+ MDNode::getTemporary(VMContext, None),</div><div> [&] (ArrayRef<Value *> Elts) -> MDNode *{</div><div> MDNode *Node = MDNode::get(VMContext, Elts);</div><div> // Create a named metadata so that we</div><div>@@ -996,7 +996,7 @@ DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name,</div><div> MDNode *TParams, MDNode *Decl) {</div><div> return createFunctionHelper(VMContext, Context, Name, LinkageName, File,</div><div> LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,</div><div>- Flags, isOptimized, Fn, TParams, Decl,</div><div>+ Flags, isOptimized, Fn, TParams, Decl, nullptr,</div><div> [&] (ArrayRef<Value *> Elts) {</div><div> return MDNode::getTemporary(VMContext, Elts);</div><div> });</div><div><br></div><br> </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"><div style="word-wrap:break-word"><div><div><br></div><div>Fred</div><span><div><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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">
+<br>
FwdDecl.replaceAllUsesWith(CGM.getLLVMContext(),<br>
llvm::DIDescriptor(cast<llvm::MDNode>(VH)));<br>
}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>
</div></blockquote></span></div><br></div></blockquote></div><br></div></div>