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 | bf7607ab49f381e462c553abe1ad089b67351534 (patch) | |
tree | 5a612e961ed8cf40156b46c8d993e0290a9547ac /unittests/ASTMatchers | |
parent | 71bd6fc3cc738663bfa8888cec4be678a8a75dc6 (diff) | |
download | clang-bf7607ab49f381e462c553abe1ad089b67351534.tar.gz clang-bf7607ab49f381e462c553abe1ad089b67351534.tar.bz2 clang-bf7607ab49f381e462c553abe1ad089b67351534.tar.xz |
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210902 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ASTMatchers')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 03acfe3060..d247fac29f 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/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"))); } |