<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 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@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:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@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="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal>My eventual question:<o:p></o:p></p><p class=MsoNormal>What is the best way for analysis AST visitors to visit template instantiations?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Background:<o:p></o:p></p><p class=MsoNormal>I am working on a checker that will report about excessive padding.  Basically, any place where padding could be reduced by reordering data members, I want to emit a report.  This is different from –Wpadding because I don’t want to report on items where there isn’t a relatively easy fix.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The general way I’m implementing this is by using the check::ASTDecl<RecordDecl> visitor, returning early for some really troublesome cases, then using getASTRecordLayout.  I then compare the actual size and padding against a computed optimal padding and size, and report when the observed padding doesn’t meet the optimal padding.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I started writing tests for this, and started to run into problems with C++ templates.  Here is the most troublesome code test case I’ve hit so far:<o:p></o:p></p><p class=MsoNormal>template <typename T><o:p></o:p></p><p class=MsoNormal>struct Foo {<o:p></o:p></p><p class=MsoNormal>  // expected-warning@+1{{Excessive padding in struct 'Foo<int>::Nested'}}<o:p></o:p></p><p class=MsoNormal>  struct Nested { // doesn’t actually warn though…<o:p></o:p></p><p class=MsoNormal>    char c1;<o:p></o:p></p><p class=MsoNormal>    T t;<o:p></o:p></p><p class=MsoNormal>    char c2;<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>struct Holder { //no-warning<o:p></o:p></p><p class=MsoNormal>  Foo<int>::Nested t1;<o:p></o:p></p><p class=MsoNormal>  Foo<char>::Nested t2;<o:p></o:p></p><p class=MsoNormal>};<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>It seems that by default, AnalysisConsumer doesn’t visit template instantiations.  In fact, if I add “bool shouldVisitTemplateInstantiations() const { return true; }” to the AnalysisConsumer class, I get the reports I expect.  Is there a better way for me to accomplish my goal?  I don’t like the idea of turning on instantiation visitation for every checker just because my checker needs it.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Before I found AnalysisConsumer, I did make an attempt to walk the instantiations by visiting ClassTemplateDecl and iterating over specializations.  That works ok if I don’t have nested Records, like I posted above.  I hadn’t found the “right” way to recurse into the structure before finding shouldVisitTemplateInsantiations.  Maybe a “better” approach is to basically copy RecursiveASTVisitor::TraverseClassInstantiation?  I’m not sure if I’m comfortable duplicating that code, but if it’s the better option then I will.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks for the help,<o:p></o:p></p><p class=MsoNormal>Ben Craig<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>Employee of Qualcomm Innovation Center, Inc.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>