[PATCH] D97151: [clang-tidy] Simplify redundant branch condition check

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 21 07:33:00 PST 2021


steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added a subscriber: xazax.hun.
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/D97151

Files:
  clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h


Index: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h
@@ -26,6 +26,9 @@
       : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+    return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -48,23 +48,23 @@
           .bind(CondVarStr);
   Finder->addMatcher(
       ifStmt(
-          hasCondition(ignoringParenImpCasts(anyOf(
+          hasCondition(anyOf(
               declRefExpr(hasDeclaration(ImmutableVar)).bind(OuterIfVar1Str),
-              binaryOperator(hasOperatorName("&&"),
-                             hasEitherOperand(ignoringParenImpCasts(
-                                 declRefExpr(hasDeclaration(ImmutableVar))
-                                     .bind(OuterIfVar2Str))))))),
+              binaryOperator(
+                  hasOperatorName("&&"),
+                  hasEitherOperand(declRefExpr(hasDeclaration(ImmutableVar))
+                                       .bind(OuterIfVar2Str))))),
           hasThen(hasDescendant(
-              ifStmt(hasCondition(ignoringParenImpCasts(
-                         anyOf(declRefExpr(hasDeclaration(varDecl(
-                                            equalsBoundNode(CondVarStr))))
-                                .bind(InnerIfVar1Str),
-                               binaryOperator(
-                                   hasAnyOperatorName("&&", "||"),
-                                   hasEitherOperand(ignoringParenImpCasts(
-                                       declRefExpr(hasDeclaration(varDecl(
+              ifStmt(hasCondition(anyOf(
+                         declRefExpr(hasDeclaration(
+                                         varDecl(equalsBoundNode(CondVarStr))))
+                             .bind(InnerIfVar1Str),
+                         binaryOperator(
+                             hasAnyOperatorName("&&", "||"),
+                             hasEitherOperand(
+                                 declRefExpr(hasDeclaration(varDecl(
                                                  equalsBoundNode(CondVarStr))))
-                                     .bind(InnerIfVar2Str))))))))
+                                     .bind(InnerIfVar2Str))))))
                   .bind(InnerIfStr))),
           forFunction(functionDecl().bind(FuncStr)))
           .bind(OuterIfStr),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97151.325305.patch
Type: text/x-patch
Size: 3038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210221/bd4bdd3b/attachment.bin>


More information about the cfe-commits mailing list