Re: [llvm-dev] RecursiveASTVisitor won't visit all declarations

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re: [llvm-dev] RecursiveASTVisitor won't visit all declarations

Дилян Палаузов via cfe-dev

I think it’s more suitable to ask this question on clang mailing list (cfe-dev)


On Feb 5, 2019, at 12:29 AM, Teodor Dermendzhiev via llvm-dev <[hidden email]> wrote:

Hi all,
I am having problems walking through the syntax tree of a simple header file. With llvm 4.0.1 everything works as expected but after upgrading to 7.0.0 I notice that just a small number of all declarations in the AST are being visited. 

Running a simple ASTFrontendAction (like the one from this article - ) in HandleTranslationUnit() -

    virtual void HandleTranslationUnit(ASTContext &Context) {
        Decl* tu = Context.getTranslationUnitDecl();

when I dump the *tu* variable I get a lot smaller dump with 7.0.0. After investigating further I updated TraverseDeclContextHelper() method in order to print the size of decls() container for every DeclContext we visit:

template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
  if (!DC)
    return true;

  int childSize = 0; // my code

  for (auto *Child : DC->decls()) {
    childSize++; // my code
    if (!canIgnoreChildDeclWhileTraversingDeclContext(Child))

  std::cout << DC->getDeclKindName() << ": " << childSize << " child declarations" << "\n"; //my code

  return true;

With llvm 4.0.0 I get: 
TranslationUnit: 20526 child declarations

while with 7.0.0:
TranslationUnit: 486 child declarations

I created a sample project that illustrates this behavior - . 

Any help tackling this issue is appreciated. Thank you.

Best wishes,
Teodor Dermendzhiev

LLVM Developers mailing list
[hidden email]

cfe-dev mailing list
[hidden email]