]> granicus.if.org Git - clang/commitdiff
[RecursiveASTVisitor] Introduce dataTraverseStmtPre()/dataTraverseStmtPost() to allow...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 13 Feb 2016 01:24:19 +0000 (01:24 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 13 Feb 2016 01:24:19 +0000 (01:24 +0000)
This should fix the asan bot that hits stack overflow in a couple of test/Index tests.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260785 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/RecursiveASTVisitor.h
lib/Index/IndexBody.cpp

index 1e397ae58ebd2107bab305173fe38c4e820b7a40..442882adc0bda89ffa5a9bbc05d06f5c354b515a 100644 (file)
@@ -163,6 +163,18 @@ public:
   /// otherwise (including when the argument is nullptr).
   bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue = nullptr);
 
+  /// Invoked before visiting a statement or expression via data recursion.
+  ///
+  /// \returns false to skip visiting the node, true otherwise.
+  bool dataTraverseStmtPre(Stmt *S) { return true; }
+
+  /// Invoked after visiting a statement or expression via data recursion.
+  /// This is not invoked if the previously invoked \c dataTraverseStmtPre
+  /// returned false.
+  ///
+  /// \returns false if the visitation was terminated early, true otherwise.
+  bool dataTraverseStmtPost(Stmt *S) { return true; }
+
   /// \brief Recursively visit a type, by dispatching to
   /// Traverse*Type() based on the argument's getTypeClass() property.
   ///
@@ -557,7 +569,10 @@ bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S,
     Stmt *CurrS = LocalQueue.pop_back_val();
 
     size_t N = LocalQueue.size();
-    TRY_TO(dataTraverseNode(CurrS, &LocalQueue));
+    if (getDerived().dataTraverseStmtPre(CurrS)) {
+      TRY_TO(dataTraverseNode(CurrS, &LocalQueue));
+      TRY_TO(dataTraverseStmtPost(CurrS));
+    }
     // Process new children in the order they were added.
     std::reverse(LocalQueue.begin() + N, LocalQueue.end());
   }
index 56fba28387d0fdd86a5bb2f86dd6657952d96100..f7164453db6a07cfc87fba094b6771a3960668a2 100644 (file)
@@ -29,11 +29,15 @@ public:
   
   bool shouldWalkTypesOfTypeLocs() const { return false; }
 
-  bool TraverseStmt(Stmt *S) {
+  bool dataTraverseStmtPre(Stmt *S) {
     StmtStack.push_back(S);
-    bool ret = base::TraverseStmt(S);
+    return true;
+  }
+
+  bool dataTraverseStmtPost(Stmt *S) {
+    assert(StmtStack.back() == S);
     StmtStack.pop_back();
-    return ret;
+    return true;
   }
 
   bool TraverseTypeLoc(TypeLoc TL) {