Skip to content

Commit

Permalink
[clang] Use range-based for loops with llvm::reverse (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Nov 18, 2021
1 parent 9722191 commit 7411560
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 27 deletions.
14 changes: 5 additions & 9 deletions clang/lib/Driver/SanitizerArgs.cpp
Expand Up @@ -223,9 +223,7 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
SanitizerMask TrappingKinds;
SanitizerMask TrappingSupportedWithGroups = setGroupBits(TrappingSupported);

for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend();
I != E; ++I) {
const auto *Arg = *I;
for (const llvm::opt::Arg *Arg : llvm::reverse(Args)) {
if (Arg->getOption().matches(options::OPT_fsanitize_trap_EQ)) {
Arg->claim();
SanitizerMask Add = parseArgValues(D, Arg, true);
Expand Down Expand Up @@ -322,9 +320,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
bool RemoveObjectSizeAtO0 =
!OptLevel || OptLevel->getOption().matches(options::OPT_O0);

for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend();
I != E; ++I) {
const auto *Arg = *I;
for (const llvm::opt::Arg *Arg : llvm::reverse(Args)) {
if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) {
Arg->claim();
SanitizerMask Add = parseArgValues(D, Arg, DiagnoseErrors);
Expand All @@ -349,7 +345,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
if (SanitizerMask KindsToDiagnose =
Add & InvalidTrappingKinds & ~DiagnosedKinds) {
if (DiagnoseErrors) {
std::string Desc = describeSanitizeArg(*I, KindsToDiagnose);
std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
D.Diag(diag::err_drv_argument_not_allowed_with)
<< Desc << "-fsanitize-trap=undefined";
}
Expand All @@ -361,7 +357,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
if (SanitizerMask KindsToDiagnose =
Add & NotAllowedWithMinimalRuntime & ~DiagnosedKinds) {
if (DiagnoseErrors) {
std::string Desc = describeSanitizeArg(*I, KindsToDiagnose);
std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
D.Diag(diag::err_drv_argument_not_allowed_with)
<< Desc << "-fsanitize-minimal-runtime";
}
Expand Down Expand Up @@ -391,7 +387,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,

if (SanitizerMask KindsToDiagnose = Add & ~Supported & ~DiagnosedKinds) {
if (DiagnoseErrors) {
std::string Desc = describeSanitizeArg(*I, KindsToDiagnose);
std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< Desc << TC.getTriple().str();
}
Expand Down
6 changes: 2 additions & 4 deletions clang/lib/Serialization/ASTWriter.cpp
Expand Up @@ -3429,11 +3429,9 @@ class ASTIdentifierTableTrait {
// Only emit declarations that aren't from a chained PCH, though.
SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II),
IdResolver.end());
for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(),
DEnd = Decls.rend();
D != DEnd; ++D)
for (NamedDecl *D : llvm::reverse(Decls))
LE.write<uint32_t>(
Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D)));
Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), D)));
}
}
};
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/Serialization/ModuleManager.cpp
Expand Up @@ -383,16 +383,14 @@ void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor,

// For any module that this module depends on, push it on the
// stack (if it hasn't already been marked as visited).
for (auto M = CurrentModule->Imports.rbegin(),
MEnd = CurrentModule->Imports.rend();
M != MEnd; ++M) {
for (ModuleFile *M : llvm::reverse(CurrentModule->Imports)) {
// Remove our current module as an impediment to visiting the
// module we depend on. If we were the last unvisited module
// that depends on this particular module, push it into the
// queue to be visited.
unsigned &NumUnusedEdges = UnusedIncomingEdges[(*M)->Index];
unsigned &NumUnusedEdges = UnusedIncomingEdges[M->Index];
if (NumUnusedEdges && (--NumUnusedEdges == 0))
Queue.push_back(*M);
Queue.push_back(M);
}
}

Expand Down
3 changes: 1 addition & 2 deletions clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
Expand Up @@ -393,8 +393,7 @@ ProgramStateRef ExprEngine::createTemporaryRegionIfNeeded(
SVal BaseReg = Reg;

// Make the necessary adjustments to obtain the sub-object.
for (auto I = Adjustments.rbegin(), E = Adjustments.rend(); I != E; ++I) {
const SubobjectAdjustment &Adj = *I;
for (const SubobjectAdjustment &Adj : llvm::reverse(Adjustments)) {
switch (Adj.Kind) {
case SubobjectAdjustment::DerivedToBaseAdjustment:
Reg = StoreMgr.evalDerivedToBase(Reg, Adj.DerivedToBase.BasePath);
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
Expand Up @@ -757,9 +757,8 @@ void ExprEngine::VisitInitListExpr(const InitListExpr *IE,
return;
}

for (InitListExpr::const_reverse_iterator it = IE->rbegin(),
ei = IE->rend(); it != ei; ++it) {
SVal V = state->getSVal(cast<Expr>(*it), LCtx);
for (const Stmt *S : llvm::reverse(*IE)) {
SVal V = state->getSVal(cast<Expr>(S), LCtx);
vals = getBasicVals().prependSVal(V, vals);
}

Expand Down
8 changes: 4 additions & 4 deletions clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
Expand Up @@ -792,8 +792,8 @@ void HTMLDiagnostics::RewriteFile(Rewriter &R, const PathPieces &path,

// Stores the different ranges where we have reported something.
std::vector<SourceRange> PopUpRanges;
for (auto I = path.rbegin(), E = path.rend(); I != E; ++I) {
const auto &Piece = *I->get();
for (const PathDiagnosticPieceRef &I : llvm::reverse(path)) {
const auto &Piece = *I.get();

if (isa<PathDiagnosticPopUpPiece>(Piece)) {
++IndexMap[NumRegularPieces];
Expand Down Expand Up @@ -835,8 +835,8 @@ void HTMLDiagnostics::RewriteFile(Rewriter &R, const PathPieces &path,
// Secondary indexing if we are having multiple pop-ups between two notes.
// (e.g. [(13) 'a' is 'true']; [(13.1) 'b' is 'false']; [(13.2) 'c' is...)
NumRegularPieces = TotalRegularPieces;
for (auto I = path.rbegin(), E = path.rend(); I != E; ++I) {
const auto &Piece = *I->get();
for (const PathDiagnosticPieceRef &I : llvm::reverse(path)) {
const auto &Piece = *I.get();

if (const auto *PopUpP = dyn_cast<PathDiagnosticPopUpPiece>(&Piece)) {
int PopUpPieceIndex = IndexMap[NumRegularPieces];
Expand Down

0 comments on commit 7411560

Please sign in to comment.