<div dir="ltr">I think this just a bug.<div>I actually had the same bug in some other code.</div><div>Nowadays, i think this should just be "for (I : users())"</div><div><br></div><div>The main use of the use_begin/use_end idiom nowadays is to be able to modify the use list itself (IE people removing uses) without iterator invalidation.</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 10, 2015 at 12:23 PM, Kaylor, Andrew <span dir="ltr"><<a href="mailto:andrew.kaylor@intel.com" target="_blank">andrew.kaylor@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal">In the course of adding some new code I came across a debug output message before an assert that was extremely unhelpful. If I incorrectly try to delete a Value object that still has uses in a debug build, an debug message is printed just
before an assertion that says it is telling me where the value is still being used but actually just tries to print the value itself multiple times, which in my case was crashing because the Value was already partially destructed.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">It looked like a pretty simple and obvious fix and I was just going to go ahead and commit it, but when I looked at the revision history I saw that the current behavior has been in place since 2002. So I thought maybe it would be a good
idea to get a reality check and make sure I wasn’t being an idiot in some way.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Can someone give me a second opinion?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Here’s the change I am proposing:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Index: lib/IR/Value.cpp<u></u><u></u></p>
<p class="MsoNormal">===================================================================<u></u><u></u></p>
<p class="MsoNormal">--- lib/IR/Value.cpp (revision 231388)<u></u><u></u></p>
<p class="MsoNormal">+++ lib/IR/Value.cpp (working copy)<u></u><u></u></p>
<p class="MsoNormal">@@ -69,15 +69,15 @@<u></u><u></u></p>
<p class="MsoNormal">#ifndef NDEBUG // Only in -g mode...<u></u><u></u></p>
<p class="MsoNormal"> // Check to make sure that there are no uses of this value that are still<u></u><u></u></p>
<p class="MsoNormal"> // around when the value is destroyed. If there are, then we have a dangling<u></u><u></u></p>
<p class="MsoNormal">- // reference and something is wrong. This code is here to print out what is<u></u><u></u></p>
<p class="MsoNormal">- // still being referenced. The value in question should be printed as<u></u><u></u></p>
<p class="MsoNormal">- // a <badref><u></u><u></u></p>
<p class="MsoNormal">+ // reference and something is wrong. This code is here to print out where<u></u><u></u></p>
<p class="MsoNormal">+ // the value is still being referenced. The value will be printed as a<u></u><u></u></p>
<p class="MsoNormal">+ // <badref>.<u></u><u></u></p>
<p class="MsoNormal"> //<u></u><u></u></p>
<p class="MsoNormal"> if (!use_empty()) {<u></u><u></u></p>
<p class="MsoNormal"> dbgs() << "While deleting: " << *VTy << " %" << getName() << "\n";<u></u><u></u></p>
<p class="MsoNormal"> for (use_iterator I = use_begin(), E = use_end(); I != E; ++I)<u></u><u></u></p>
<p class="MsoNormal"> dbgs() << "Use still stuck around after Def is destroyed:"<u></u><u></u></p>
<p class="MsoNormal">- << **I << "\n";<u></u><u></u></p>
<p class="MsoNormal">+ << *(I->getUser()) << "\n";<u></u><u></u></p>
<p class="MsoNormal"> }<u></u><u></u></p>
<p class="MsoNormal">#endif<u></u><u></u></p>
<p class="MsoNormal"> assert(use_empty() && "Uses remain when a value is destroyed!");<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">=======================================================================<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">This code appears in the Value::~Value(). I’m pretty sure that “**I” here is just going to be a reference to the Value being destructed, whereas *(I->getUser()) will provide useful information.<u></u><u></u></p>
</div>
</div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>