Skip to content

Commit 386f2f3

Browse files
committed
[analyzer][NFC] Modernize iterator-based loops in LiveVariablesImpl::dumpBlockLiveness
Convert multiple iterator-based loops to range-based for loops: - DenseMap iteration over blocksEndToLiveness - std::vector iteration over CFGBlocks - ImmutableSet iteration over liveDecls - std::vector iteration over declVec
1 parent cb532a3 commit 386f2f3

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

clang/lib/Analysis/LiveVariables.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -585,38 +585,26 @@ void LiveVariables::dumpBlockLiveness(const SourceManager &M) {
585585

586586
void LiveVariablesImpl::dumpBlockLiveness(const SourceManager &M) {
587587
std::vector<const CFGBlock *> vec;
588-
for (const auto &KV : blocksEndToLiveness) {
589-
vec.push_back(KV.first);
590-
}
588+
vec.reserve(blocksEndToLiveness.size());
589+
llvm::append_range(vec, llvm::make_first_range(blocksEndToLiveness));
591590
llvm::sort(vec, [](const CFGBlock *A, const CFGBlock *B) {
592591
return A->getBlockID() < B->getBlockID();
593592
});
594593

595594
std::vector<const VarDecl*> declVec;
596595

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

615-
for (std::vector<const VarDecl*>::iterator di = declVec.begin(),
616-
de = declVec.end(); di != de; ++di) {
617-
llvm::errs() << " " << (*di)->getDeclName().getAsString()
618-
<< " <";
619-
(*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);
620608
llvm::errs() << ">\n";
621609
}
622610
}

0 commit comments

Comments
 (0)