[clang-tidy] Simplify redundant branch condition check

Differential Revision: https://reviews.llvm.org/D97151
This commit is contained in:
Stephen Kelly 2020-12-29 23:28:28 +00:00
parent df42f9950d
commit a5feefa3c7
2 changed files with 17 additions and 14 deletions

View 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),

View 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