[PATCH] D94131: [clang-tidy] Use new mapAnyOf matcher

2021-02-03 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 321233.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94131/new/

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/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
  
clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-rewritten-binop.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty-cxx20.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty-cxx20.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty-cxx20.cpp
@@ -0,0 +1,44 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-container-size-empty %t -- -- -fno-delayed-template-parsing
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+template 
+struct OpEqOnly {
+  OpEqOnly();
+  bool operator==(const OpEqOnly ) const;
+  unsigned long size() const;
+  bool empty() const;
+};
+
+template 
+struct HasSpaceshipMem {
+  HasSpaceshipMem();
+  bool operator<=>(const HasSpaceshipMem ) const = default;
+  unsigned long size() const;
+  bool empty() const;
+};
+
+void returnsVoid() {
+  OpEqOnly OEO;
+  HasSpaceshipMem HSM;
+
+  if (OEO != OpEqOnly())
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness
+  // CHECK-FIXES: {{^  }}if (!OEO.empty()){{$}}
+  // CHECK-MESSAGES: :18:8: note: method 'OpEqOnly'::empty() defined here
+  if (HSM != HasSpaceshipMem())
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness
+  // CHECK-FIXES: {{^  }}if (!HSM.empty()){{$}}
+  // CHECK-MESSAGES: :25:8: note: method 'HasSpaceshipMem'::empty() defined here
+}
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-rewritten-binop.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-rewritten-binop.cpp
@@ -0,0 +1,60 @@
+// RUN: %check_clang_tidy -std=c++20 %s modernize-loop-convert %t -- -- -I %S/Inputs/modernize-loop-convert
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct HasSpaceshipMem {
+  typedef int value_type;
+
+  struct iterator {
+value_type *();
+const value_type *() const;
+iterator ++();
+void insert(value_type);
+value_type X;
+constexpr auto operator<=>(const HasSpaceshipMem::iterator &) const = default;
+  };
+
+  iterator begin();
+  iterator end();
+};
+
+struct OpEqOnly {
+  typedef int value_type;
+  struct iterator {
+value_type *();
+const value_type *() const;
+iterator ++();
+bool operator==(const iterator ) const;
+void insert(value_type);
+value_type X;
+  };
+  iterator begin();
+  iterator end();
+};
+
+void rewritten() {
+  OpEqOnly Oeo;
+  for (OpEqOnly::iterator It = Oeo.begin(), E = Oeo.end(); It != E; ++It) {
+(void)*It;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & It : Oeo)
+  // CHECK-FIXES-NEXT: (void)It;
+
+  HasSpaceshipMem Hsm;
+  for (HasSpaceshipMem::iterator It = Hsm.begin(), E = Hsm.end(); It != E; ++It) {
+(void)*It;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & It : Hsm)
+  // CHECK-FIXES-NEXT: (void)It;
+}
Index: 

[PATCH] D94131: [clang-tidy] Use new mapAnyOf matcher

2021-01-16 Thread Nathan James via Phabricator via cfe-commits
njames93 requested changes to this revision.
njames93 added a comment.
This revision now requires changes to proceed.

Can you either update the description of this patch to include the 
binaryOperation changes, or remove those changes from here.




Comment at: 
clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp:62
 Finder->addMatcher(
-ifStmt(
-
-allOf(hasWaitDescendantCPP,
-  unless(anyOf(hasDescendant(ifStmt(hasWaitDescendantCPP)),
-   hasDescendant(whileStmt(hasWaitDescendantCPP)),
-   hasDescendant(forStmt(hasWaitDescendantCPP)),
-   hasDescendant(doStmt(hasWaitDescendantCPP)
-
-),
+ifStmt(allOf(
+hasWaitDescendantCPP,

While were here, this allOf matcher could be removed.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp:43-45
+  const auto HasNoSelfCheck = cxxMethodDecl(unless(hasDescendant(
+  binaryOperation(hasAnyOperatorName("==", "!="),
+  hasEitherOperand(ignoringParenCasts(cxxThisExpr()));

nit: Can this unrelated change be removed from this patch.



Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:313
// 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,

nit: ditto.



Comment at: clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp:33-34
   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));
 

And here.



Comment at: clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp:42
   const auto IsSelfMutatingAssignment =
-  expr(anyOf(binaryOperator(isAssignmentOperator(), hasLHS(IsPartOfSelf)),
- cxxOperatorCallExpr(isAssignmentOperator(),
- hasArgument(0, IsPartOfSelf;
+  binaryOperation(isAssignmentOperator(), hasLHS(IsPartOfSelf));
 

Here.



Comment at: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp:213-215
+ hasCondition(ignoringImplicit(binaryOperation(
+ hasOperatorName("!="), hasOperands(IteratorComparisonMatcher,
+IteratorBoundMatcher,

Also unrelated.



Comment at: 
clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp:186-188
+if (match(traverse(TK_AsIs,
+   compoundStmt(has(ignoringParenImpCasts(binaryOperation(
+   hasOperatorName("="), hasLHS(LHS), hasRHS(RHS)),

Also unrelated.



Comment at: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp:51-54
+  callOrConstruct(forEachArgumentWithParam(
+  MoveCallMatcher,
+  
parmVarDecl(hasType(references(isConstQualified())
+  .bind("receiving-expr"),

Unrelated changes again.



Comment at: 
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp:75
  cxxUnresolvedConstructExpr(hasType(booleanType())),
- callExpr(hasAnyArgumentWithParam(
+ callOrConstruct(hasAnyArgumentWithParam(
  expr(equalsBoundNode(ExprName)),

Unrelated change.



Comment at: 
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp:181-186
+  binaryOperation(unless(isInTemplateInstantiation()),
+  hasAnyOperatorName("==", "!="),
+  hasOperands(ignoringParenImpCasts(WrongComparend),
+  ignoringParenImpCasts(STLArg)),
+  unless(hasAncestor(cxxMethodDecl(
+  ofClass(equalsBoundNode("container"))

Unrelated change



Comment at: clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp:70
   

[PATCH] D94131: [clang-tidy] Use new mapAnyOf matcher

2021-01-16 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 317177.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94131/new/

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/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,8 @@
   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);
+  match(findAll(callOrConstruct(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,26 +56,23 @@
   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())),
- 

[PATCH] D94131: [clang-tidy] Use new mapAnyOf matcher

2021-01-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

In D94131#2481804 , @njames93 wrote:

> Theres a few compile errors here in the pre merge. Is this patch based 
> against trunk or some local branch?

It's a patch series but for some reason Phab isn't aware of that, hence the 
lint errors and seemingly odd use of things not already landed.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94131/new/

https://reviews.llvm.org/D94131

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94131: [clang-tidy] Use new mapAnyOf matcher

2021-01-06 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Theres a few compile errors here in the pre merge. Is this patch based against 
trunk or some local branch?




Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:313
// 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,

This doesn't compile and it appears unrelated. Same beloe



Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp:32
   // 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(;

Any reason for clang not finding this? 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94131/new/

https://reviews.llvm.org/D94131

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94131: [clang-tidy] Use new mapAnyOf matcher

2021-01-05 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 314739.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94131/new/

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/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(,
  

[PATCH] D94131: [clang-tidy] Use new mapAnyOf matcher

2021-01-05 Thread Stephen Kelly via Phabricator via cfe-commits
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(