diff options
author | Daniel Jasper <djasper@google.com> | 2012-11-11 22:14:55 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2012-11-11 22:14:55 +0000 |
commit | 33806cdefcffb091515bc329158d8c05714aa01a (patch) | |
tree | c6e61cc59a7223c299e05c11f30a32d6fe125c3b /clang/lib/ASTMatchers/ASTMatchersInternal.cpp | |
parent | 07351f8e78b415907342591a5a067e9efcd837e4 (diff) | |
download | bcm5719-llvm-33806cdefcffb091515bc329158d8c05714aa01a.tar.gz bcm5719-llvm-33806cdefcffb091515bc329158d8c05714aa01a.zip |
Fix binding of nodes in case of forEach..() matchers.
When recursively visiting the generated matches, the aggregated bindings need
to be copied during the recursion. Otherwise, we they might not be properly
overwritten (which is shown by the test), or there might be bound nodes present
that were bound on a different matching branch.
Review: http://llvm-reviews.chandlerc.com/D112
llvm-svn: 167695
Diffstat (limited to 'clang/lib/ASTMatchers/ASTMatchersInternal.cpp')
-rw-r--r-- | clang/lib/ASTMatchers/ASTMatchersInternal.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp index e7ee8ee7ed3..408195d3690 100644 --- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp +++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -51,19 +51,20 @@ void BoundNodesTree::copyTo(BoundNodesTreeBuilder* Builder) const { void BoundNodesTree::visitMatches(Visitor* ResultVisitor) { BoundNodesMap AggregatedBindings; - visitMatchesRecursively(ResultVisitor, &AggregatedBindings); + visitMatchesRecursively(ResultVisitor, AggregatedBindings); } void BoundNodesTree:: visitMatchesRecursively(Visitor* ResultVisitor, - BoundNodesMap* AggregatedBindings) { - Bindings.copyTo(AggregatedBindings); + const BoundNodesMap& AggregatedBindings) { + BoundNodesMap CombinedBindings(AggregatedBindings); + Bindings.copyTo(&CombinedBindings); if (RecursiveBindings.empty()) { - ResultVisitor->visitMatch(BoundNodes(*AggregatedBindings)); + ResultVisitor->visitMatch(BoundNodes(CombinedBindings)); } else { for (unsigned I = 0; I < RecursiveBindings.size(); ++I) { RecursiveBindings[I].visitMatchesRecursively(ResultVisitor, - AggregatedBindings); + CombinedBindings); } } } |