[PATCH] D97151: [clang-tidy] Simplify redundant branch condition check
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 27 04:15:34 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa5feefa3c72e: [clang-tidy] Simplify redundant branch condition check (authored by stephenkelly).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97151/new/
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.326894.patch
Type: text/x-patch
Size: 3038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210227/76f8bdf0/attachment-0001.bin>
More information about the cfe-commits
mailing list