From: Simon Pilgrim Date: Sat, 12 Feb 2022 11:31:27 +0000 (+0000) Subject: [clang-tidy] ContainerSizeEmptyCheck::check - simplify isa<> and dyn_cast<> repeated... X-Git-Tag: upstream/15.0.7~16723 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ad94bd74bb5e2c984f541bc1921a9eda73ed973;p=platform%2Fupstream%2Fllvm.git [clang-tidy] ContainerSizeEmptyCheck::check - simplify isa<> and dyn_cast<> repeated calls Just use dyn_cast<> to determine literal + container values from the binop --- diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp index 548fed9..d399c95 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(BinaryOp->getLHS()->IgnoreImpCasts()); + const auto *LiteralRHS = + llvm::dyn_cast(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(BinaryOp->getLHS()->IgnoreImpCasts()); const auto OpCode = BinaryOp->getOpcode(); - uint64_t Value = 0; - if (ContainerIsLHS) { - if (const auto *Literal = llvm::dyn_cast( - BinaryOp->getRHS()->IgnoreImpCasts())) - Value = Literal->getValue().getLimitedValue(); - else - return; - } else { - Value = - llvm::dyn_cast(BinaryOp->getLHS()->IgnoreImpCasts()) - ->getValue() - .getLimitedValue(); - } // Constant that is not handled. if (Value > 1)