From: Simon Pilgrim Date: Wed, 29 Sep 2021 11:54:52 +0000 (+0100) Subject: [clang-tidy] Merges separate isa<>/assert/unreachable/dyn_cast<>/cast<> calls X-Git-Tag: upstream/15.0.7~30156 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7674bd4d44921d2d110cfb56f2674d4e6e8a68e3;p=platform%2Fupstream%2Fllvm.git [clang-tidy] Merges separate isa<>/assert/unreachable/dyn_cast<>/cast<> calls We can directly use cast<> instead of separate dyn_cast<> with assertions as cast<> will perform this for us. Similarly we can replace a if(isa<>)+cast<>/dyn_cast<> with if(dyn_cast<>) --- diff --git a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp index 40ba391..0290789 100644 --- a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp @@ -120,9 +120,7 @@ bool UnrollLoopsCheck::hasKnownBounds(const Stmt *Statement, if (isa(Statement)) return false; // The last loop type is a for loop. - const auto *ForLoop = dyn_cast(Statement); - if (!ForLoop) - llvm_unreachable("Unknown loop"); + const auto *ForLoop = cast(Statement); const Stmt *Initializer = ForLoop->getInit(); const Expr *Conditional = ForLoop->getCond(); const Expr *Increment = ForLoop->getInc(); @@ -142,8 +140,7 @@ bool UnrollLoopsCheck::hasKnownBounds(const Stmt *Statement, if (!Op->isIncrementDecrementOp()) return false; - if (isa(Conditional)) { - const auto *BinaryOp = dyn_cast(Conditional); + if (const auto *BinaryOp = dyn_cast(Conditional)) { const Expr *LHS = BinaryOp->getLHS(); const Expr *RHS = BinaryOp->getRHS(); // If both sides are value dependent or constant, loop bounds are unknown. @@ -173,8 +170,7 @@ bool UnrollLoopsCheck::hasLargeNumIterations(const Stmt *Statement, assert(CXXLoopBound && "CXX ranged for loop has no loop bound"); return exprHasLargeNumIterations(CXXLoopBound, Context); } - const auto *ForLoop = dyn_cast(Statement); - assert(ForLoop && "Unknown loop"); + const auto *ForLoop = cast(Statement); const Stmt *Initializer = ForLoop->getInit(); const Expr *Conditional = ForLoop->getCond(); const Expr *Increment = ForLoop->getInc(); @@ -189,10 +185,9 @@ bool UnrollLoopsCheck::hasLargeNumIterations(const Stmt *Statement, InitValue = Evaluation->getInt().getExtValue(); } } - assert(isa(Conditional) && - "Conditional is not a binary operator"); + int EndValue; - const auto *BinaryOp = dyn_cast(Conditional); + const auto *BinaryOp = cast(Conditional); if (!extractValue(EndValue, BinaryOp, Context)) return true;