[cfe-dev] VisitUnaryOperator called twice in RecursiveASTVisitor when post-order traversal

Malcolm Parsons via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 15 08:20:21 PST 2016


On 15 November 2016 at 13:29, Gennadiy Vikentiy via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> I'm new to Clang LibTooling. I am using `RecursiveASTVisitor` to
> traverse the AST in post-order (i.e. with `shouldTraversePostOrder()`
> returning true). I am finding that one particular `Visit` function,
> `VisitUnaryOperator` is called twice (other `Visit` functions seem to
> be fine). In pre-order traversal, it is called once as expected. I'm
> using the latest svn Clang. Am I missing something?

Does this fix it?

diff --git a/include/clang/AST/RecursiveASTVisitor.h
b/include/clang/AST/RecursiveASTVisitor.h
index 99f46c7..6b4d998d 100644
--- a/include/clang/AST/RecursiveASTVisitor.h
+++ b/include/clang/AST/RecursiveASTVisitor.h
@@ -357,7 +357,8 @@ public:
 #define OPERATOR(NAME)
         \
   bool TraverseUnary##NAME(UnaryOperator *S,
         \
                            DataRecursionQueue *Queue = nullptr) {
         \
-    TRY_TO(WalkUpFromUnary##NAME(S));
         \
+    if (!getDerived().shouldTraversePostOrder())
         \
+      TRY_TO(WalkUpFromUnary##NAME(S));
         \
     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr());
         \
     return true;
         \
   }
         \


-- 
Malcolm Parsons



More information about the cfe-dev mailing list