diff options
| author | Samuel Benzaquen <sbenza@google.com> | 2014-10-13 17:38:12 +0000 |
|---|---|---|
| committer | Samuel Benzaquen <sbenza@google.com> | 2014-10-13 17:38:12 +0000 |
| commit | 2009960ea33759a1848ade83640896db27a7382b (patch) | |
| tree | 223524dd02482725480875efa68226a3ccf00081 /clang/lib | |
| parent | 1ee5ac87e2bc14a7c04fdb735d69d445b3b7f24d (diff) | |
| download | bcm5719-llvm-2009960ea33759a1848ade83640896db27a7382b.tar.gz bcm5719-llvm-2009960ea33759a1848ade83640896db27a7382b.zip | |
Fix bug in DynTypedMatcher::constructVariadic() that would cause false negatives.
Summary:
Change r219118 fixed the bug for anyOf and eachOf, but it is still
present for unless.
The variadic wrapper doesn't have enough information to know how to
restrict the type. Different operators handle restrict failures in
different ways.
Reviewers: klimek
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D5731
llvm-svn: 219622
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/ASTMatchers/ASTMatchersInternal.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp index f6fd5ba2a3f..c8e5852475c 100644 --- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp +++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -89,18 +89,19 @@ static llvm::ManagedStatic<TrueMatcherImpl> TrueMatcherInstance; DynTypedMatcher DynTypedMatcher::constructVariadic( VariadicOperatorFunction Func, std::vector<DynTypedMatcher> InnerMatchers) { assert(InnerMatchers.size() > 0 && "Array must not be empty."); - DynTypedMatcher Result = InnerMatchers[0]; - // Use the least derived type as the restriction for the wrapper. - // This allows mismatches to be resolved on the inner matchers. - for (const DynTypedMatcher &M : InnerMatchers) { - assert(Result.SupportedKind.isSame(M.SupportedKind) && - "SupportedKind must match!"); - Result.RestrictKind = - ast_type_traits::ASTNodeKind::getMostDerivedCommonAncestor( - Result.RestrictKind, M.RestrictKind); - } - Result.Implementation = new VariadicMatcher(Func, std::move(InnerMatchers)); - return Result; + assert(std::all_of(InnerMatchers.begin(), InnerMatchers.end(), + [&InnerMatchers](const DynTypedMatcher &M) { + return InnerMatchers[0].SupportedKind.isSame(M.SupportedKind); + }) && + "SupportedKind must match!"); + + // We must relax the restrict kind here. + // The different operators might deal differently with a mismatch. + // Make it the same as SupportedKind, since that is the broadest type we are + // allowed to accept. + return DynTypedMatcher(InnerMatchers[0].SupportedKind, + InnerMatchers[0].SupportedKind, + new VariadicMatcher(Func, std::move(InnerMatchers))); } DynTypedMatcher DynTypedMatcher::trueMatcher( |

