Skip to content

Commit 723fcd5

Browse files
authored
[analyzer][NFC] Modernize loops in LiveVariables analysis (#157670)
1 parent 144c93b commit 723fcd5

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

clang/lib/Analysis/LiveVariables.cpp

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ namespace {
9090
if (A.isEmpty())
9191
return B;
9292

93-
for (typename SET::iterator it = B.begin(), ei = B.end(); it != ei; ++it) {
94-
A = A.add(*it);
93+
for (const auto *Elem : B) {
94+
A = A.add(Elem);
9595
}
9696
return A;
9797
}
@@ -556,9 +556,8 @@ LiveVariables::computeLiveness(AnalysisDeclContext &AC, bool killAtAssign) {
556556

557557
// Merge the values of all successor blocks.
558558
LivenessValues val;
559-
for (CFGBlock::const_succ_iterator it = block->succ_begin(),
560-
ei = block->succ_end(); it != ei; ++it) {
561-
if (const CFGBlock *succ = *it) {
559+
for (const CFGBlock *succ : block->succs()) {
560+
if (succ) {
562561
val = LV->merge(val, LV->blocksBeginToLiveness[succ]);
563562
}
564563
}
@@ -586,38 +585,26 @@ void LiveVariables::dumpBlockLiveness(const SourceManager &M) {
586585

587586
void LiveVariablesImpl::dumpBlockLiveness(const SourceManager &M) {
588587
std::vector<const CFGBlock *> vec;
589-
for (const auto &KV : blocksEndToLiveness) {
590-
vec.push_back(KV.first);
591-
}
588+
vec.reserve(blocksEndToLiveness.size());
589+
llvm::append_range(vec, llvm::make_first_range(blocksEndToLiveness));
592590
llvm::sort(vec, [](const CFGBlock *A, const CFGBlock *B) {
593591
return A->getBlockID() < B->getBlockID();
594592
});
595593

596594
std::vector<const VarDecl*> declVec;
597595

598-
for (std::vector<const CFGBlock *>::iterator
599-
it = vec.begin(), ei = vec.end(); it != ei; ++it) {
600-
llvm::errs() << "\n[ B" << (*it)->getBlockID()
596+
for (const CFGBlock *block : vec) {
597+
llvm::errs() << "\n[ B" << block->getBlockID()
601598
<< " (live variables at block exit) ]\n";
602-
603-
LiveVariables::LivenessValues vals = blocksEndToLiveness[*it];
604599
declVec.clear();
605-
606-
for (llvm::ImmutableSet<const VarDecl *>::iterator si =
607-
vals.liveDecls.begin(),
608-
se = vals.liveDecls.end(); si != se; ++si) {
609-
declVec.push_back(*si);
610-
}
611-
600+
llvm::append_range(declVec, blocksEndToLiveness[block].liveDecls);
612601
llvm::sort(declVec, [](const Decl *A, const Decl *B) {
613602
return A->getBeginLoc() < B->getBeginLoc();
614603
});
615604

616-
for (std::vector<const VarDecl*>::iterator di = declVec.begin(),
617-
de = declVec.end(); di != de; ++di) {
618-
llvm::errs() << " " << (*di)->getDeclName().getAsString()
619-
<< " <";
620-
(*di)->getLocation().print(llvm::errs(), M);
605+
for (const VarDecl *VD : declVec) {
606+
llvm::errs() << " " << VD->getDeclName().getAsString() << " <";
607+
VD->getLocation().print(llvm::errs(), M);
621608
llvm::errs() << ">\n";
622609
}
623610
}

0 commit comments

Comments
 (0)