[cfe-dev] AST Matcher matches InitListExpr child twice

Ben Liblit via cfe-dev cfe-dev at lists.llvm.org
Mon Jun 12 10:53:50 PDT 2017


Stephan Bergmann <sbergman at redhat.com> wrote:
> That looks to be by design, cf. DEF_TRAVERSE_STMT(InitListExpr,...) in 
> include/clang/AST/RecursiveASTVisitor.h calling into 
> TraverseSynOrSemInitListExpr twice (for "syntactic" and "semantic" 
> InitListExpr).

Nutty!  But clearly by design, as you point out.  There seems to be no 
way to detect this duplication short of maintaining my own "nodes I have 
already seen" set, and no way to prevent double visits short of defining 
my own RecursiveASTVisitor.

> In some of our LibreOffice RecursiveASTVisitor implementations we use
> [...] to traverse only once

Thank you for this example code, Stephan.  Unfortunately I see no way to 
tell the AST Matcher system to use an alternate visitor of this sort. 
Am I missing some API that would let me do this?  Or is the recursive 
visit outside of my control if I'm using MatchFinder to drive my tool?

-- Ben



More information about the cfe-dev mailing list