[clang-tools-extra] a5feefa - [clang-tidy] Simplify redundant branch condition check

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 27 04:15:21 PST 2021


Author: Stephen Kelly
Date: 2021-02-27T12:13:23Z
New Revision: a5feefa3c72e67ea94b50addf8f0975dae9a9696

URL: https://github.com/llvm/llvm-project/commit/a5feefa3c72e67ea94b50addf8f0975dae9a9696
DIFF: https://github.com/llvm/llvm-project/commit/a5feefa3c72e67ea94b50addf8f0975dae9a9696.diff

LOG: [clang-tidy] Simplify redundant branch condition check

Differential Revision: https://reviews.llvm.org/D97151

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
index 2b0d9630527b..3998e2bc1de0 100644
--- a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -48,23 +48,23 @@ void RedundantBranchConditionCheck::registerMatchers(MatchFinder *Finder) {
           .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),

diff  --git a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h
index 7b38d59a0121..a086b269e64d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h
@@ -26,6 +26,9 @@ class RedundantBranchConditionCheck : public ClangTidyCheck {
       : 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


        


More information about the cfe-commits mailing list