aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2025-07-01 19:38:28 -0700
committerGitHub <noreply@github.com>2025-07-01 19:38:28 -0700
commiteb07f0d4a933d18dbf9f606d533baced2a1a19ca (patch)
tree9ed98dc0e8c38db6b24800dcf56c7bafd4df7f7f /clang/lib
parent2599a9aeb543f01cb20e3fdc2713aa8c8cb20fbf (diff)
downloadllvm-eb07f0d4a933d18dbf9f606d533baced2a1a19ca.zip
llvm-eb07f0d4a933d18dbf9f606d533baced2a1a19ca.tar.gz
llvm-eb07f0d4a933d18dbf9f606d533baced2a1a19ca.tar.bz2
[Analysis] Use range-based for loops (NFC) (#146466)
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Analysis/CFG.cpp5
-rw-r--r--clang/lib/Analysis/CFGStmtMap.cpp4
-rw-r--r--clang/lib/Analysis/CallGraph.cpp5
-rw-r--r--clang/lib/Analysis/LiveVariables.cpp10
-rw-r--r--clang/lib/Analysis/PathDiagnostic.cpp4
-rw-r--r--clang/lib/Analysis/ReachableCode.cpp5
6 files changed, 13 insertions, 20 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index c23e3d0..d960d51 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -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.
diff --git a/clang/lib/Analysis/CFGStmtMap.cpp b/clang/lib/Analysis/CFGStmtMap.cpp
index c3a4581..028e62b 100644
--- a/clang/lib/Analysis/CFGStmtMap.cpp
+++ b/clang/lib/Analysis/CFGStmtMap.cpp
@@ -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);
}
diff --git a/clang/lib/Analysis/CallGraph.cpp b/clang/lib/Analysis/CallGraph.cpp
index 6a2b039..26646cd 100644
--- a/clang/lib/Analysis/CallGraph.cpp
+++ b/clang/lib/Analysis/CallGraph.cpp
@@ -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 >";
diff --git a/clang/lib/Analysis/LiveVariables.cpp b/clang/lib/Analysis/LiveVariables.cpp
index c1b2ff4..375fdb3 100644
--- a/clang/lib/Analysis/LiveVariables.cpp
+++ b/clang/lib/Analysis/LiveVariables.cpp
@@ -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) {}
@@ -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();
diff --git a/clang/lib/Analysis/PathDiagnostic.cpp b/clang/lib/Analysis/PathDiagnostic.cpp
index b1fbc3c..ef24efd 100644
--- a/clang/lib/Analysis/PathDiagnostic.cpp
+++ b/clang/lib/Analysis/PathDiagnostic.cpp
@@ -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";
}
}
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
index 739c47b..4a9ab5d 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -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;