diff options
author | Samuel Benzaquen <sbenza@google.com> | 2014-06-13 13:31:40 +0000 |
---|---|---|
committer | Samuel Benzaquen <sbenza@google.com> | 2014-06-13 13:31:40 +0000 |
commit | 3ca0a7b4044440cc1755b3e4011d43eaf428ef77 (patch) | |
tree | 2c09a4771053a30f2ea41588e8ab3febd85227ae /clang/unittests/ASTMatchers/ASTMatchersTest.cpp | |
parent | ed5f645bf3a37887d765e98804a7a89da89f631f (diff) | |
download | bcm5719-llvm-3ca0a7b4044440cc1755b3e4011d43eaf428ef77.tar.gz bcm5719-llvm-3ca0a7b4044440cc1755b3e4011d43eaf428ef77.zip |
Do not store duplicate parents when memoization data is available.
Summary:
Do not store duplicate parents when memoization data is available.
This does not solve the duplication problem, but ameliorates it.
Reviewers: klimek
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D4124
llvm-svn: 210902
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 03acfe3060c..d247fac29f1 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -3623,6 +3623,27 @@ TEST(HasParent, MatchesAllParents) { compoundStmt(hasParent(recordDecl())))); } +TEST(HasParent, NoDuplicateParents) { + class HasDuplicateParents : public BoundNodesCallback { + public: + bool run(const BoundNodes *Nodes) override { return false; } + bool run(const BoundNodes *Nodes, ASTContext *Context) override { + const Stmt *Node = Nodes->getNodeAs<Stmt>("node"); + std::set<const void *> Parents; + for (const auto &Parent : Context->getParents(*Node)) { + if (!Parents.insert(Parent.getMemoizationData()).second) { + return true; + } + } + return false; + } + }; + EXPECT_FALSE(matchAndVerifyResultTrue( + "template <typename T> int Foo() { return 1 + 2; }\n" + "int x = Foo<int>() + Foo<unsigned>();", + stmt().bind("node"), new HasDuplicateParents())); +} + TEST(TypeMatching, MatchesTypes) { EXPECT_TRUE(matches("struct S {};", qualType().bind("loc"))); } |