diff options
author | Manuel Klimek <klimek@google.com> | 2013-07-08 14:16:30 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-07-08 14:16:30 +0000 |
commit | 7e3d9698fd425200f19410d4302eca5b4e821b9c (patch) | |
tree | 4f1984500a45112be5ad214a2518c89262d12fbe | |
parent | 8b4ccc0645f0be49b6f643d1ca370f2bad4caaa4 (diff) | |
download | bcm5719-llvm-7e3d9698fd425200f19410d4302eca5b4e821b9c.tar.gz bcm5719-llvm-7e3d9698fd425200f19410d4302eca5b4e821b9c.zip |
Fix use of invalidated iterator bug in AST match finder.
Pulled out the cache clearing in the case of descendant matching, too,
for consistency, also it is not technically needed there.
FIXME: Make cache size configurable and add unit test.
llvm-svn: 185820
-rw-r--r-- | clang/lib/ASTMatchers/ASTMatchFinder.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp index a68c7fdffe1..e1e5f44c07b 100644 --- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp @@ -384,8 +384,6 @@ public: return matchesRecursively(Node, Matcher, Builder, MaxDepth, Traversal, Bind); - if (ResultCache.size() > MaxMemoizationEntries) - ResultCache.clear(); std::pair<MemoizationMap::iterator, bool> InsertResult = ResultCache.insert(std::make_pair(Key, MemoizedMatchResult())); if (InsertResult.second) { @@ -426,6 +424,8 @@ public: const DynTypedMatcher &Matcher, BoundNodesTreeBuilder *Builder, BindKind Bind) { + if (ResultCache.size() > MaxMemoizationEntries) + ResultCache.clear(); return memoizedMatchesRecursively(Node, Matcher, Builder, INT_MAX, TK_AsIs, Bind); } @@ -434,6 +434,10 @@ public: const DynTypedMatcher &Matcher, BoundNodesTreeBuilder *Builder, AncestorMatchMode MatchMode) { + // Reset the cache outside of the recursive call to make sure we + // don't invalidate any iterators. + if (ResultCache.size() > MaxMemoizationEntries) + ResultCache.clear(); return memoizedMatchesAncestorOfRecursively(Node, Matcher, Builder, MatchMode); } @@ -498,8 +502,6 @@ private: Key.MatcherID = Matcher.getID(); Key.Node = Node; Key.BoundNodes = *Builder; - if (ResultCache.size() > MaxMemoizationEntries) - ResultCache.clear(); std::pair<MemoizationMap::iterator, bool> InsertResult = ResultCache.insert(std::make_pair(Key, MemoizedMatchResult())); if (InsertResult.second) { |