steveire created this revision.
steveire added a reviewer: aaron.ballman.
Herald added subscribers: kbarton, xazax.hun, nemanjai.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D94131
Files:
clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
Index: clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
===================================================================
--- clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -66,10 +66,10 @@
substTemplateTypeParmType(hasReplacementType(ConstReferenceOrValue))));
auto UsedAsConstRefOrValueArg = forEachArgumentWithParam(
DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValueOrReplaced)));
- Matches = match(findAll(callExpr(UsedAsConstRefOrValueArg)), Stmt, Context);
- extractNodesByIdTo(Matches, "declRef", DeclRefs);
- Matches =
- match(findAll(cxxConstructExpr(UsedAsConstRefOrValueArg)), Stmt, Context);
+ Matches = match(
+ findAll(
+ mapAnyOf(callExpr, cxxConstructExpr).with(UsedAsConstRefOrValueArg)),
+ Stmt, Context);
extractNodesByIdTo(Matches, "declRef", DeclRefs);
// References and pointers to const assignments.
Matches =
Index: clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
@@ -37,11 +37,10 @@
has(compoundStmt(hasAnySubstatement(returnStmt(unless(has(expr())))))
.bind("return"))),
this);
- auto CompoundContinue =
- has(compoundStmt(hasAnySubstatement(continueStmt())).bind("continue"));
Finder->addMatcher(
- stmt(anyOf(forStmt(), cxxForRangeStmt(), whileStmt(), doStmt()),
- CompoundContinue),
+ mapAnyOf(forStmt, cxxForRangeStmt, whileStmt, doStmt)
+ .with(hasBody(compoundStmt(hasAnySubstatement(continueStmt()))
+ .bind("continue"))),
this);
}
Index: clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -56,28 +56,26 @@
const char *ExprName = "__booleanContextExpr";
auto Result =
expr(expr().bind(ExprName),
- anyOf(hasParent(varDecl(hasType(booleanType()))),
+ anyOf(hasParent(
+ mapAnyOf(varDecl, fieldDecl).with(hasType(booleanType()))),
hasParent(cxxConstructorDecl(
hasAnyConstructorInitializer(cxxCtorInitializer(
withInitializer(expr(equalsBoundNode(ExprName))),
forField(hasType(booleanType())))))),
- hasParent(fieldDecl(hasType(booleanType()))),
hasParent(stmt(anyOf(
explicitCastExpr(hasDestinationType(booleanType())),
- ifStmt(hasCondition(expr(equalsBoundNode(ExprName)))),
- doStmt(hasCondition(expr(equalsBoundNode(ExprName)))),
- whileStmt(hasCondition(expr(equalsBoundNode(ExprName)))),
- forStmt(hasCondition(expr(equalsBoundNode(ExprName)))),
- conditionalOperator(
- hasCondition(expr(equalsBoundNode(ExprName)))),
+ mapAnyOf(ifStmt, doStmt, whileStmt, forStmt,
+ conditionalOperator)
+ .with(hasCondition(expr(equalsBoundNode(ExprName)))),
parenListExpr(hasParent(varDecl(hasType(booleanType())))),
parenExpr(hasParent(
explicitCastExpr(hasDestinationType(booleanType())))),
returnStmt(forFunction(returns(booleanType()))),
cxxUnresolvedConstructExpr(hasType(booleanType())),
- callExpr(hasAnyArgumentWithParam(
- expr(equalsBoundNode(ExprName)),
- parmVarDecl(hasType(booleanType())))),
+ mapAnyOf(callExpr, cxxConstructExpr)
+ .with(hasAnyArgumentWithParam(
+ expr(equalsBoundNode(ExprName)),
+ parmVarDecl(hasType(booleanType())))),
binaryOperator(hasAnyOperatorName("&&", "||")),
unaryOperator(hasOperatorName("!")).bind("NegOnSize"))))))
.matches(Node, Finder, Builder);
@@ -181,21 +179,12 @@
expr(hasType(pointsTo(ValidContainer))).bind("Pointee"))),
expr(hasType(ValidContainer)).bind("STLObject"));
Finder->addMatcher(
- cxxOperatorCallExpr(
- unless(isInTemplateInstantiation()),
- hasAnyOverloadedOperatorName("==", "!="),
- anyOf(allOf(hasArgument(0, WrongComparend), hasArgument(1, STLArg)),
- allOf(hasArgument(0, STLArg), hasArgument(1, WrongComparend))),
- unless(hasAncestor(
- cxxMethodDecl(ofClass(equalsBoundNode("container"))))))
- .bind("BinCmp"),
- this);
- Finder->addMatcher(
- binaryOperator(hasAnyOperatorName("==", "!="),
- anyOf(allOf(hasLHS(WrongComparend), hasRHS(STLArg)),
- allOf(hasLHS(STLArg), hasRHS(WrongComparend))),
- unless(hasAncestor(
- cxxMethodDecl(ofClass(equalsBoundNode("container"))))))
+ binaryOperation(unless(isInTemplateInstantiation()),
+ hasAnyOperatorName("==", "!="),
+ hasOperands(ignoringParenImpCasts(WrongComparend),
+ ignoringParenImpCasts(STLArg))
+ unless(hasAncestor(cxxMethodDecl(
+ ofClass(equalsBoundNode("container"))))))
.bind("BinCmp"),
this);
}
Index: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
@@ -50,11 +50,10 @@
auto ConstParamMatcher = forEachArgumentWithParam(
MoveCallMatcher, parmVarDecl(hasType(references(isConstQualified()))));
- Finder->addMatcher(callExpr(ConstParamMatcher).bind("receiving-expr"), this);
- Finder->addMatcher(
- traverse(TK_AsIs,
- cxxConstructExpr(ConstParamMatcher).bind("receiving-expr")),
- this);
+ Finder->addMatcher(mapAnyOf(callExpr, cxxConstructExpr)
+ .with(ConstParamMatcher)
+ .bind("receiving-expr"),
+ this);
}
void MoveConstArgCheck::check(const MatchFinder::MatchResult &Result) {
Index: clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
@@ -183,15 +183,10 @@
auto LHS = memberExpr(hasObjectExpression(cxxThisExpr()),
member(fieldDecl(equalsNode(Field))));
auto RHS = accessToFieldInVar(Field, Param);
- if (match(
- traverse(TK_AsIs,
- compoundStmt(has(ignoringParenImpCasts(stmt(anyOf(
- binaryOperator(hasOperatorName("="), hasLHS(LHS),
- hasRHS(RHS)),
- cxxOperatorCallExpr(
- hasOverloadedOperatorName("="), argumentCountIs(2),
- hasArgument(0, LHS), hasArgument(1, RHS)))))))),
- *Compound, *Context)
+ if (match(traverse(TK_AsIs,
+ compoundStmt(has(ignoringParenImpCasts(binaryOperation(
+ hasOperatorName("="), hasLHS(LHS), hasRHS(RHS)))))),
+ *Compound, *Context)
.empty())
return false;
}
Index: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -187,11 +187,6 @@
StatementMatcher IteratorComparisonMatcher = expr(
ignoringParenImpCasts(declRefExpr(to(varDecl().bind(ConditionVarName)))));
- auto OverloadedNEQMatcher = ignoringImplicit(
- cxxOperatorCallExpr(hasOverloadedOperatorName("!="), argumentCountIs(2),
- hasArgument(0, IteratorComparisonMatcher),
- hasArgument(1, IteratorBoundMatcher)));
-
// This matcher tests that a declaration is a CXXRecordDecl that has an
// overloaded operator*(). If the operator*() returns by value instead of by
// reference then the return type is tagged with DerefByValueResultName.
@@ -215,14 +210,9 @@
containsDeclaration(0, InitDeclMatcher),
containsDeclaration(1, EndDeclMatcher)),
declStmt(hasSingleDecl(InitDeclMatcher)))),
- hasCondition(
- anyOf(binaryOperator(hasOperatorName("!="),
- hasLHS(IteratorComparisonMatcher),
- hasRHS(IteratorBoundMatcher)),
- binaryOperator(hasOperatorName("!="),
- hasLHS(IteratorBoundMatcher),
- hasRHS(IteratorComparisonMatcher)),
- OverloadedNEQMatcher)),
+ hasCondition(ignoringImplicit(binaryOperation(
+ hasOperatorName("!="), hasOperands(IteratorComparisonMatcher,
+ IteratorBoundMatcher)))),
hasIncrement(anyOf(
unaryOperator(hasOperatorName("++"),
hasUnaryOperand(declRefExpr(
Index: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -597,6 +597,7 @@
hasOperatorName("!"),
hasUnaryOperand(anyOf(CastExpr, RelationalExpr)))));
+ // Currently no equivalent for binaryOperator?
const auto OverloadedOperatorExpr =
cxxOperatorCallExpr(
hasAnyOverloadedOperatorName("==", "!=", "<", "<=", ">", ">="),
@@ -854,6 +855,7 @@
// Logical or bitwise operator with equivalent nested operands, like (X && Y
// && X) or (X && (Y && X))
Finder->addMatcher(
+ // Different operators to below
binaryOperator(hasAnyOperatorName("|", "&", "||", "&&", "^"),
nestedOperandsAreEquivalent(),
// Filter noisy false positives.
@@ -889,6 +891,7 @@
// Overloaded operators with equivalent operands.
Finder->addMatcher(
+ // Merge with above
cxxOperatorCallExpr(
hasAnyOverloadedOperatorName("|", "&", "||", "&&", "^"),
nestedParametersAreEquivalent(), argumentCountIs(2),
Index: clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
+++ clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
@@ -47,8 +47,9 @@
allOf(callee(namedDecl(hasAnyName("isa", "cast", "cast_or_null",
"dyn_cast", "dyn_cast_or_null"))
.bind("func")),
- hasArgument(0, anyOf(declRefExpr().bind("arg"),
- cxxMemberCallExpr().bind("arg"))))))
+ hasArgument(
+ 0,
+ mapAnyOf(declRefExpr, cxxMemberCallExpr).bind("arg")))))
.bind("rhs");
Finder->addMatcher(
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
@@ -29,10 +29,8 @@
// Check if the 'goto' is used for control flow other than jumping
// out of a nested loop.
- auto Loop = stmt(anyOf(forStmt(), cxxForRangeStmt(), whileStmt(), doStmt()));
- auto NestedLoop =
- stmt(anyOf(forStmt(hasAncestor(Loop)), cxxForRangeStmt(hasAncestor(Loop)),
- whileStmt(hasAncestor(Loop)), doStmt(hasAncestor(Loop))));
+ auto Loop = mapAnyOf(forStmt, cxxForRangeStmt, whileStmt, doStmt);
+ auto NestedLoop = Loop.with(hasAncestor(Loop.with(anything())));
Finder->addMatcher(gotoStmt(anyOf(unless(hasAncestor(NestedLoop)),
unless(isForwardJumping())))
Index: clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp
+++ clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp
@@ -30,12 +30,8 @@
MemberExprOrSourceObject);
const auto IsSourceMutatingAssignment = traverse(
- TK_AsIs,
- expr(anyOf(binaryOperator(isAssignmentOperator(), hasLHS(IsPartOfSource))
- .bind(MutatingOperatorName),
- cxxOperatorCallExpr(isAssignmentOperator(),
- hasArgument(0, IsPartOfSource))
- .bind(MutatingOperatorName))));
+ TK_AsIs, binaryOperation(hasOperatorName("="), hasLHS(IsPartOfSource))
+ .bind(MutatingOperatorName));
const auto MemberExprOrSelf = anyOf(memberExpr(), cxxThisExpr());
@@ -43,9 +39,7 @@
unless(hasDescendant(expr(unless(MemberExprOrSelf)))), MemberExprOrSelf);
const auto IsSelfMutatingAssignment =
- expr(anyOf(binaryOperator(isAssignmentOperator(), hasLHS(IsPartOfSelf)),
- cxxOperatorCallExpr(isAssignmentOperator(),
- hasArgument(0, IsPartOfSelf))));
+ binaryOperation(isAssignmentOperator(), hasLHS(IsPartOfSelf));
const auto IsSelfMutatingMemberFunction =
functionDecl(hasBody(hasDescendant(IsSelfMutatingAssignment)));
Index: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -310,9 +310,7 @@
// Assignment. In addition to the overloaded assignment operator,
// test for built-in assignment as well, since template functions
// may be instantiated to use std::move() on built-in types.
- binaryOperator(hasOperatorName("="), hasLHS(DeclRefMatcher)),
- cxxOperatorCallExpr(hasOverloadedOperatorName("="),
- hasArgument(0, DeclRefMatcher)),
+ binaryOperation(hasOperatorName("="), hasLHS(DeclRefMatcher)),
// Declaration. We treat this as a type of reinitialization too,
// so we don't need to treat it separately.
declStmt(hasDescendant(equalsNode(MovedVariable))),
Index: clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
@@ -40,12 +40,10 @@
// Self-check: Code compares something with 'this' pointer. We don't check
// whether it is actually the parameter what we compare.
- const auto HasNoSelfCheck = cxxMethodDecl(unless(anyOf(
- hasDescendant(binaryOperator(hasAnyOperatorName("==", "!="),
- has(ignoringParenCasts(cxxThisExpr())))),
- hasDescendant(cxxOperatorCallExpr(
- hasAnyOverloadedOperatorName("==", "!="), argumentCountIs(2),
- has(ignoringParenCasts(cxxThisExpr())))))));
+ const auto HasNoSelfCheck = cxxMethodDecl(unless(hasDescendant(
+ mapAnyOf(binaryOperator, cxxOperatorCallExpr)
+ .with(hasAnyOperatorName("==", "!="),
+ hasEitherOperand(ignoringParenCasts(cxxThisExpr()))))));
// Both copy-and-swap and copy-and-move method creates a copy first and
// assign it to 'this' with swap or move.
Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
@@ -113,10 +113,8 @@
// Detect suspicious calls to string compare:
// 'if (strcmp())' -> 'if (strcmp() != 0)'
Finder->addMatcher(
- stmt(anyOf(ifStmt(hasCondition(StringCompareCallExpr)),
- whileStmt(hasCondition(StringCompareCallExpr)),
- doStmt(hasCondition(StringCompareCallExpr)),
- forStmt(hasCondition(StringCompareCallExpr)),
+ stmt(anyOf(mapAnyOf(ifStmt, whileStmt, doStmt, forStmt)
+ .with(hasCondition(StringCompareCallExpr)),
binaryOperator(hasAnyOperatorName("&&", "||"),
hasEitherOperand(StringCompareCallExpr))))
.bind("missing-comparison"),
Index: clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
@@ -59,34 +59,27 @@
if (getLangOpts().CPlusPlus) {
// Check for `CON54-CPP`
Finder->addMatcher(
- ifStmt(
-
- allOf(hasWaitDescendantCPP,
- unless(anyOf(hasDescendant(ifStmt(hasWaitDescendantCPP)),
- hasDescendant(whileStmt(hasWaitDescendantCPP)),
- hasDescendant(forStmt(hasWaitDescendantCPP)),
- hasDescendant(doStmt(hasWaitDescendantCPP)))))
-
- ),
+ ifStmt(allOf(
+ hasWaitDescendantCPP,
+ unless(hasDescendant(mapAnyOf(ifStmt, whileStmt, forStmt, doStmt)
+ .with(hasWaitDescendantCPP))))),
this);
} else {
// Check for `CON36-C`
Finder->addMatcher(
+ ifStmt(allOf(
+ hasWaitDescendantC,
+ unless(
+ anyOf(hasDescendant(mapAnyOf(ifStmt, whileStmt, forStmt, doStmt)
+ .with(hasWaitDescendantC)),
+ hasParent(whileStmt()),
+ hasParent(compoundStmt(hasParent(whileStmt()))),
+ hasParent(forStmt()),
+ hasParent(compoundStmt(hasParent(forStmt()))),
+ hasParent(doStmt()),
+ hasParent(compoundStmt(hasParent(doStmt())))))
- ifStmt(
- allOf(hasWaitDescendantC,
- unless(anyOf(hasDescendant(ifStmt(hasWaitDescendantC)),
- hasDescendant(whileStmt(hasWaitDescendantC)),
- hasDescendant(forStmt(hasWaitDescendantC)),
- hasDescendant(doStmt(hasWaitDescendantC)),
- hasParent(whileStmt()),
- hasParent(compoundStmt(hasParent(whileStmt()))),
- hasParent(forStmt()),
- hasParent(compoundStmt(hasParent(forStmt()))),
- hasParent(doStmt()),
- hasParent(compoundStmt(hasParent(doStmt())))))
-
- ))
+ ))
,
this);
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -21,9 +21,9 @@
static internal::Matcher<Stmt>
loopEndingStmt(internal::Matcher<Stmt> Internal) {
- return stmt(anyOf(breakStmt(Internal), returnStmt(Internal),
- gotoStmt(Internal), cxxThrowExpr(Internal),
- callExpr(Internal, callee(functionDecl(isNoReturn())))));
+ return stmt(anyOf(
+ mapAnyOf(breakStmt, returnStmt, gotoStmt, cxxThrowExpr).with(Internal),
+ callExpr(Internal, callee(functionDecl(isNoReturn())))));
}
/// Return whether `Var` was changed in `LoopStmt`.
@@ -122,8 +122,8 @@
unless(hasBody(hasDescendant(
loopEndingStmt(forFunction(equalsBoundNode("func")))))));
- Finder->addMatcher(stmt(anyOf(whileStmt(LoopCondition), doStmt(LoopCondition),
- forStmt(LoopCondition)))
+ Finder->addMatcher(mapAnyOf(whileStmt, doStmt, forStmt)
+ .with(LoopCondition)
.bind("loop-stmt"),
this);
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits