-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[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
Open
kazutakahirata
wants to merge
1
commit into
llvm:main
Choose a base branch
from
kazutakahirata:cleanup_20250630_range_for_clang_Analysis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Analysis] Use range-based for loops (NFC) #146466
kazutakahirata
wants to merge
1
commit into
llvm:main
from
kazutakahirata:cleanup_20250630_range_for_clang_Analysis
+16
−24
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang-analysis @llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/146466.diff 7 Files Affected:
diff --git a/clang/include/clang/Analysis/CFG.h b/clang/include/clang/Analysis/CFG.h
index e70c70335e597..1b1ff5e558ec5 100644
--- a/clang/include/clang/Analysis/CFG.h
+++ b/clang/include/clang/Analysis/CFG.h
@@ -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()));
}
}
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index cf7595952be27..9c642d77db765 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -1754,10 +1754,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 c3a4581e1fb10..028e62ba89b79 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 6a2b0392ccea6..26646cd6b6502 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 c1b2ff41edc0a..375fdb3695e2f 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 b1fbc3c9eff94..ef24efd3c4bd0 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 739c47b12e8c4..4a9ab5d9f0f73 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;
|
tgymnich
approved these changes
Jul 1, 2025
1480b40
to
b61f4e9
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.