[cfe-dev] doing global unused methods analysis

Manuel Klimek via cfe-dev cfe-dev at lists.llvm.org
Mon Oct 5 06:40:07 PDT 2015


On Mon, Oct 5, 2015 at 3:27 PM Noel Grandin <noelgrandin at gmail.com> wrote:

> Hi Manuel
>
> That was a bad example, this is a better one (dramatically simplified from
> my actual code).
> I can't seem to use clang-query here (I have 3.6), but dumping the AST
> shows my problem.
>

Note that the AST dump doesn't contain all nodes.
In this case, it is correct though. The problem is that the method is not
actually instantiated. You'll need to reference it in order for it to
actually get instantiated.


>
> Specifically, in the below code, when I traverse the AST, there is no way
> to see that a call to doRegisterHandlers() is
> in fact being generated.
>
> The relevant section of AST looks like:
> CallExpr 0x328d958 <line:15:9, col:42> '<dependent type>'
> | | | |   |-CXXDependentScopeMemberExpr 0x328d8d8 <col:9, col:15>
> '<dependent type>' lvalue
> | | | |   | `-CXXThisExpr 0x328d8c0 <col:9> 'ImportFilterImpl<Generator>
> *' this
> | | | |   `-DeclRefExpr 0x328d930 <col:34> 'Generator' lvalue Var
> 0x328d850 'exporter' 'Generator'
>
>
> Now I know that clang is doing the right thing here, but I'm hoping there
> is a way I can tell it to "expand out" and
> generate more AST nodes when I hit a template instantiation?
>
> Thanks a lot for the help!
>
> Regards, Noel.
>
>
> --------------------------------------
>
> class XFilter
> {
> public:
>      virtual bool filter()  = 0;
> };
>
> template<class Generator>
> class ImportFilterImpl : public XFilter
> {
> public:
>      virtual bool filter() override
>      {
>          Generator exporter;
>          this->doRegisterHandlers(exporter);
>      }
>
> private:
>      virtual void doRegisterHandlers(Generator &) {};
> };
>
>
> template<class T>
> class ImplInheritanceHelper : public T
> {};
>
> template<class Generator>
> struct ImportFilter : public
> ImplInheritanceHelper<ImportFilterImpl<Generator> >
> {
> };
>
> class MyGenerator {};
>
> class MainClass : public ImportFilter<MyGenerator>
> {};
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151005/69e9ba24/attachment.html>


More information about the cfe-dev mailing list