<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Can someone give me a second opinion?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here’s the change I am proposing:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Index: lib/IR/Value.cpp<o:p></o:p></p>
<p class="MsoNormal">===================================================================<o:p></o:p></p>
<p class="MsoNormal">--- lib/IR/Value.cpp         (revision 231388)<o:p></o:p></p>
<p class="MsoNormal">+++ lib/IR/Value.cpp      (working copy)<o:p></o:p></p>
<p class="MsoNormal">@@ -69,15 +69,15 @@<o:p></o:p></p>
<p class="MsoNormal">#ifndef NDEBUG      // Only in -g mode...<o:p></o:p></p>
<p class="MsoNormal">   // Check to make sure that there are no uses of this value that are still<o:p></o:p></p>
<p class="MsoNormal">   // around when the value is destroyed.  If there are, then we have a dangling<o:p></o:p></p>
<p class="MsoNormal">-  // reference and something is wrong.  This code is here to print out what is<o:p></o:p></p>
<p class="MsoNormal">-  // still being referenced.  The value in question should be printed as<o:p></o:p></p>
<p class="MsoNormal">-  // a <badref><o:p></o:p></p>
<p class="MsoNormal">+  // reference and something is wrong.  This code is here to print out where<o:p></o:p></p>
<p class="MsoNormal">+  // the value is still being referenced.  The value will be printed as a<o:p></o:p></p>
<p class="MsoNormal">+  // <badref>.<o:p></o:p></p>
<p class="MsoNormal">   //<o:p></o:p></p>
<p class="MsoNormal">   if (!use_empty()) {<o:p></o:p></p>
<p class="MsoNormal">     dbgs() << "While deleting: " << *VTy << " %" << getName() << "\n";<o:p></o:p></p>
<p class="MsoNormal">     for (use_iterator I = use_begin(), E = use_end(); I != E; ++I)<o:p></o:p></p>
<p class="MsoNormal">       dbgs() << "Use still stuck around after Def is destroyed:"<o:p></o:p></p>
<p class="MsoNormal">-           << **I << "\n";<o:p></o:p></p>
<p class="MsoNormal">+           << *(I->getUser()) << "\n";<o:p></o:p></p>
<p class="MsoNormal">   }<o:p></o:p></p>
<p class="MsoNormal">#endif<o:p></o:p></p>
<p class="MsoNormal">   assert(use_empty() && "Uses remain when a value is destroyed!");<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">=======================================================================<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
</div>
</body>
</html>