From 1b654f2293f7859676edc6b06156de84c32f482a Mon Sep 17 00:00:00 2001 From: Gabor Horvath Date: Wed, 30 Mar 2016 11:22:14 +0000 Subject: [PATCH] [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 --- clang/docs/LibASTMatchersReference.html | 10 ---------- clang/docs/ReleaseNotes.rst | 6 ++++++ clang/include/clang/ASTMatchers/ASTMatchers.h | 7 +------ clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 7 ++++++- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index 58ab6d12850f..aaddb5b840bd 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -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. @@ -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. diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 922c37e6f049..942e12eed1cd 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -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()`` must be changed to + ``hasAnyArgument(ignoringParenImpCasts())``. + ... libclang diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index b727ff897bd2..04d6938a2d9e 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -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, 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; } diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index fc983737f4ac..a34617935799 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -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) {