Skip to content

[Analysis] Use range-based for loops (NFC) #146466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions clang/include/clang/Analysis/CFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -1394,10 +1394,9 @@ class CFG {
//===--------------------------------------------------------------------===//

template <typename Callback> void VisitBlockStmts(Callback &O) const {
for (const_iterator I = begin(), E = end(); I != E; ++I)
for (CFGBlock::const_iterator BI = (*I)->begin(), BE = (*I)->end();
BI != BE; ++BI) {
if (std::optional<CFGStmt> stmt = BI->getAs<CFGStmt>())
for (CFGBlock *BB : *this)
for (const CFGElement &Elem : *BB) {
if (std::optional<CFGStmt> stmt = Elem.getAs<CFGStmt>())
O(const_cast<Stmt *>(stmt->getStmt()));
}
}
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/Analysis/CFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,10 +1753,9 @@ std::unique_ptr<CFG> CFGBuilder::buildCFG(const Decl *D, Stmt *Statement) {

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

// If there is no target block that contains label, then we are looking
// at an incomplete AST. Handle this by not registering a successor.
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Analysis/CFGStmtMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ CFGStmtMap *CFGStmtMap::Build(CFG *C, ParentMap *PM) {

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

return new CFGStmtMap(PM, SM);
}
Expand Down
5 changes: 1 addition & 4 deletions clang/lib/Analysis/CallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,7 @@ void CallGraph::print(raw_ostream &OS) const {
// We are going to print the graph in reverse post order, partially, to make
// sure the output is deterministic.
llvm::ReversePostOrderTraversal<const CallGraph *> RPOT(this);
for (llvm::ReversePostOrderTraversal<const CallGraph *>::rpo_iterator
I = RPOT.begin(), E = RPOT.end(); I != E; ++I) {
const CallGraphNode *N = *I;

for (const CallGraphNode *N : RPOT) {
OS << " Function: ";
if (N == Root)
OS << "< root >";
Expand Down
10 changes: 4 additions & 6 deletions clang/lib/Analysis/LiveVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ LiveVariablesImpl::runOnBlock(const CFGBlock *block,

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

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

void LiveVariablesImpl::dumpBlockLiveness(const SourceManager &M) {
std::vector<const CFGBlock *> vec;
for (llvm::DenseMap<const CFGBlock *, LiveVariables::LivenessValues>::iterator
it = blocksEndToLiveness.begin(), ei = blocksEndToLiveness.end();
it != ei; ++it) {
vec.push_back(it->first);
for (const auto &KV : blocksEndToLiveness) {
vec.push_back(KV.first);
}
llvm::sort(vec, [](const CFGBlock *A, const CFGBlock *B) {
return A->getBlockID() < B->getBlockID();
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Analysis/PathDiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,9 +1146,9 @@ void PathDiagnostic::FullProfile(llvm::FoldingSetNodeID &ID) const {

LLVM_DUMP_METHOD void PathPieces::dump() const {
unsigned index = 0;
for (PathPieces::const_iterator I = begin(), E = end(); I != E; ++I) {
for (const PathDiagnosticPieceRef &Piece : *this) {
llvm::errs() << "[" << index++ << "] ";
(*I)->dump();
Piece->dump();
llvm::errs() << "\n";
}
}
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/Analysis/ReachableCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,8 @@ static bool isInCoroutineStmt(const Stmt *DeadStmt, const CFGBlock *Block) {
const Stmt *CoroStmt = nullptr;
// Find the first coroutine statement after the DeadStmt in the block.
bool AfterDeadStmt = false;
for (CFGBlock::const_iterator I = Block->begin(), E = Block->end(); I != E;
++I)
if (std::optional<CFGStmt> CS = I->getAs<CFGStmt>()) {
for (const CFGElement &Elem : *Block)
if (std::optional<CFGStmt> CS = Elem.getAs<CFGStmt>()) {
const Stmt *S = CS->getStmt();
if (S == DeadStmt)
AfterDeadStmt = true;
Expand Down