<div dir="ltr">> I guess nobody did this before because plists were supposed to be
    used by IDEs, and IDEs were supposed to have their own
    jump-to-definition functionality (in this case, macro definition).<br><br><div>Is
 it correct that plists are only meant for IDEs? IDEs cannot always know
 which compilation action was used to analyze the TU. Especially if the 
analysis (or the compilation) is made for multiple targets (32-64 bits 
etc).<br><br></div><div>I've often been made aware of user complaints 
that the Static Analyzer found a false positive, but it's often 
virtually impossible to trace back what really happened, as the cluster 
of macros was so hard to follow, not even jump-to-definition was a 
satisfactory solution.<br><br>I think it would valuable to show the 
macro expansion as the Static Analyzer expands it. I'm however a little 
uncertain as to how I'd implement this. There's two options that came to
 my mind:<br><br></div><div>* Add macro expansion info into the plist 
output (behind an optional flag, and maybe a macros-as-events flag too).
 This would easily be the best solution for my needs, but seems to be 
hard to implement well. It also depends on other consumers of the plist 
output whether there's an actual desire for this feature other than 
mine.<br><br></div><div>* Develop a standalone clang tool that would 
create a new file with the macro expansions. This would be the least 
invasive solution for plist file generation, but also the least 
comfortable for my needs.<br><br></div><div>My main question is, would you be fine with adding a new macro node to the plist output?<br><br></div><div>Cheers,<br></div>Kristóf</div><br><div class="gmail_quote"><div dir="ltr">Kristóf Umann <<a href="mailto:dkszelethus@gmail.com">dkszelethus@gmail.com</a>> ezt írta (időpont: 2018. aug. 27., H, 17:11):<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Thanks for the great responses!<br><br></div>I've had quite a few conversations with my colleges and I think I'll take another direction with this, one that doesn't involve plists. It's a great point to mention that macro expansions shouldn't be handled by the analyzer, although jump-to-definition isn't an ideal solution to to my (our) problems, as macro definitions are often very hard to read due to them containing references to various other macros.<br><br></div>Cheers,<br></div>Kristóf<br></div><br><div class="gmail_quote"><div dir="ltr">George Karpenkov <<a href="mailto:ekarpenkov@apple.com" target="_blank">ekarpenkov@apple.com</a>> ezt írta (időpont: 2018. aug. 18., Szo, 2:03):<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">I just wanted to say that it would be really amazing if HTML output knew how to show the macros properly (I guess it might be less critical for plists, as Artem says).<div>This is definitely one of my top complaints about HTML reports; I’ve tried working on it at the past, but other work took priority.</div><div><div><br><blockquote type="cite"><div>On Aug 17, 2018, at 4:55 PM, Artem Dergachev via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="m_-1742139835440702351m_-2071606503778737690Apple-interchange-newline"><div>
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    I guess nobody did this before because plists were supposed to be
    used by IDEs, and IDEs were supposed to have their own
    jump-to-definition functionality (in this case, macro definition).<br>
    <br>
    I don't know that much about macros and source locations, but i
    suspect it should indeed be possible to obtain the expanded text by
    traversing spelling and expansion locations, though probably
    sometimes scanning token-by-token is inevitable. To state the
    obvious, there are a lot of useful methods in the SourceManager, but
    it's often unobvious how to combine them correctly :/<br>
    <br>
    <div class="m_-1742139835440702351m_-2071606503778737690moz-cite-prefix">On 8/17/18 5:09 AM, Kristóf Umann via
      cfe-dev wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">
        <div>Hi!<br>
          <br>
          I'm currently trying to implement a new node in the plist
          output that would show the expansion of a macro, like this:<br>
          <br>
          <span style="font-family:monospace,monospace">void
            setToNull(int **vptr) {</span><br>
          <span style="font-family:monospace,monospace">  *vptr =
            nullptr;</span><br>
          <span style="font-family:monospace,monospace">}</span><br>
          <span style="font-family:monospace,monospace"><br>
          </span></div>
        <span style="font-family:monospace,monospace">void print(void*);</span><br>
        <div><br>
          <span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">#define TO_NULL(x) \<br>
          </span><span style="font-family:monospace,monospace"> 
            setToNull(x)<br>
          </span><span style="font-family:monospace,monospace"><br>
          </span><span style="font-family:monospace,monospace">#define
            DOES_NOTHING(x) \</span><br>
          <span style="font-family:monospace,monospace"> 
            {                     \</span><br>
          <span style="font-family:monospace,monospace">    int
            b;              \</span><br>
          <span style="font-family:monospace,monospace">    b =
            5;              \</span><br>
          <span style="font-family:monospace,monospace"> 
            }                     \</span><br>
          <span style="font-family:monospace,monospace">  print(x)</span><br>
          <span style="font-family:monospace,monospace"></span><br>
          <span style="font-family:monospace,monospace">#define
            DEREF(x)   \</span><br>
          <span style="font-family:monospace,monospace"> 
            DOES_NOTHING(x); \</span><br>
          <span style="font-family:monospace,monospace">  *x</span><br>
          <span style="font-family:monospace,monospace"></span><br>
          <span style="font-family:monospace,monospace">void f() {</span><br>
          <span style="font-family:monospace,monospace">  int *a = new
            int(5);</span><br>
          <span style="font-family:monospace,monospace"> 
            TO_NULL(&a);</span><br>
          <span style="font-family:monospace,monospace">  DEREF(a) = 5;</span><br>
          <span style="font-family:monospace,monospace">}</span><br>
          <br>
          For this code, two <span style="font-family:monospace,monospace">PathDiagnosticMacroPiece</span>s
          should be generated, and a message like this should be
          displayed:<span style="font-family:monospace,monospace"></span><br>
          <span style="font-family:monospace,monospace">  Expanding
            macro 'TO_NULL' to 'print(&a); setToNull(&a)'</span><br>
          <span style="font-family:monospace,monospace">  Expanding
            macro 'DEREF' to '{ int sajt; sajt = 5; } print(a); *a'</span><br>
          I've made some progress on this issue, but here are the
          problems I faced.<br>
          <br>
          Currently, HTML file generation supports macro expansions
          fairly well, however, the code that achieves this seems to be
          held together by sheer luck:<br>
          <a href="https://clang.llvm.org/doxygen/namespaceclang_1_1html.html#a3283736376c3e436ff65975acdb1d399" target="_blank">https://clang.llvm.org/doxygen/namespaceclang_1_1html.html#a3283736376c3e436ff65975acdb1d399</a><br>
          As I understand it, the entire file is re-lexed and
          preprocessed, during which macro expansions are added to the
          HTML file. I attempted to reuse the code here without having
          to re-lex everything, but so far my efforts lead to little
          success. I also found that any modification of this code
          quickly leads to instabilities -- although this part of Clang
          is somewhat of a mystery to me just yet, so I'd concede to
          this being my fault.<br>
          <br>
          I also fear that since HTML output is not as used as other
          outputs, and could lack vigorous testing, it could be
          crash-prone.<br>
          <div>
            <div style="margin-left:40px"><br>
            </div>
            Do you know any way of obtaining the expansion of a macro
            expression that doesn't involve such <span class="m_-1742139835440702351m_-2071606503778737690gmail-m_5067136254874769323gmail-yZ8quc m_-1742139835440702351m_-2071606503778737690gmail-m_5067136254874769323gmail-ILfuVd">abusement</span>
            of the preprocessor? Something like this would be ideal:<br>
            <span style="font-family:monospace,monospace"></span><br>
            <span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">SourceLocation Loc
              = /* PathDiagnosticMacroPiece location */;</span><br>
            <span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">Preproc.getMacroExpansionForExpression(Loc));</span><br>
            <br>
            Cheers,<br>
            Kristóf</div>
        </div>
      </div>
      <br>
      <fieldset class="m_-1742139835440702351m_-2071606503778737690mimeAttachmentHeader"></fieldset>
      <pre class="m_-1742139835440702351m_-2071606503778737690moz-quote-pre">_______________________________________________
cfe-dev mailing list
<a class="m_-1742139835440702351m_-2071606503778737690moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>
<a class="m_-1742139835440702351m_-2071606503778737690moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
    </blockquote>
    <br>
  </div>

_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br></div></blockquote></div><br></div></div></blockquote></div>
</blockquote></div>