-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add ignoring paren imp casts in has any argument #89509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add ignoring paren imp casts in has any argument #89509
Conversation
…ignoringParenImpCasts-in-hasAnyArgument
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: None (komalverma04) ChangesMaintaining Consistency in
|
@PiotrZSL Please guide me tackling the failing tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started taking a look at this and realized you switched up which argument matcher needs the extra ignoringParenImpCasts
, so that it can be removed from the matcher definition (possibly in a different pr).
See
llvm-project/clang/include/clang/ASTMatchers/ASTMatchers.h
Lines 4891 to 4907 in d674f45
AST_POLYMORPHIC_MATCHER_P(hasAnyArgument, | |
AST_POLYMORPHIC_SUPPORTED_TYPES( | |
CallExpr, CXXConstructExpr, | |
CXXUnresolvedConstructExpr, ObjCMessageExpr), | |
internal::Matcher<Expr>, InnerMatcher) { | |
for (const Expr *Arg : Node.arguments()) { | |
if (Finder->isTraversalIgnoringImplicitNodes() && | |
isa<CXXDefaultArgExpr>(Arg)) | |
break; | |
BoundNodesTreeBuilder Result(*Builder); | |
if (InnerMatcher.matches(*Arg, Finder, &Result)) { | |
*Builder = std::move(Result); | |
return true; | |
} | |
} | |
return false; | |
} |
vs
llvm-project/clang/include/clang/ASTMatchers/ASTMatchers.h
Lines 4553 to 4564 in d674f45
AST_POLYMORPHIC_MATCHER_P2(hasArgument, | |
AST_POLYMORPHIC_SUPPORTED_TYPES( | |
CallExpr, CXXConstructExpr, | |
CXXUnresolvedConstructExpr, ObjCMessageExpr), | |
unsigned, N, internal::Matcher<Expr>, InnerMatcher) { | |
if (N >= Node.getNumArgs()) | |
return false; | |
const Expr *Arg = Node.getArg(N); | |
if (Finder->isTraversalIgnoringImplicitNodes() && isa<CXXDefaultArgExpr>(Arg)) | |
return false; | |
return InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, Builder); | |
} |
IgnoreParenImpCasts()
inside the hasArgument
matcher, because that is not it's job. So we want to a) add ignoringParenImpCasts
to arguments of the hasArgument
matcher, and b) remove the call to IgnoreParenImpCasts
from the hasArgument
matcher.See this comment from the original issue: #75754 (comment)
This is also the reason why the tests are failing, you are actually changing the behavior of these checks.
hasAnyArgument( | ||
/* `hasArgument` would skip over parens */ ignoringParenImpCasts( | ||
anyOf(NullLiteral, NullInitList, EmptyInitList))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checkout this file later for this and the other section I highlighted, here it looks like the only reason that hasAnyArgument
was chosen is because of this differing behavior, instead, this can be replaced with hasArgument(0, ...)
after the IgnoreParenImpCasts
is removed from the hasArgument
matcher.
hasAnyArgument( | ||
/* `hasArgument` would skip over parens */ ignoringParenImpCasts( | ||
anyOf(NullLiteral, NullInitList, EmptyInitList))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
Maintaining Consistency in
hasAnyArgument()
andhasArgument()
Matchers in Clang AST MatchersThe
hasArgument()
matcher already ignores implicit casts and parentheses, but thehasAnyArgument()
matcher does not. To ensure consistency, we need to explicitly useignoringParenImpCasts()
to handle cases where there might be implicit casts or parentheses around the argument in the Clang AST match.The code changes made are as follows:
This change ensures that any implicit casts and parentheses around the argument type S * are ignored.
Fixes #75754