Skip to content

Commit a9d175f

Browse files
[CodeGen] Use range-based for loops (NFC) (#144939)
1 parent d3a2931 commit a9d175f

File tree

10 files changed

+39
-50
lines changed

10 files changed

+39
-50
lines changed

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,10 +1415,10 @@ llvm::Function *CodeGenFunction::GenerateBlockFunction(
14151415
// Arrange for local static and local extern declarations to appear
14161416
// to be local to this function as well, in case they're directly
14171417
// referenced in a block.
1418-
for (DeclMapTy::const_iterator i = ldm.begin(), e = ldm.end(); i != e; ++i) {
1419-
const auto *var = dyn_cast<VarDecl>(i->first);
1418+
for (const auto &KV : ldm) {
1419+
const auto *var = dyn_cast<VarDecl>(KV.first);
14201420
if (var && !var->hasLocalStorage())
1421-
setAddrOfLocalVar(var, i->second);
1421+
setAddrOfLocalVar(var, KV.second);
14221422
}
14231423

14241424
// Begin building the function declaration.

clang/lib/CodeGen/CGCleanup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,8 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
962962

963963
// Append the prepared cleanup prologue from above.
964964
llvm::BasicBlock *NormalExit = Builder.GetInsertBlock();
965-
for (unsigned I = 0, E = InstsToAppend.size(); I != E; ++I)
966-
InstsToAppend[I]->insertInto(NormalExit, NormalExit->end());
965+
for (llvm::Instruction *Inst : InstsToAppend)
966+
Inst->insertInto(NormalExit, NormalExit->end());
967967

968968
// Optimistically hope that any fixups will continue falling through.
969969
for (unsigned I = FixupDepth, E = EHStack.getNumBranchFixups();

clang/lib/CodeGen/CGDeclCXX.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,9 +1121,9 @@ CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
11211121
EmitObjCAutoreleasePoolCleanup(token);
11221122
}
11231123

1124-
for (unsigned i = 0, e = Decls.size(); i != e; ++i)
1125-
if (Decls[i])
1126-
EmitRuntimeCall(Decls[i]);
1124+
for (llvm::Function *Decl : Decls)
1125+
if (Decl)
1126+
EmitRuntimeCall(Decl);
11271127

11281128
Scope.ForceCleanup();
11291129

clang/lib/CodeGen/CGException.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ static bool PersonalityHasOnlyCXXUses(llvm::Constant *Fn) {
319319
llvm::Function *F = dyn_cast<llvm::Function>(U);
320320
if (!F) return false;
321321

322-
for (auto BB = F->begin(), E = F->end(); BB != E; ++BB) {
323-
if (BB->isLandingPad())
324-
if (!LandingPadHasOnlyCXXUses(BB->getLandingPadInst()))
322+
for (llvm::BasicBlock &BB : *F) {
323+
if (BB.isLandingPad())
324+
if (!LandingPadHasOnlyCXXUses(BB.getLandingPadInst()))
325325
return false;
326326
}
327327
}
@@ -937,8 +937,8 @@ llvm::BasicBlock *CodeGenFunction::EmitLandingPad() {
937937
filterTypes[0]->getType() : Int8PtrTy,
938938
filterTypes.size());
939939

940-
for (unsigned i = 0, e = filterTypes.size(); i != e; ++i)
941-
Filters.push_back(cast<llvm::Constant>(filterTypes[i]));
940+
for (llvm::Value *filterType : filterTypes)
941+
Filters.push_back(cast<llvm::Constant>(filterType));
942942
llvm::Constant *FilterArray = llvm::ConstantArray::get(AType, Filters);
943943
LPadInst->addClause(FilterArray);
944944

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,8 +3801,8 @@ void CodeGenFunction::EmitCheck(
38013801
ArgTypes.push_back(Args.back()->getType());
38023802
}
38033803

3804-
for (size_t i = 0, n = DynamicArgs.size(); i != n; ++i) {
3805-
Args.push_back(EmitCheckValue(DynamicArgs[i]));
3804+
for (llvm::Value *DynamicArg : DynamicArgs) {
3805+
Args.push_back(EmitCheckValue(DynamicArg));
38063806
ArgTypes.push_back(IntPtrTy);
38073807
}
38083808
}
@@ -4932,8 +4932,8 @@ EmitExtVectorElementExpr(const ExtVectorElementExpr *E) {
49324932
llvm::Constant *BaseElts = Base.getExtVectorElts();
49334933
SmallVector<llvm::Constant *, 4> CElts;
49344934

4935-
for (unsigned i = 0, e = Indices.size(); i != e; ++i)
4936-
CElts.push_back(BaseElts->getAggregateElement(Indices[i]));
4935+
for (unsigned Index : Indices)
4936+
CElts.push_back(BaseElts->getAggregateElement(Index));
49374937
llvm::Constant *CV = llvm::ConstantVector::get(CElts);
49384938
return LValue::MakeExtVectorElt(Base.getExtVectorAddress(), CV, type,
49394939
Base.getBaseInfo(), TBAAAccessInfo());
@@ -6660,8 +6660,8 @@ static LValueOrRValue emitPseudoObjectExpr(CodeGenFunction &CGF,
66606660
}
66616661

66626662
// Unbind all the opaques now.
6663-
for (unsigned i = 0, e = opaques.size(); i != e; ++i)
6664-
opaques[i].unbind(CGF);
6663+
for (CodeGenFunction::OpaqueValueMappingData &opaque : opaques)
6664+
opaque.unbind(CGF);
66656665

66666666
return result;
66676667
}

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,7 @@ bool ConstStructBuilder::Build(const APValue &Val, const RecordDecl *RD,
871871
}
872872
llvm::stable_sort(Bases);
873873

874-
for (unsigned I = 0, N = Bases.size(); I != N; ++I) {
875-
BaseInfo &Base = Bases[I];
876-
874+
for (const BaseInfo &Base : Bases) {
877875
bool IsPrimaryBase = Layout.getPrimaryBase() == Base.Decl;
878876
Build(Val.getStructBase(Base.Index), Base.Decl, IsPrimaryBase,
879877
VTableClass, Offset + Base.Offset);

clang/lib/CodeGen/CGObjC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3173,8 +3173,8 @@ ARCExprEmitter<Impl,Result>::visitPseudoObjectExpr(const PseudoObjectExpr *E) {
31733173
}
31743174

31753175
// Unbind all the opaques now.
3176-
for (unsigned i = 0, e = opaques.size(); i != e; ++i)
3177-
opaques[i].unbind(CGF);
3176+
for (CodeGenFunction::OpaqueValueMappingData &opaque : opaques)
3177+
opaque.unbind(CGF);
31783178

31793179
return result;
31803180
}

clang/lib/CodeGen/CGObjCGNU.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
11031103
bool isNamed = !isNonASCII;
11041104
if (isNamed) {
11051105
StringName = ".objc_str_";
1106-
for (int i=0,e=Str.size() ; i<e ; ++i) {
1107-
unsigned char c = Str[i];
1106+
for (unsigned char c : Str) {
11081107
if (isalnum(c))
11091108
StringName += c;
11101109
else if (c == ' ')
@@ -2560,10 +2559,9 @@ llvm::Value *CGObjCGNU::GetTypedSelector(CodeGenFunction &CGF, Selector Sel,
25602559
SmallVectorImpl<TypedSelector> &Types = SelectorTable[Sel];
25612560
llvm::GlobalAlias *SelValue = nullptr;
25622561

2563-
for (SmallVectorImpl<TypedSelector>::iterator i = Types.begin(),
2564-
e = Types.end() ; i!=e ; i++) {
2565-
if (i->first == TypeEncoding) {
2566-
SelValue = i->second;
2562+
for (const TypedSelector &Type : Types) {
2563+
if (Type.first == TypeEncoding) {
2564+
SelValue = Type.second;
25672565
break;
25682566
}
25692567
}
@@ -3333,13 +3331,12 @@ CGObjCGNU::GenerateProtocolList(ArrayRef<std::string> Protocols) {
33333331
ProtocolList.addInt(LongTy, Protocols.size());
33343332

33353333
auto Elements = ProtocolList.beginArray(PtrToInt8Ty);
3336-
for (const std::string *iter = Protocols.begin(), *endIter = Protocols.end();
3337-
iter != endIter ; iter++) {
3334+
for (const std::string &Protocol : Protocols) {
33383335
llvm::Constant *protocol = nullptr;
3339-
llvm::StringMap<llvm::Constant*>::iterator value =
3340-
ExistingProtocols.find(*iter);
3336+
llvm::StringMap<llvm::Constant *>::iterator value =
3337+
ExistingProtocols.find(Protocol);
33413338
if (value == ExistingProtocols.end()) {
3342-
protocol = GenerateEmptyProtocol(*iter);
3339+
protocol = GenerateEmptyProtocol(Protocol);
33433340
} else {
33443341
protocol = value->getValue();
33453342
}

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,8 +2702,8 @@ llvm::Constant *CGObjCCommonMac::getBitmapBlockLayout(bool ComputeByrefLayout) {
27022702
unsigned char inst = (BLOCK_LAYOUT_OPERATOR << 4) | 0;
27032703
Layout.push_back(inst);
27042704
std::string BitMap;
2705-
for (unsigned i = 0, e = Layout.size(); i != e; i++)
2706-
BitMap += Layout[i];
2705+
for (unsigned char C : Layout)
2706+
BitMap += C;
27072707

27082708
if (CGM.getLangOpts().ObjCGCBitmapPrint) {
27092709
if (ComputeByrefLayout)
@@ -4225,9 +4225,8 @@ FragileHazards::FragileHazards(CodeGenFunction &CGF) : CGF(CGF) {
42254225
return;
42264226

42274227
// Collect all the blocks in the function.
4228-
for (llvm::Function::iterator I = CGF.CurFn->begin(), E = CGF.CurFn->end();
4229-
I != E; ++I)
4230-
BlocksBeforeTry.insert(&*I);
4228+
for (llvm::BasicBlock &BB : *CGF.CurFn)
4229+
BlocksBeforeTry.insert(&BB);
42314230

42324231
llvm::FunctionType *AsmFnTy = GetAsmFnType();
42334232

@@ -4299,9 +4298,7 @@ void FragileHazards::emitHazardsInNewBlocks() {
42994298
CGBuilderTy Builder(CGF, CGF.getLLVMContext());
43004299

43014300
// Iterate through all blocks, skipping those prior to the try.
4302-
for (llvm::Function::iterator FI = CGF.CurFn->begin(), FE = CGF.CurFn->end();
4303-
FI != FE; ++FI) {
4304-
llvm::BasicBlock &BB = *FI;
4301+
for (llvm::BasicBlock &BB : *CGF.CurFn) {
43054302
if (BlocksBeforeTry.count(&BB))
43064303
continue;
43074304

@@ -4348,10 +4345,9 @@ void FragileHazards::collectLocals() {
43484345
// Collect all the allocas currently in the function. This is
43494346
// probably way too aggressive.
43504347
llvm::BasicBlock &Entry = CGF.CurFn->getEntryBlock();
4351-
for (llvm::BasicBlock::iterator I = Entry.begin(), E = Entry.end(); I != E;
4352-
++I)
4353-
if (isa<llvm::AllocaInst>(*I) && !AllocasToIgnore.count(&*I))
4354-
Locals.push_back(&*I);
4348+
for (llvm::Instruction &I : Entry)
4349+
if (isa<llvm::AllocaInst>(I) && !AllocasToIgnore.count(&I))
4350+
Locals.push_back(&I);
43554351
}
43564352

43574353
llvm::FunctionType *FragileHazards::GetAsmFnType() {

clang/lib/CodeGen/CGObjCRuntime.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,7 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
220220
CGBuilderTy::InsertPoint SavedIP = CGF.Builder.saveAndClearIP();
221221

222222
// Emit the handlers.
223-
for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {
224-
CatchHandler &Handler = Handlers[I];
225-
223+
for (CatchHandler &Handler : Handlers) {
226224
CGF.EmitBlock(Handler.Block);
227225

228226
CodeGenFunction::LexicalScope Cleanups(CGF, Handler.Body->getSourceRange());

0 commit comments

Comments
 (0)