[clang-tidy] Simplify redundant branch condition check
authorStephen Kelly <steveire@gmail.com>
Tue, 29 Dec 2020 23:28:28 +0000 (23:28 +0000)
committerStephen Kelly <steveire@gmail.com>
Sat, 27 Feb 2021 12:13:23 +0000 (12:13 +0000)
Differential Revision: https://reviews.llvm.org/D97151

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

index 2b0d963..3998e2b 100644 (file)
@@ -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),
index 7b38d59..a086b26 100644 (file)
@@ -26,6 +26,9 @@ public:
       : 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