r260785 - [RecursiveASTVisitor] Introduce dataTraverseStmtPre()/dataTraverseStmtPost() to allow clients to do before/after actions during data recursive visitation.
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 12 17:24:20 PST 2016
Author: akirtzidis
Date: Fri Feb 12 19:24:19 2016
New Revision: 260785
URL: http://llvm.org/viewvc/llvm-project?rev=260785&view=rev
Log:
[RecursiveASTVisitor] Introduce dataTraverseStmtPre()/dataTraverseStmtPost() to allow clients to do before/after actions during data recursive visitation.
This should fix the asan bot that hits stack overflow in a couple of test/Index tests.
Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/lib/Index/IndexBody.cpp
Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=260785&r1=260784&r2=260785&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Fri Feb 12 19:24:19 2016
@@ -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>::Trave
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());
}
Modified: cfe/trunk/lib/Index/IndexBody.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexBody.cpp?rev=260785&r1=260784&r2=260785&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexBody.cpp (original)
+++ cfe/trunk/lib/Index/IndexBody.cpp Fri Feb 12 19:24:19 2016
@@ -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) {
More information about the cfe-commits
mailing list