[cfe-dev] doing global unused methods analysis

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


Looks to me like everything is in the AST:

$ cat /tmp/t.cc
template <typename T> class A {};
template <typename T> class B {};
class C : public A<B<int>>{};

$ clang-query /tmp/t.cc -- -std=c++11
clang-query> m cxxRecordDecl()

Match #1:

Binding for "root":
CXXRecordDecl 0x32ec0c0 </tmp/t.cc:1:23, col:32> col:29 class A definition
`-CXXRecordDecl 0x3339180 <col:23, col:29> col:29 implicit class A


Match #2:

Binding for "root":
CXXRecordDecl 0x3339180 </tmp/t.cc:1:23, col:29> col:29 implicit class A


Match #3:

Binding for "root":
ClassTemplateSpecializationDecl 0x33398f8 </tmp/t.cc:1:1, col:32> col:29
class A definition
|-TemplateArgument type 'class B<int>'
`-CXXRecordDecl 0x3339ad8 prev 0x33398f8 <col:23, col:29> col:29 implicit
class A


Match #4:

Binding for "root":
CXXRecordDecl 0x3339ad8 prev 0x33398f8 </tmp/t.cc:1:23, col:29> col:29
implicit class A


Match #5:

Binding for "root":
CXXRecordDecl 0x3339290 </tmp/t.cc:2:23, col:32> col:29 class B definition
`-CXXRecordDecl 0x3339598 <col:23, col:29> col:29 implicit class B


Match #6:

Binding for "root":
CXXRecordDecl 0x3339598 </tmp/t.cc:2:23, col:29> col:29 implicit class B


Match #7:

Binding for "root":
ClassTemplateSpecializationDecl 0x3339750 </tmp/t.cc:2:1, col:32> col:29
class B
`-TemplateArgument type 'int'


Match #8:

Binding for "root":
CXXRecordDecl 0x3339628 </tmp/t.cc:3:1, col:28> col:7 class C definition
|-public 'A<B<int> >':'class A<class B<int> >'
`-CXXRecordDecl 0x3339b98 <col:1, col:7> col:7 implicit class C


Match #9:

Binding for "root":
CXXRecordDecl 0x3339b98 </tmp/t.cc:3:1, col:7> col:7 implicit class C

On Mon, Oct 5, 2015 at 2:42 PM Noel Grandin via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi
>
> I'm working on the LibreOffice team, and I'm using a clang plugin to do a
> fairly brute-force analysis looking for unused
> methods, using the clang compiler plugin API.
>
> Mostly this works fairly well. I'm walking the AST and outputting every
> method definition I see, and every call I see.
>
> The one shortcoming is that clang does not generate AST nodes for all
> implicit instantiations of templates.
> For example, if I have
>     template<T> class A {};
>     template<T> class B {};
>     class C : public A< B<int> > {};
> , it will not generate AST nodes for the B<int> instantiation that occurs
> in the template parameter.
>
> Is there a way to make clang do this, or am I simply barking up the wrong
> tree :-) ?
>
> Thanks, Noel Grandin.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151005/e6328cb5/attachment.html>


More information about the cfe-dev mailing list