<div dir="rtl"><div dir="ltr">Hi,</div><div dir="ltr"><br></div><div dir="ltr">MIChainHead is a pointer to the head of a linked list of MacroInfoChain nodes, each containing a MacroInfo and MacroInfoChain*.<br></div><div dir="ltr">


<br></div><div dir="ltr">Why does the while loop modify MIChainHead on every iteration?</div><div dir="ltr">MIChainHead should be modified only if it points to the node containing the removed <span style="font-size:12.727272033691406px;font-family:arial,sans-serif">MacroInfo MI. </span><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">In all other cases it should not change.</span></div>


<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></span></div><div dir="ltr">As it is now, the loop will always terminate with MIChainHead == nullptr.<br></div><div dir="ltr"><br>


</div><div dir="ltr">Yaron</div><div dir="ltr"><br></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div dir="ltr">2014-08-03 21:10 GMT+03:00 Vassil Vassilev <span dir="ltr"><<a href="mailto:vvasilev@cern.ch" target="_blank">vvasilev@cern.ch</a>></span>:</div>


<blockquote class="gmail_quote" style="margin:0 .8ex;border-left:1px #ccc solid;border-right:1px #ccc solid;padding-left:1ex;padding-right:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <div>Hi Yaron,<br>
        Yes I meant double destruction.<span><font color="#888888"><br>
      Vassil</font></span><div><div><br>
      On 03/08/14 20:08, Yaron Keren wrote:<br>
    </div></div></div><div><div>
    <blockquote type="cite">
      
      <div dir="rtl">
        <div dir="ltr">Hi Vassil,</div>
        <div dir="ltr"><br>
        </div>
        <div dir="ltr">Do you mean double destruction (not deletion) of <span style="font-family:arial,sans-serif;font-size:12.727272033691406px">MacroInfo
            first time in </span><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">ReleaseMacroInfo </span><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">and
            the second time in </span>~Preprocessor via
           ~MacroInfoChain?</div>
        <div dir="ltr"><br>
        </div>
        <div dir="ltr">
          <div dir="ltr">  while (MacroInfoChain *I = MIChainHead) {</div>
          <div dir="ltr">    MIChainHead = I->Next;</div>
          <div dir="ltr">    I->~MacroInfoChain();</div>
          <div dir="ltr">  }</div>
          <div><br>
          </div>
          <div>or something else?</div>
          <div><br>
          </div>
          <div>Yaron<br>
          </div>
        </div>
        <div dir="ltr"><br>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">
          <div dir="ltr">2014-08-02 23:05 GMT+03:00 Vassil Vassilev <span dir="ltr"><<a href="mailto:vvasilev@cern.ch" target="_blank">vvasilev@cern.ch</a>></span>:</div>
          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
              In cases where ReleaseMacroInfo gets called and it doesn't
            cleanup the Preprocessor's MIChainHead can lead to double
            deletion. I am sending the patch that fixes the problem for
            me.<br>
            Vassil<br>
            <br>
            <br>
            diff --git a/lib/Lex/PPDirectives.cpp
            b/lib/Lex/PPDirectives.cpp<br>
            index 5f38387..1a9b5eb 100644<br>
            --- a/lib/Lex/PPDirectives.cpp<br>
            +++ b/lib/Lex/PPDirectives.cpp<br>
            @@ -94,6 +94,14 @@ Preprocessor::AllocateVisibilityMacroDirective(SourceLocation
            Loc,<br>
             /// error in the macro definition.<br>
             void Preprocessor::ReleaseMacroInfo(MacroInfo *MI) {<br>
               // Don't try to reuse the storage; this only happens on
            error paths.<br>
            +<br>
            +  // If this is on the macro info chain, avoid double
            deletion on teardown.<br>
            +  while (MacroInfoChain *I = MIChainHead) {<br>
            +    if (&(I->MI) == MI)<br>
            +      I->Next = (I->Next) ? I->Next->Next : 0;<br>
            +    MIChainHead = I->Next;<br>
            +  }<br>
            +<br>
               MI->~MacroInfo();<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>
    </blockquote>
    <br>
  </div></div></div>

</blockquote></div><br></div></div>