Skip to content

Commit eb1c7c1

Browse files
[AST, Analysis] Use llvm::reverse (NFC)
1 parent db27867 commit eb1c7c1

File tree

6 files changed

+29
-45
lines changed

6 files changed

+29
-45
lines changed

clang/lib/AST/Expr.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -753,11 +753,10 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, const Decl *CurrentDecl) {
753753

754754
std::string TemplateParams;
755755
llvm::raw_string_ostream TOut(TemplateParams);
756-
for (SpecsTy::reverse_iterator I = Specs.rbegin(), E = Specs.rend();
757-
I != E; ++I) {
758-
const TemplateParameterList *Params
759-
= (*I)->getSpecializedTemplate()->getTemplateParameters();
760-
const TemplateArgumentList &Args = (*I)->getTemplateArgs();
756+
for (const ClassTemplateSpecializationDecl *D : llvm::reverse(Specs)) {
757+
const TemplateParameterList *Params =
758+
D->getSpecializedTemplate()->getTemplateParameters();
759+
const TemplateArgumentList &Args = D->getTemplateArgs();
761760
assert(Params->size() == Args.size());
762761
for (unsigned i = 0, numParams = Params->size(); i != numParams; ++i) {
763762
StringRef Param = Params->getParam(i)->getName();
@@ -2361,10 +2360,8 @@ SourceLocation InitListExpr::getEndLoc() const {
23612360
SourceLocation End = RBraceLoc;
23622361
if (End.isInvalid()) {
23632362
// Find the first non-null initializer from the end.
2364-
for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(),
2365-
E = InitExprs.rend();
2366-
I != E; ++I) {
2367-
if (Stmt *S = *I) {
2363+
for (Stmt *S : llvm::reverse(InitExprs)) {
2364+
if (S) {
23682365
End = S->getEndLoc();
23692366
break;
23702367
}

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,8 +2825,8 @@ void MicrosoftCXXNameMangler::mangleArtificialTagType(
28252825
// Always start with the unqualified name.
28262826
mangleSourceName(UnqualifiedName);
28272827

2828-
for (auto I = NestedNames.rbegin(), E = NestedNames.rend(); I != E; ++I)
2829-
mangleSourceName(*I);
2828+
for (StringRef N : llvm::reverse(NestedNames))
2829+
mangleSourceName(N);
28302830

28312831
// Terminate the whole name with an '@'.
28322832
Out << '@';

clang/lib/AST/VTableBuilder.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,8 +1418,7 @@ FindNearestOverriddenMethod(const CXXMethodDecl *MD,
14181418
OverriddenMethodsSetTy OverriddenMethods;
14191419
ComputeAllOverriddenMethods(MD, OverriddenMethods);
14201420

1421-
for (const CXXRecordDecl *PrimaryBase :
1422-
llvm::make_range(Bases.rbegin(), Bases.rend())) {
1421+
for (const CXXRecordDecl *PrimaryBase : llvm::reverse(Bases)) {
14231422
// Now check the overridden methods.
14241423
for (const CXXMethodDecl *OverriddenMD : OverriddenMethods) {
14251424
// We found our overridden method.
@@ -3098,8 +3097,7 @@ void VFTableBuilder::AddMethods(BaseSubobject Base, unsigned BaseDepth,
30983097
}
30993098

31003099
static void PrintBasePath(const VPtrInfo::BasePath &Path, raw_ostream &Out) {
3101-
for (const CXXRecordDecl *Elem :
3102-
llvm::make_range(Path.rbegin(), Path.rend())) {
3100+
for (const CXXRecordDecl *Elem : llvm::reverse(Path)) {
31033101
Out << "'";
31043102
Elem->printQualifiedName(Out);
31053103
Out << "' in ";

clang/lib/Analysis/CFG.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,16 +1801,11 @@ void CFGBuilder::addLifetimeEnds(LocalScope::const_iterator B,
18011801
autoCreateBlock();
18021802
// object with trivial destructor end their lifetime last (when storage
18031803
// duration ends)
1804-
for (SmallVectorImpl<VarDecl *>::reverse_iterator I = DeclsTrivial.rbegin(),
1805-
E = DeclsTrivial.rend();
1806-
I != E; ++I)
1807-
appendLifetimeEnds(Block, *I, S);
1804+
for (VarDecl *VD : llvm::reverse(DeclsTrivial))
1805+
appendLifetimeEnds(Block, VD, S);
18081806

1809-
for (SmallVectorImpl<VarDecl *>::reverse_iterator
1810-
I = DeclsNonTrivial.rbegin(),
1811-
E = DeclsNonTrivial.rend();
1812-
I != E; ++I)
1813-
appendLifetimeEnds(Block, *I, S);
1807+
for (VarDecl *VD : llvm::reverse(DeclsNonTrivial))
1808+
appendLifetimeEnds(Block, VD, S);
18141809
}
18151810

18161811
/// Add to current block markers for ending scopes.
@@ -1823,9 +1818,8 @@ void CFGBuilder::addScopesEnd(LocalScope::const_iterator B,
18231818

18241819
autoCreateBlock();
18251820

1826-
for (auto I = DeclsWithEndedScope.rbegin(), E = DeclsWithEndedScope.rend();
1827-
I != E; ++I)
1828-
appendScopeEnd(Block, *I, S);
1821+
for (VarDecl *VD : llvm::reverse(DeclsWithEndedScope))
1822+
appendScopeEnd(Block, VD, S);
18291823

18301824
return;
18311825
}
@@ -1850,24 +1844,22 @@ void CFGBuilder::addAutomaticObjDtors(LocalScope::const_iterator B,
18501844
for (LocalScope::const_iterator I = B; I != E; ++I)
18511845
Decls.push_back(*I);
18521846

1853-
for (SmallVectorImpl<VarDecl*>::reverse_iterator I = Decls.rbegin(),
1854-
E = Decls.rend();
1855-
I != E; ++I) {
1856-
if (hasTrivialDestructor(*I)) {
1847+
for (VarDecl *VD : llvm::reverse(Decls)) {
1848+
if (hasTrivialDestructor(VD)) {
18571849
// If AddScopes is enabled and *I is a first variable in a scope, add a
18581850
// ScopeEnd marker in a Block.
1859-
if (BuildOpts.AddScopes && DeclsWithEndedScope.count(*I)) {
1851+
if (BuildOpts.AddScopes && DeclsWithEndedScope.count(VD)) {
18601852
autoCreateBlock();
1861-
appendScopeEnd(Block, *I, S);
1853+
appendScopeEnd(Block, VD, S);
18621854
}
18631855
continue;
18641856
}
18651857
// If this destructor is marked as a no-return destructor, we need to
18661858
// create a new block for the destructor which does not have as a successor
18671859
// anything built thus far: control won't flow out of this block.
1868-
QualType Ty = (*I)->getType();
1860+
QualType Ty = VD->getType();
18691861
if (Ty->isReferenceType()) {
1870-
Ty = getReferenceInitTemporaryType((*I)->getInit());
1862+
Ty = getReferenceInitTemporaryType(VD->getInit());
18711863
}
18721864
Ty = Context->getBaseElementType(Ty);
18731865

@@ -1877,9 +1869,9 @@ void CFGBuilder::addAutomaticObjDtors(LocalScope::const_iterator B,
18771869
autoCreateBlock();
18781870

18791871
// Add ScopeEnd just after automatic obj destructor.
1880-
if (BuildOpts.AddScopes && DeclsWithEndedScope.count(*I))
1881-
appendScopeEnd(Block, *I, S);
1882-
appendAutomaticObjDtor(Block, *I, S);
1872+
if (BuildOpts.AddScopes && DeclsWithEndedScope.count(VD))
1873+
appendScopeEnd(Block, VD, S);
1874+
appendAutomaticObjDtor(Block, VD, S);
18831875
}
18841876
}
18851877

clang/lib/Analysis/CloneDetection.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ void OnlyLargestCloneConstraint::constrain(
147147
// Erasing a list of indexes from the vector should be done with decreasing
148148
// indexes. As IndexesToRemove is constructed with increasing values, we just
149149
// reverse iterate over it to get the desired order.
150-
for (auto I = IndexesToRemove.rbegin(); I != IndexesToRemove.rend(); ++I) {
151-
Result.erase(Result.begin() + *I);
152-
}
150+
for (unsigned I : llvm::reverse(IndexesToRemove))
151+
Result.erase(Result.begin() + I);
153152
}
154153

155154
bool FilenamePatternConstraint::isAutoGenerated(

clang/lib/Analysis/ReachableCode.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ static bool isDeadReturn(const CFGBlock *B, const Stmt *S) {
8787
// block, or may be in a subsequent block because of destructors.
8888
const CFGBlock *Current = B;
8989
while (true) {
90-
for (CFGBlock::const_reverse_iterator I = Current->rbegin(),
91-
E = Current->rend();
92-
I != E; ++I) {
93-
if (Optional<CFGStmt> CS = I->getAs<CFGStmt>()) {
90+
for (const CFGElement &CE : llvm::reverse(*Current)) {
91+
if (Optional<CFGStmt> CS = CE.getAs<CFGStmt>()) {
9492
if (const ReturnStmt *RS = dyn_cast<ReturnStmt>(CS->getStmt())) {
9593
if (RS == S)
9694
return true;

0 commit comments

Comments
 (0)