[cfe-dev] Life time of AST elements.

Manuel Klimek via cfe-dev cfe-dev at lists.llvm.org
Mon Oct 12 06:58:23 PDT 2015


On Mon, Oct 12, 2015 at 2:37 PM Frank Redeker via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hello all,
>
> I'm writing a tool to analyze the call hierarchy of functions (methods)
> using ClangTool.
>
> My idea is to collect the TranslationUnitDecls given to my own
> ASTCosumer's HandleTranslationUnit method and traverse them later when
> ClangTool.run() has finished.
>
> But it seems that the AST nodes are no longer valid after
> ClangTool.run() has returned. (e.g. If I call getQualifiedNameAsString()
> on a FunctionDecl object retrieved from the TranslationUnitDecl, I get
> `Assertion failed: DC && "This decl is not contained in a translation
> unit!"`)
>
> So I wonder if there is any trick to extend the life time for the AST or
> should I use ClangTool.buildAST() rather then ClangTool.run() to get the
> ASTs ?
>

The idea is to do the reverse:
Store any information about the AST you want later in some data structure
in the callback.


>
>
> Frank
> _______________________________________________
> 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/20151012/5d1fef4c/attachment.html>


More information about the cfe-dev mailing list