]> granicus.if.org Git - clang/commitdiff
[ASTMatchers] Existing matcher hasAnyArgument fixed
authorGabor Horvath <xazax.hun@gmail.com>
Wed, 30 Mar 2016 11:22:14 +0000 (11:22 +0000)
committerGabor Horvath <xazax.hun@gmail.com>
Wed, 30 Mar 2016 11:22:14 +0000 (11:22 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264855 91177308-0d34-0410-b5e6-96231b3b80d8

docs/LibASTMatchersReference.html
docs/ReleaseNotes.rst
include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersTest.cpp

index 58ab6d12850fd70f2ddbf5ef7f2b5658a35049b8..aaddb5b840bdd0806e3a6b80453a3e9029d85a3e 100644 (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>
 
 
index 922c37e6f0494b4e6de182ed71fa55fca390d4dc..942e12eed1cd8b9befbb55d50bdd323646a81f1d 100644 (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
index b727ff897bd24468c6fdf92ff8dfedffb886dd20..04d6938a2d9e8b89c8bdb4443c5ecc467e7b8374 100644 (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;
     }
index fc983737f4acdaa5fe7f44ed2f65e1348d9ace9f..a34617935799a2968d556dbef3c0f7c5c6b98221 100644 (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) {