From 7d6dc15f6c20f1c9dd90f65bff508c52f2958f53 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 30 Sep 2018 21:41:11 +0000 Subject: [PATCH] Use the container form llvm::sort(C, ...) There are a few leftovers of rC343147 that are not (\w+)\.begin but in the form of ([-[:alnum:]>.]+)\.begin or spanning two lines. Change them to use the container form in this commit. The 12 occurrences have been inspected manually for safety. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343425 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Serialization/ContinuousRangeMap.h | 2 +- lib/AST/ASTContext.cpp | 11 +++++------ lib/AST/VTableBuilder.cpp | 13 ++++++------- lib/ASTMatchers/Dynamic/Parser.cpp | 10 +++++----- lib/Basic/Targets.cpp | 2 +- lib/CodeGen/CodeGenModule.cpp | 5 ++--- lib/Frontend/CompilerInvocation.cpp | 4 ++-- lib/Sema/SemaDecl.cpp | 4 ++-- utils/TableGen/ClangAttrEmitter.cpp | 4 ++-- utils/TableGen/ClangDiagnosticsEmitter.cpp | 2 +- 10 files changed, 27 insertions(+), 30 deletions(-) diff --git a/include/clang/Serialization/ContinuousRangeMap.h b/include/clang/Serialization/ContinuousRangeMap.h index 73bf2ed10f..ad827e37db 100644 --- a/include/clang/Serialization/ContinuousRangeMap.h +++ b/include/clang/Serialization/ContinuousRangeMap.h @@ -118,7 +118,7 @@ public: Builder &operator=(const Builder&) = delete; ~Builder() { - llvm::sort(Self.Rep.begin(), Self.Rep.end(), Compare()); + llvm::sort(Self.Rep, Compare()); std::unique(Self.Rep.begin(), Self.Rep.end(), [](const_reference A, const_reference B) { // FIXME: we should not allow any duplicate keys, but there are a lot of diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 3d0d1e666c..21bdc096ae 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -2295,12 +2295,11 @@ structHasUniqueObjectRepresentations(const ASTContext &Context, } } - llvm::sort( - Bases.begin(), Bases.end(), [&](const std::pair &L, - const std::pair &R) { - return Layout.getBaseClassOffset(L.first->getAsCXXRecordDecl()) < - Layout.getBaseClassOffset(R.first->getAsCXXRecordDecl()); - }); + llvm::sort(Bases, [&](const std::pair &L, + const std::pair &R) { + return Layout.getBaseClassOffset(L.first->getAsCXXRecordDecl()) < + Layout.getBaseClassOffset(R.first->getAsCXXRecordDecl()); + }); for (const auto Base : Bases) { int64_t BaseOffset = Context.toBits( diff --git a/lib/AST/VTableBuilder.cpp b/lib/AST/VTableBuilder.cpp index 46844daf3b..81e3c94780 100644 --- a/lib/AST/VTableBuilder.cpp +++ b/lib/AST/VTableBuilder.cpp @@ -2205,13 +2205,12 @@ VTableLayout::VTableLayout(ArrayRef VTableIndices, else this->VTableIndices = OwningArrayRef(VTableIndices); - llvm::sort(this->VTableThunks.begin(), this->VTableThunks.end(), - [](const VTableLayout::VTableThunkTy &LHS, - const VTableLayout::VTableThunkTy &RHS) { - assert((LHS.first != RHS.first || LHS.second == RHS.second) && - "Different thunks should have unique indices!"); - return LHS.first < RHS.first; - }); + llvm::sort(this->VTableThunks, [](const VTableLayout::VTableThunkTy &LHS, + const VTableLayout::VTableThunkTy &RHS) { + assert((LHS.first != RHS.first || LHS.second == RHS.second) && + "Different thunks should have unique indices!"); + return LHS.first < RHS.first; + }); } VTableLayout::~VTableLayout() { } diff --git a/lib/ASTMatchers/Dynamic/Parser.cpp b/lib/ASTMatchers/Dynamic/Parser.cpp index 96362cd4bc..2f6238b546 100644 --- a/lib/ASTMatchers/Dynamic/Parser.cpp +++ b/lib/ASTMatchers/Dynamic/Parser.cpp @@ -645,12 +645,12 @@ Parser::completeExpression(StringRef Code, unsigned CompletionOffset, Sema *S, P.parseExpressionImpl(&Dummy); // Sort by specificity, then by name. - llvm::sort(P.Completions.begin(), P.Completions.end(), + llvm::sort(P.Completions, [](const MatcherCompletion &A, const MatcherCompletion &B) { - if (A.Specificity != B.Specificity) - return A.Specificity > B.Specificity; - return A.TypedText < B.TypedText; - }); + if (A.Specificity != B.Specificity) + return A.Specificity > B.Specificity; + return A.TypedText < B.TypedText; + }); return P.Completions; } diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 1ef2fe3b81..1a2f4145f1 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -640,7 +640,7 @@ TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags, Opts->Features.push_back((F.getValue() ? "+" : "-") + F.getKey().str()); // Sort here, so we handle the features in a predictable order. (This matters // when we're dealing with features that overlap.) - llvm::sort(Opts->Features.begin(), Opts->Features.end()); + llvm::sort(Opts->Features); if (!Target->handleTargetFeatures(Opts->Features, Diags)) return nullptr; diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index c2fb4797cc..dbea1fc711 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -2554,9 +2554,8 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) { } llvm::sort( - Options.begin(), Options.end(), - [](const CodeGenFunction::MultiVersionResolverOption &LHS, - const CodeGenFunction::MultiVersionResolverOption &RHS) { + Options, [](const CodeGenFunction::MultiVersionResolverOption &LHS, + const CodeGenFunction::MultiVersionResolverOption &RHS) { return CodeGenFunction::GetX86CpuSupportsMask(LHS.Conditions.Features) > CodeGenFunction::GetX86CpuSupportsMask(RHS.Conditions.Features); }); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 782c796452..d423661501 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1339,7 +1339,7 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, Success = false; } else - llvm::sort(Opts.VerifyPrefixes.begin(), Opts.VerifyPrefixes.end()); + llvm::sort(Opts.VerifyPrefixes); DiagnosticLevelMask DiagMask = DiagnosticLevelMask::None; Success &= parseDiagnosticLevelMask("-verify-ignore-unexpected=", Args.getAllArgValues(OPT_verify_ignore_unexpected_EQ), @@ -2502,7 +2502,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.CurrentModule = Opts.ModuleName; Opts.AppExt = Args.hasArg(OPT_fapplication_extension); Opts.ModuleFeatures = Args.getAllArgValues(OPT_fmodule_feature); - llvm::sort(Opts.ModuleFeatures.begin(), Opts.ModuleFeatures.end()); + llvm::sort(Opts.ModuleFeatures); Opts.NativeHalfType |= Args.hasArg(OPT_fnative_half_type); Opts.NativeHalfArgsAndReturns |= Args.hasArg(OPT_fnative_half_arguments_and_returns); // Enable HalfArgsAndReturns if present in Args or if NativeHalfArgsAndReturns diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index d02b971230..f5ba87f635 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -9596,7 +9596,7 @@ static bool CheckTargetCausesMultiVersioning( const auto *OldTA = OldFD->getAttr(); TargetAttr::ParsedTargetAttr NewParsed = NewTA->parse(); // Sort order doesn't matter, it just needs to be consistent. - llvm::sort(NewParsed.Features.begin(), NewParsed.Features.end()); + llvm::sort(NewParsed.Features); // If the old decl is NOT MultiVersioned yet, and we don't cause that // to change, this is a simple redeclaration. @@ -9682,7 +9682,7 @@ static bool CheckMultiVersionAdditionalDecl( TargetAttr::ParsedTargetAttr NewParsed; if (NewTA) { NewParsed = NewTA->parse(); - llvm::sort(NewParsed.Features.begin(), NewParsed.Features.end()); + llvm::sort(NewParsed.Features); } bool UseMemberUsingDeclRules = diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp index 5386ea6c31..59eab39773 100644 --- a/utils/TableGen/ClangAttrEmitter.cpp +++ b/utils/TableGen/ClangAttrEmitter.cpp @@ -3961,10 +3961,10 @@ void EmitClangAttrDocs(RecordKeeper &Records, raw_ostream &OS) { for (auto &I : SplitDocs) { WriteCategoryHeader(I.first, OS); - llvm::sort(I.second.begin(), I.second.end(), + llvm::sort(I.second, [](const DocumentationData &D1, const DocumentationData &D2) { return D1.Heading < D2.Heading; - }); + }); // Walk over each of the attributes in the category and write out their // documentation. diff --git a/utils/TableGen/ClangDiagnosticsEmitter.cpp b/utils/TableGen/ClangDiagnosticsEmitter.cpp index 782b713073..f551d93282 100644 --- a/utils/TableGen/ClangDiagnosticsEmitter.cpp +++ b/utils/TableGen/ClangDiagnosticsEmitter.cpp @@ -1763,7 +1763,7 @@ void EmitClangDiagDocs(RecordKeeper &Records, raw_ostream &OS) { OS << "Also controls "; bool First = true; - llvm::sort(GroupInfo.SubGroups.begin(), GroupInfo.SubGroups.end()); + llvm::sort(GroupInfo.SubGroups); for (const auto &Name : GroupInfo.SubGroups) { if (!First) OS << ", "; OS << "`" << (IsRemarkGroup ? "-R" : "-W") << Name << "`_"; -- 2.40.0