[ASTMatchers] Existing matcher hasAnyArgument fixed

Summary: A checker (will be uploaded after this patch) needs to check implicit casts. The checker needs matcher hasAnyArgument but it ignores implicit casts and parenthesized expressions which disables checking of implicit casts for arguments in the checker. However the documentation of the matcher contains a FIXME that this should be removed once separate matchers for ignoring implicit casts and parenthesized expressions are ready. Since these matchers were already there the fix could be executed. Only one Clang checker was affected which was also fixed (ignoreParenImpCasts added) and is separately uploaded. Third party checkers (not in the Clang repository) may be affected by this fix so the fix must be emphasized in the release notes.

Reviewers: klimek, sbenza, alexfh

Subscribers: alexfh, klimek, xazax.hun, cfe-commits

Differential Revision: http://reviews.llvm.org/D18243

llvm-svn: 264855
This commit is contained in:
Gabor Horvath 2016-03-30 11:22:14 +00:00
parent 058c302e0a
commit 1b654f2293
4 changed files with 13 additions and 17 deletions

View File

@ -3636,11 +3636,6 @@ callExpr(hasAnyArgument(declRefExpr()))
matches x(1, y, 42)
with hasAnyArgument(...)
matching y
FIXME: Currently this will ignore parentheses and implicit casts on
the argument before applying the inner matcher. We'll want to remove
this to allow for greater control by the user once ignoreImplicit()
has been implemented.
</pre></td></tr>
@ -3907,11 +3902,6 @@ callExpr(hasAnyArgument(declRefExpr()))
matches x(1, y, 42)
with hasAnyArgument(...)
matching y
FIXME: Currently this will ignore parentheses and implicit casts on
the argument before applying the inner matcher. We'll want to remove
this to allow for greater control by the user once ignoreImplicit()
has been implemented.
</pre></td></tr>

View File

@ -120,6 +120,12 @@ this section should help get you past the largest hurdles of upgrading.
AST Matchers
------------
- hasAnyArgument: Matcher no longer ignores parentheses and implicit casts on
the argument before applying the inner matcher. The fix was done to allow for
greater control by the user. In all existing checkers that use this matcher
all instances of code ``hasAnyArgument(<inner matcher>)`` must be changed to
``hasAnyArgument(ignoringParenImpCasts(<inner matcher>))``.
...
libclang

View File

@ -2989,18 +2989,13 @@ AST_MATCHER(CXXCtorInitializer, isMemberInitializer) {
/// matches x(1, y, 42)
/// with hasAnyArgument(...)
/// matching y
///
/// FIXME: Currently this will ignore parentheses and implicit casts on
/// the argument before applying the inner matcher. We'll want to remove
/// this to allow for greater control by the user once \c ignoreImplicit()
/// has been implemented.
AST_POLYMORPHIC_MATCHER_P(hasAnyArgument,
AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,
CXXConstructExpr),
internal::Matcher<Expr>, InnerMatcher) {
for (const Expr *Arg : Node.arguments()) {
BoundNodesTreeBuilder Result(*Builder);
if (InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, &Result)) {
if (InnerMatcher.matches(*Arg, Finder, &Result)) {
*Builder = std::move(Result);
return true;
}

View File

@ -1633,10 +1633,15 @@ TEST(Matcher, Argument) {
TEST(Matcher, AnyArgument) {
StatementMatcher CallArgumentY = callExpr(
hasAnyArgument(declRefExpr(to(varDecl(hasName("y"))))));
hasAnyArgument(
ignoringParenImpCasts(declRefExpr(to(varDecl(hasName("y")))))));
EXPECT_TRUE(matches("void x(int, int) { int y; x(1, y); }", CallArgumentY));
EXPECT_TRUE(matches("void x(int, int) { int y; x(y, 42); }", CallArgumentY));
EXPECT_TRUE(notMatches("void x(int, int) { x(1, 2); }", CallArgumentY));
StatementMatcher ImplicitCastedArgument = callExpr(
hasAnyArgument(implicitCastExpr()));
EXPECT_TRUE(matches("void x(long) { int y; x(y); }", ImplicitCastedArgument));
}
TEST(ForEachArgumentWithParam, ReportsNoFalsePositives) {