summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorMalcolm Parsons <malcolm.parsons@gmail.com>2016-12-07 17:39:04 +0000
committerMalcolm Parsons <malcolm.parsons@gmail.com>2016-12-07 17:39:04 +0000
commitb2b0cb7ca8b7df917a7c57eceb238152cea779d5 (patch)
tree91f254a5c41a1e4f2ff490a65e34979067a44f58 /clang
parentc894ac81634a89c91723b620693aea6b1df754ba (diff)
downloadbcm5719-llvm-b2b0cb7ca8b7df917a7c57eceb238152cea779d5.tar.gz
bcm5719-llvm-b2b0cb7ca8b7df917a7c57eceb238152cea779d5.zip
[RecursiveASTVisitor] Fix post-order traversal of UnaryOperator
Reviewers: aaron.ballman, klimek, doug.gregor, teemperor, rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D26742 llvm-svn: 288923
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/RecursiveASTVisitor.h3
-rw-r--r--clang/unittests/AST/PostOrderASTVisitor.cpp9
2 files changed, 9 insertions, 3 deletions
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h
index d08d47744ae..d3a651643a2 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/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; \
} \
diff --git a/clang/unittests/AST/PostOrderASTVisitor.cpp b/clang/unittests/AST/PostOrderASTVisitor.cpp
index 012f63a48ad..ee17f14bd10 100644
--- a/clang/unittests/AST/PostOrderASTVisitor.cpp
+++ b/clang/unittests/AST/PostOrderASTVisitor.cpp
@@ -34,6 +34,11 @@ namespace {
bool shouldTraversePostOrder() const { return VisitPostOrder; }
+ bool VisitUnaryOperator(UnaryOperator *Op) {
+ VisitedNodes.push_back(Op->getOpcodeStr(Op->getOpcode()));
+ return true;
+ }
+
bool VisitBinaryOperator(BinaryOperator *Op) {
VisitedNodes.push_back(Op->getOpcodeStr());
return true;
@@ -76,7 +81,7 @@ TEST(RecursiveASTVisitor, PostOrderTraversal) {
auto ASTUnit = tooling::buildASTFromCode(
"class A {"
" class B {"
- " int foo() { while(4) { int i = 9; } return (1 + 3) + 2; }"
+ " int foo() { while(4) { int i = 9; int j = -i; } return (1 + 3) + 2; }"
" };"
"};"
);
@@ -87,7 +92,7 @@ TEST(RecursiveASTVisitor, PostOrderTraversal) {
Visitor.TraverseTranslationUnitDecl(TU);
std::vector<std::string> expected = {
- "4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A"
+ "4", "9", "i", "-", "j", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A"
};
// Compare the list of actually visited nodes
// with the expected list of visited nodes.
OpenPOWER on IntegriCloud