forked from OSchip/llvm-project
[clang-tidy] Simplify redundant branch condition check
Differential Revision: https://reviews.llvm.org/D97151
This commit is contained in:
parent
df42f9950d
commit
a5feefa3c7
|
@ -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))))
|
||||
ifStmt(hasCondition(anyOf(
|
||||
declRefExpr(hasDeclaration(
|
||||
varDecl(equalsBoundNode(CondVarStr))))
|
||||
.bind(InnerIfVar1Str),
|
||||
binaryOperator(
|
||||
hasAnyOperatorName("&&", "||"),
|
||||
hasEitherOperand(ignoringParenImpCasts(
|
||||
hasEitherOperand(
|
||||
declRefExpr(hasDeclaration(varDecl(
|
||||
equalsBoundNode(CondVarStr))))
|
||||
.bind(InnerIfVar2Str))))))))
|
||||
.bind(InnerIfVar2Str))))))
|
||||
.bind(InnerIfStr))),
|
||||
forFunction(functionDecl().bind(FuncStr)))
|
||||
.bind(OuterIfStr),
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue