summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2015-07-03 15:12:24 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2015-07-03 15:12:24 +0000
commitefb037a10e984ed3f8dc78d7d0d29fb6465760b9 (patch)
treef39482dad556fe49a4d31226a5636b7b5265d3b8
parent6b3af82767d94ec83c36d17db1e52e60ac20dd0f (diff)
Rewrite users of Stmt::child_begin/end into for-range loops.
No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241355 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/LiveVariables.cpp9
-rw-r--r--lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp7
-rw-r--r--lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp4
-rw-r--r--lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp14
-rw-r--r--lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp6
-rw-r--r--lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp7
-rw-r--r--lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp7
-rw-r--r--lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp6
-rw-r--r--lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp4
-rw-r--r--lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp13
-rw-r--r--lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp10
-rw-r--r--lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp9
-rw-r--r--lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp6
-rw-r--r--lib/StaticAnalyzer/Core/BugReporter.cpp6
-rw-r--r--lib/StaticAnalyzer/Core/BugReporterVisitors.cpp5
-rw-r--r--lib/StaticAnalyzer/Core/CheckerHelpers.cpp32
16 files changed, 61 insertions, 84 deletions
diff --git a/lib/Analysis/LiveVariables.cpp b/lib/Analysis/LiveVariables.cpp
index 0ab158036d..5e0a9a0d73 100644
--- a/lib/Analysis/LiveVariables.cpp
+++ b/lib/Analysis/LiveVariables.cpp
@@ -322,11 +322,10 @@ void TransferFunctions::Visit(Stmt *S) {
return;
}
}
-
- for (Stmt::child_iterator it = S->child_begin(), ei = S->child_end();
- it != ei; ++it) {
- if (Stmt *child = *it)
- AddLiveStmt(val.liveStmts, LV.SSetFact, child);
+
+ for (Stmt *Child : S->children()) {
+ if (Child)
+ AddLiveStmt(val.liveStmts, LV.SSetFact, Child);
}
}
diff --git a/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp b/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
index abfb971d4c..3db19946a3 100644
--- a/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
@@ -168,10 +168,9 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
}
void WalkAST::VisitChildren(Stmt *S) {
- for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I != E;
- ++I)
- if (Stmt *child = *I)
- Visit(child);
+ for (Stmt *Child : S->children())
+ if (Child)
+ Visit(Child);
}
namespace {
diff --git a/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp b/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
index 339af8f033..12eb0bde28 100644
--- a/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
+++ b/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
@@ -69,8 +69,8 @@ static bool scan_ivar_release(Stmt *S, ObjCIvarDecl *ID,
}
// Recurse to children.
- for (Stmt::child_iterator I = S->child_begin(), E= S->child_end(); I!=E; ++I)
- if (*I && scan_ivar_release(*I, ID, PD, Release, SelfII, Ctx))
+ for (Stmt *SubStmt : S->children())
+ if (SubStmt && scan_ivar_release(SubStmt, ID, PD, Release, SelfII, Ctx))
return true;
return false;
diff --git a/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp b/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
index 0beb917833..e0c113c862 100644
--- a/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ b/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -109,9 +109,9 @@ public:
//===----------------------------------------------------------------------===//
void WalkAST::VisitChildren(Stmt *S) {
- for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
- if (Stmt *child = *I)
- Visit(child);
+ for (Stmt *Child : S->children())
+ if (Child)
+ Visit(Child);
}
void WalkAST::VisitCallExpr(CallExpr *CE) {
@@ -162,11 +162,11 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
}
void WalkAST::VisitCompoundStmt(CompoundStmt *S) {
- for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
- if (Stmt *child = *I) {
- if (CallExpr *CE = dyn_cast<CallExpr>(child))
+ for (Stmt *Child : S->children())
+ if (Child) {
+ if (CallExpr *CE = dyn_cast<CallExpr>(Child))
checkUncheckedReturnValue(CE);
- Visit(child);
+ Visit(Child);
}
}
diff --git a/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp b/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp
index a61e658f69..81a20063f9 100644
--- a/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp
+++ b/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp
@@ -37,9 +37,9 @@ public:
}
void WalkAST::VisitChildren(Stmt *S) {
- for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
- if (Stmt *child = *I)
- Visit(child);
+ for (Stmt *Child : S->children())
+ if (Child)
+ Visit(Child);
}
// CWE-467: Use of sizeof() on a Pointer Type
diff --git a/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp b/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp
index 0b7375a4b6..4e3f9b73ac 100644
--- a/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp
@@ -124,10 +124,9 @@ public:
const CheckerBase *checker)
: DeclWithIssue(declWithIssue), BR(br), Checker(checker) {}
void VisitChildren(Stmt *S) {
- for (Stmt::child_iterator I = S->child_begin(), E = S->child_end() ;
- I != E; ++I)
- if (Stmt *child = *I)
- Visit(child);
+ for (Stmt *Child : S->children())
+ if (Child)
+ Visit(Child);
}
void VisitStmt(Stmt *S) { VisitChildren(S); }
void VisitDeclStmt(DeclStmt *DS);
diff --git a/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
index 296aec6680..fb07484bfc 100644
--- a/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
@@ -65,10 +65,9 @@ public:
}
void VisitChildren(const Stmt *S) {
- for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end();
- I!=E; ++I)
- if (const Stmt *child = *I)
- VisitChild(S, child);
+ for (const Stmt *Child : S->children())
+ if (Child)
+ VisitChild(S, Child);
}
TypeCallPair VisitCastExpr(const CastExpr *E) {
diff --git a/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp
index e3fc611a7e..224251beb0 100644
--- a/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp
@@ -153,9 +153,9 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
}
void WalkAST::VisitChildren(Stmt *S) {
- for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
- if (Stmt *child = *I)
- Visit(child);
+ for (Stmt *Child : S->children())
+ if (Child)
+ Visit(Child);
}
namespace {
diff --git a/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp
index d3b17534fd..c6da37eac0 100644
--- a/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp
@@ -57,8 +57,8 @@ static void Scan(IvarUsageMap& M, const Stmt *S) {
Scan(M, sub);
}
- for (Stmt::const_child_iterator I=S->child_begin(),E=S->child_end(); I!=E;++I)
- Scan(M, *I);
+ for (const Stmt *SubStmt : S->children())
+ Scan(M, SubStmt);
}
static void Scan(IvarUsageMap& M, const ObjCPropertyImplDecl *D) {
diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
index 9fa2bb19b4..6ee87a561e 100644
--- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -2182,9 +2182,8 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N,
// Add the range by scanning the children of the statement for any bindings
// to Sym.
- for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end();
- I!=E; ++I)
- if (const Expr *Exp = dyn_cast_or_null<Expr>(*I))
+ for (const Stmt *Child : S->children())
+ if (const Expr *Exp = dyn_cast_or_null<Expr>(Child))
if (CurrSt->getSValAsScalarOrLoc(Exp, LCtx).getAsLocSymbol() == Sym) {
P->addRange(Exp->getSourceRange());
break;
@@ -2779,16 +2778,14 @@ void RetainCountChecker::processObjCLiterals(CheckerContext &C,
const Expr *Ex) const {
ProgramStateRef state = C.getState();
const ExplodedNode *pred = C.getPredecessor();
- for (Stmt::const_child_iterator it = Ex->child_begin(), et = Ex->child_end() ;
- it != et ; ++it) {
- const Stmt *child = *it;
- SVal V = state->getSVal(child, pred->getLocationContext());
+ for (const Stmt *Child : Ex->children()) {
+ SVal V = state->getSVal(Child, pred->getLocationContext());
if (SymbolRef sym = V.getAsSymbol())
if (const RefVal* T = getRefBinding(state, sym)) {
RefVal::Kind hasErr = (RefVal::Kind) 0;
state = updateSymbol(state, sym, *T, MayEscape, hasErr, C);
if (hasErr) {
- processNonLeakError(state, child->getSourceRange(), hasErr, sym, C);
+ processNonLeakError(state, Child->getSourceRange(), hasErr, sym, C);
return;
}
}
diff --git a/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp b/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp
index 12c1e9f067..1d8ef99471 100644
--- a/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp
@@ -37,12 +37,10 @@ class UndefBranchChecker : public Checker<check::BranchCondition> {
if (!MatchesCriteria(Ex))
return nullptr;
- for (Stmt::const_child_iterator I = Ex->child_begin(),
- E = Ex->child_end();I!=E;++I)
- if (const Expr *ExI = dyn_cast_or_null<Expr>(*I)) {
- const Expr *E2 = FindExpr(ExI);
- if (E2) return E2;
- }
+ for (const Stmt *SubStmt : Ex->children())
+ if (const Expr *ExI = dyn_cast_or_null<Expr>(SubStmt))
+ if (const Expr *E2 = FindExpr(ExI))
+ return E2;
return Ex;
}
diff --git a/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp b/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
index c42a2b2984..53fd069bf1 100644
--- a/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
@@ -40,13 +40,10 @@ static const DeclRefExpr *FindBlockDeclRefExpr(const Stmt *S,
if (BR->getDecl() == VD)
return BR;
- for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end();
- I!=E; ++I)
- if (const Stmt *child = *I) {
- const DeclRefExpr *BR = FindBlockDeclRefExpr(child, VD);
- if (BR)
+ for (const Stmt *Child : S->children())
+ if (Child)
+ if (const DeclRefExpr *BR = FindBlockDeclRefExpr(Child, VD))
return BR;
- }
return nullptr;
}
diff --git a/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp b/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
index 7e1fc1eb54..f6ef4aef5c 100644
--- a/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -125,9 +125,9 @@ public:
//===----------------------------------------------------------------------===//
void WalkAST::VisitChildren(Stmt *S) {
- for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
- if (Stmt *child = *I)
- Visit(child);
+ for (Stmt *Child : S->children())
+ if (Child)
+ Visit(Child);
}
void WalkAST::VisitCallExpr(CallExpr *CE) {
diff --git a/lib/StaticAnalyzer/Core/BugReporter.cpp b/lib/StaticAnalyzer/Core/BugReporter.cpp
index a42b4ef2db..e4db64fe34 100644
--- a/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -1250,10 +1250,8 @@ static void reversePropagateIntererstingSymbols(BugReport &R,
// Fall through.
case Stmt::BinaryOperatorClass:
case Stmt::UnaryOperatorClass: {
- for (Stmt::const_child_iterator CI = Ex->child_begin(),
- CE = Ex->child_end();
- CI != CE; ++CI) {
- if (const Expr *child = dyn_cast_or_null<Expr>(*CI)) {
+ for (const Stmt *SubStmt : Ex->children()) {
+ if (const Expr *child = dyn_cast_or_null<Expr>(SubStmt)) {
IE.insert(child);
SVal ChildV = State->getSVal(child, LCtx);
R.markInteresting(ChildV);
diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index fa7884f4a4..f2915ed818 100644
--- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1130,9 +1130,8 @@ void FindLastStoreBRVisitor::registerStatementVarDecls(BugReport &BR,
}
}
- for (Stmt::const_child_iterator I = Head->child_begin();
- I != Head->child_end(); ++I)
- WorkList.push_back(*I);
+ for (const Stmt *SubStmt : Head->children())
+ WorkList.push_back(SubStmt);
}
}
diff --git a/lib/StaticAnalyzer/Core/CheckerHelpers.cpp b/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
index 28df6959af..3d9a815815 100644
--- a/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
+++ b/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
@@ -22,11 +22,9 @@ bool clang::ento::containsMacro(const Stmt *S) {
if (S->getLocEnd().isMacroID())
return true;
- for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
- ++I)
- if (const Stmt *child = *I)
- if (containsMacro(child))
- return true;
+ for (const Stmt *Child : S->children())
+ if (Child && containsMacro(Child))
+ return true;
return false;
}
@@ -38,11 +36,9 @@ bool clang::ento::containsEnum(const Stmt *S) {
if (DR && isa<EnumConstantDecl>(DR->getDecl()))
return true;
- for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
- ++I)
- if (const Stmt *child = *I)
- if (containsEnum(child))
- return true;
+ for (const Stmt *Child : S->children())
+ if (Child && containsEnum(Child))
+ return true;
return false;
}
@@ -56,11 +52,9 @@ bool clang::ento::containsStaticLocal(const Stmt *S) {
if (VD->isStaticLocal())
return true;
- for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
- ++I)
- if (const Stmt *child = *I)
- if (containsStaticLocal(child))
- return true;
+ for (const Stmt *Child : S->children())
+ if (Child && containsStaticLocal(Child))
+ return true;
return false;
}
@@ -70,11 +64,9 @@ bool clang::ento::containsBuiltinOffsetOf(const Stmt *S) {
if (isa<OffsetOfExpr>(S))
return true;
- for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
- ++I)
- if (const Stmt *child = *I)
- if (containsBuiltinOffsetOf(child))
- return true;
+ for (const Stmt *Child : S->children())
+ if (Child && containsBuiltinOffsetOf(Child))
+ return true;
return false;
}