Skip to content

Commit 1480b40

Browse files
[Analysis] Use range-based for loops (NFC)
1 parent 393a75e commit 1480b40

File tree

7 files changed

+16
-24
lines changed

7 files changed

+16
-24
lines changed

clang/include/clang/Analysis/CFG.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,10 +1394,9 @@ class CFG {
13941394
//===--------------------------------------------------------------------===//
13951395

13961396
template <typename Callback> void VisitBlockStmts(Callback &O) const {
1397-
for (const_iterator I = begin(), E = end(); I != E; ++I)
1398-
for (CFGBlock::const_iterator BI = (*I)->begin(), BE = (*I)->end();
1399-
BI != BE; ++BI) {
1400-
if (std::optional<CFGStmt> stmt = BI->getAs<CFGStmt>())
1397+
for (CFGBlock *BB : *this)
1398+
for (const CFGElement &Elem : *BB) {
1399+
if (std::optional<CFGStmt> stmt = Elem.getAs<CFGStmt>())
14011400
O(const_cast<Stmt *>(stmt->getStmt()));
14021401
}
14031402
}

clang/lib/Analysis/CFG.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,10 +1754,9 @@ std::unique_ptr<CFG> CFGBuilder::buildCFG(const Decl *D, Stmt *Statement) {
17541754

17551755
// Add successors to the Indirect Goto Dispatch block (if we have one).
17561756
if (CFGBlock *B = cfg->getIndirectGotoBlock())
1757-
for (LabelSetTy::iterator I = AddressTakenLabels.begin(),
1758-
E = AddressTakenLabels.end(); I != E; ++I ) {
1757+
for (LabelDecl *LD : AddressTakenLabels) {
17591758
// Lookup the target block.
1760-
LabelMapTy::iterator LI = LabelMap.find(*I);
1759+
LabelMapTy::iterator LI = LabelMap.find(LD);
17611760

17621761
// If there is no target block that contains label, then we are looking
17631762
// at an incomplete AST. Handle this by not registering a successor.

clang/lib/Analysis/CFGStmtMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ CFGStmtMap *CFGStmtMap::Build(CFG *C, ParentMap *PM) {
8383

8484
// Walk all blocks, accumulating the block-level expressions, labels,
8585
// and terminators.
86-
for (CFG::iterator I = C->begin(), E = C->end(); I != E; ++I)
87-
Accumulate(*SM, *I);
86+
for (CFGBlock *BB : *C)
87+
Accumulate(*SM, BB);
8888

8989
return new CFGStmtMap(PM, SM);
9090
}

clang/lib/Analysis/CallGraph.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,7 @@ void CallGraph::print(raw_ostream &OS) const {
223223
// We are going to print the graph in reverse post order, partially, to make
224224
// sure the output is deterministic.
225225
llvm::ReversePostOrderTraversal<const CallGraph *> RPOT(this);
226-
for (llvm::ReversePostOrderTraversal<const CallGraph *>::rpo_iterator
227-
I = RPOT.begin(), E = RPOT.end(); I != E; ++I) {
228-
const CallGraphNode *N = *I;
229-
226+
for (const CallGraphNode *N : RPOT) {
230227
OS << " Function: ";
231228
if (N == Root)
232229
OS << "< root >";

clang/lib/Analysis/LiveVariables.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ LiveVariablesImpl::runOnBlock(const CFGBlock *block,
546546

547547
void LiveVariables::runOnAllBlocks(LiveVariables::Observer &obs) {
548548
const CFG *cfg = getImpl(impl).analysisContext.getCFG();
549-
for (CFG::const_iterator it = cfg->begin(), ei = cfg->end(); it != ei; ++it)
550-
getImpl(impl).runOnBlock(*it, getImpl(impl).blocksEndToLiveness[*it], &obs);
549+
for (CFGBlock *B : *cfg)
550+
getImpl(impl).runOnBlock(B, getImpl(impl).blocksEndToLiveness[B], &obs);
551551
}
552552

553553
LiveVariables::LiveVariables(void *im) : impl(im) {}
@@ -618,10 +618,8 @@ void LiveVariables::dumpBlockLiveness(const SourceManager &M) {
618618

619619
void LiveVariablesImpl::dumpBlockLiveness(const SourceManager &M) {
620620
std::vector<const CFGBlock *> vec;
621-
for (llvm::DenseMap<const CFGBlock *, LiveVariables::LivenessValues>::iterator
622-
it = blocksEndToLiveness.begin(), ei = blocksEndToLiveness.end();
623-
it != ei; ++it) {
624-
vec.push_back(it->first);
621+
for (const auto &KV : blocksEndToLiveness) {
622+
vec.push_back(KV.first);
625623
}
626624
llvm::sort(vec, [](const CFGBlock *A, const CFGBlock *B) {
627625
return A->getBlockID() < B->getBlockID();

clang/lib/Analysis/PathDiagnostic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,9 @@ void PathDiagnostic::FullProfile(llvm::FoldingSetNodeID &ID) const {
11461146

11471147
LLVM_DUMP_METHOD void PathPieces::dump() const {
11481148
unsigned index = 0;
1149-
for (PathPieces::const_iterator I = begin(), E = end(); I != E; ++I) {
1149+
for (const PathDiagnosticPieceRef &Piece : *this) {
11501150
llvm::errs() << "[" << index++ << "] ";
1151-
(*I)->dump();
1151+
Piece->dump();
11521152
llvm::errs() << "\n";
11531153
}
11541154
}

clang/lib/Analysis/ReachableCode.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,8 @@ static bool isInCoroutineStmt(const Stmt *DeadStmt, const CFGBlock *Block) {
460460
const Stmt *CoroStmt = nullptr;
461461
// Find the first coroutine statement after the DeadStmt in the block.
462462
bool AfterDeadStmt = false;
463-
for (CFGBlock::const_iterator I = Block->begin(), E = Block->end(); I != E;
464-
++I)
465-
if (std::optional<CFGStmt> CS = I->getAs<CFGStmt>()) {
463+
for (const CFGElement &Elem : *Block)
464+
if (std::optional<CFGStmt> CS = Elem.getAs<CFGStmt>()) {
466465
const Stmt *S = CS->getStmt();
467466
if (S == DeadStmt)
468467
AfterDeadStmt = true;

0 commit comments

Comments
 (0)