diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2022-02-12 11:31:27 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2022-02-12 11:31:27 +0000 |
commit | 7ad94bd74bb5e2c984f541bc1921a9eda73ed973 (patch) | |
tree | eae661bfccba4d4c3e09d79f98a526896d7053b1 | |
parent | 2188e61691ad89e27583fd3a4197322be830df59 (diff) |
[clang-tidy] ContainerSizeEmptyCheck::check - simplify isa<> and dyn_cast<> repeated calls
Just use dyn_cast<> to determine literal + container values from the binop
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp index 548fed9a47c3..d399c957c7c7 100644 --- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp @@ -218,23 +218,22 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) { Hint = FixItHint::CreateReplacement(BinCmpRewritten->getSourceRange(), ReplacementText); } else if (BinaryOp) { // Determine the correct transformation. + const auto *LiteralLHS = + llvm::dyn_cast<IntegerLiteral>(BinaryOp->getLHS()->IgnoreImpCasts()); + const auto *LiteralRHS = + llvm::dyn_cast<IntegerLiteral>(BinaryOp->getRHS()->IgnoreImpCasts()); + const bool ContainerIsLHS = !LiteralLHS; + + uint64_t Value = 0; + if (LiteralLHS) + Value = LiteralLHS->getValue().getLimitedValue(); + else if (LiteralRHS) + Value = LiteralRHS->getValue().getLimitedValue(); + else + return; + bool Negation = false; - const bool ContainerIsLHS = - !llvm::isa<IntegerLiteral>(BinaryOp->getLHS()->IgnoreImpCasts()); const auto OpCode = BinaryOp->getOpcode(); - uint64_t Value = 0; - if (ContainerIsLHS) { - if (const auto *Literal = llvm::dyn_cast<IntegerLiteral>( - BinaryOp->getRHS()->IgnoreImpCasts())) - Value = Literal->getValue().getLimitedValue(); - else - return; - } else { - Value = - llvm::dyn_cast<IntegerLiteral>(BinaryOp->getLHS()->IgnoreImpCasts()) - ->getValue() - .getLimitedValue(); - } // Constant that is not handled. if (Value > 1) |