Author: Dmitri Gribenko Date: 2022-07-23T15:13:25+02:00 New Revision: cd9a5cfd2e4e4d583c9bf5ef1100acaf5e96f29e
URL: https://github.com/llvm/llvm-project/commit/cd9a5cfd2e4e4d583c9bf5ef1100acaf5e96f29e DIFF: https://github.com/llvm/llvm-project/commit/cd9a5cfd2e4e4d583c9bf5ef1100acaf5e96f29e.diff LOG: Use the range-based overload of llvm::sort where possible Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D130403 Added: Modified: clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp clang-tools-extra/clang-include-fixer/SymbolIndexManager.cpp clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp clang-tools-extra/clangd/index/StdLib.cpp clang/include/clang/Basic/Attr.td clang/lib/Driver/Multilib.cpp clang/lib/Frontend/FrontendAction.cpp clang/lib/Sema/AnalysisBasedWarnings.cpp lldb/source/Interpreter/OptionValueArray.cpp lldb/source/Interpreter/OptionValueFileSpecList.cpp lldb/source/Interpreter/OptionValuePathMappings.cpp lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp lldb/source/Symbol/ArmUnwindInfo.cpp lldb/source/Symbol/CompileUnit.cpp lldb/source/Symbol/Symtab.cpp lldb/source/Target/DynamicRegisterInfo.cpp lldb/source/Target/Target.cpp lldb/source/Utility/ReproducerProvider.cpp lldb/source/Utility/Timer.cpp llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp llvm/unittests/ADT/SmallPtrSetTest.cpp llvm/unittests/TextAPI/TextStubV1Tests.cpp llvm/unittests/TextAPI/TextStubV2Tests.cpp llvm/unittests/TextAPI/TextStubV3Tests.cpp llvm/unittests/TextAPI/TextStubV4Tests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp index e25c8e2449dc8..cb5caf1ca92a1 100644 --- a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp +++ b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp @@ -193,8 +193,7 @@ groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs, // Sort replacements per file to keep consistent behavior when // clang-apply-replacements run on diff erents machine. for (auto &FileAndReplacements : GroupedReplacements) { - llvm::sort(FileAndReplacements.second.begin(), - FileAndReplacements.second.end()); + llvm::sort(FileAndReplacements.second); } return GroupedReplacements; diff --git a/clang-tools-extra/clang-include-fixer/SymbolIndexManager.cpp b/clang-tools-extra/clang-include-fixer/SymbolIndexManager.cpp index ebb4a70c1f8db..95b5ed0a8b1aa 100644 --- a/clang-tools-extra/clang-include-fixer/SymbolIndexManager.cpp +++ b/clang-tools-extra/clang-include-fixer/SymbolIndexManager.cpp @@ -59,7 +59,7 @@ static void rank(std::vector<SymbolAndSignals> &Symbols, } // Sort by the gathered scores. Use file name as a tie breaker so we can // deduplicate. - llvm::sort(Symbols.begin(), Symbols.end(), + llvm::sort(Symbols, [&](const SymbolAndSignals &A, const SymbolAndSignals &B) { auto AS = Score[A.Symbol.getFilePath()]; auto BS = Score[B.Symbol.getFilePath()]; diff --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp index 0209071af87f4..1d15ae19ead4d 100644 --- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp @@ -104,10 +104,8 @@ MagicNumbersCheck::MagicNumbersCheck(StringRef Name, ClangTidyContext *Context) consumeError(StatusOrErr.takeError()); IgnoredDoublePointValues.push_back(DoubleValue.convertToDouble()); } - llvm::sort(IgnoredFloatingPointValues.begin(), - IgnoredFloatingPointValues.end()); - llvm::sort(IgnoredDoublePointValues.begin(), - IgnoredDoublePointValues.end()); + llvm::sort(IgnoredFloatingPointValues); + llvm::sort(IgnoredDoublePointValues); } } diff --git a/clang-tools-extra/clangd/index/StdLib.cpp b/clang-tools-extra/clangd/index/StdLib.cpp index f00067229a860..f2edc514bae30 100644 --- a/clang-tools-extra/clangd/index/StdLib.cpp +++ b/clang-tools-extra/clangd/index/StdLib.cpp @@ -80,7 +80,7 @@ std::string buildUmbrella(llvm::StringLiteral Mandatory, "#endif\n", Mandatory); - llvm::sort(Headers.begin(), Headers.end()); + llvm::sort(Headers); auto Last = std::unique(Headers.begin(), Headers.end()); for (auto Header = Headers.begin(); Header != Last; ++Header) { OS << llvm::formatv("#if __has_include({0})\n" diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 78e0fce917a0f..d61f3583281d1 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -2703,7 +2703,7 @@ def Target : InheritableAttr { template<class Compare> ParsedTargetAttr parse(Compare cmp) const { ParsedTargetAttr Attrs = parse(); - llvm::sort(std::begin(Attrs.Features), std::end(Attrs.Features), cmp); + llvm::sort(Attrs.Features, cmp); return Attrs; } diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp index ab44ba50b5d52..ec619874ad607 100644 --- a/clang/lib/Driver/Multilib.cpp +++ b/clang/lib/Driver/Multilib.cpp @@ -267,10 +267,9 @@ bool MultilibSet::select(const Multilib::flags_list &Flags, Multilib &M) const { } // Sort multilibs by priority and select the one with the highest priority. - llvm::sort(Filtered.begin(), Filtered.end(), - [](const Multilib &a, const Multilib &b) -> bool { - return a.priority() > b.priority(); - }); + llvm::sort(Filtered, [](const Multilib &a, const Multilib &b) -> bool { + return a.priority() > b.priority(); + }); if (Filtered[0].priority() > Filtered[1].priority()) { M = Filtered[0]; diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index ed3e314cc73bb..7b07ab948f643 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -414,7 +414,7 @@ static std::error_code collectModuleHeaderIncludes( // Sort header paths and make the header inclusion order deterministic // across diff erent OSs and filesystems. - llvm::sort(Headers.begin(), Headers.end(), llvm::less_first()); + llvm::sort(Headers, llvm::less_first()); for (auto &H : Headers) { // Include this header as part of the umbrella directory. Module->addTopHeader(H.second); @@ -1205,4 +1205,3 @@ bool WrapperFrontendAction::hasCodeCompletionSupport() const { WrapperFrontendAction::WrapperFrontendAction( std::unique_ptr<FrontendAction> WrappedAction) : WrappedAction(std::move(WrappedAction)) {} - diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index 164fea6a449b5..9780a0aba7498 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -1575,8 +1575,7 @@ class UninitValsDiagReporter : public UninitVariablesHandler { // Sort the uses by their SourceLocations. While not strictly // guaranteed to produce them in line/column order, this will provide // a stable ordering. - llvm::sort(vec->begin(), vec->end(), - [](const UninitUse &a, const UninitUse &b) { + llvm::sort(*vec, [](const UninitUse &a, const UninitUse &b) { // Prefer a more confident report over a less confident one. if (a.getKind() != b.getKind()) return a.getKind() > b.getKind(); diff --git a/lldb/source/Interpreter/OptionValueArray.cpp b/lldb/source/Interpreter/OptionValueArray.cpp index 4468fe57702e6..c202a188fe2a1 100644 --- a/lldb/source/Interpreter/OptionValueArray.cpp +++ b/lldb/source/Interpreter/OptionValueArray.cpp @@ -218,7 +218,7 @@ Status OptionValueArray::SetArgs(const Args &args, VarSetOperationType op) { if (num_remove_indexes) { // Sort and then erase in reverse so indexes are always valid if (num_remove_indexes > 1) { - llvm::sort(remove_indexes.begin(), remove_indexes.end()); + llvm::sort(remove_indexes); for (std::vector<int>::const_reverse_iterator pos = remove_indexes.rbegin(), end = remove_indexes.rend(); diff --git a/lldb/source/Interpreter/OptionValueFileSpecList.cpp b/lldb/source/Interpreter/OptionValueFileSpecList.cpp index 6566eee09d738..9b4114e2ceb27 100644 --- a/lldb/source/Interpreter/OptionValueFileSpecList.cpp +++ b/lldb/source/Interpreter/OptionValueFileSpecList.cpp @@ -137,7 +137,7 @@ Status OptionValueFileSpecList::SetValueFromString(llvm::StringRef value, size_t num_remove_indexes = remove_indexes.size(); if (num_remove_indexes) { // Sort and then erase in reverse so indexes are always valid - llvm::sort(remove_indexes.begin(), remove_indexes.end()); + llvm::sort(remove_indexes); for (size_t j = num_remove_indexes - 1; j < num_remove_indexes; ++j) { m_current_value.Remove(j); } diff --git a/lldb/source/Interpreter/OptionValuePathMappings.cpp b/lldb/source/Interpreter/OptionValuePathMappings.cpp index 543b0e1b8ea8a..6096f45646290 100644 --- a/lldb/source/Interpreter/OptionValuePathMappings.cpp +++ b/lldb/source/Interpreter/OptionValuePathMappings.cpp @@ -174,7 +174,7 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value, } // Sort and then erase in reverse so indexes are always valid - llvm::sort(remove_indexes.begin(), remove_indexes.end()); + llvm::sort(remove_indexes); for (auto index : llvm::reverse(remove_indexes)) m_path_mappings.Remove(index, m_notify_changes); NotifyValueChanged(); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp index 1bf29efb0bee2..f8443d608ac3a 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -1430,10 +1430,9 @@ static bool ImportOffsetMap(llvm::DenseMap<const D *, O> &destination_map, std::vector<PairType> sorted_items; sorted_items.reserve(source_map.size()); sorted_items.assign(source_map.begin(), source_map.end()); - llvm::sort(sorted_items.begin(), sorted_items.end(), - [](const PairType &lhs, const PairType &rhs) { - return lhs.second < rhs.second; - }); + llvm::sort(sorted_items, [](const PairType &lhs, const PairType &rhs) { + return lhs.second < rhs.second; + }); for (const auto &item : sorted_items) { DeclFromUser<D> user_decl(const_cast<D *>(item.first)); diff --git a/lldb/source/Symbol/ArmUnwindInfo.cpp b/lldb/source/Symbol/ArmUnwindInfo.cpp index 07852485f44e2..ae6cddfbc4639 100644 --- a/lldb/source/Symbol/ArmUnwindInfo.cpp +++ b/lldb/source/Symbol/ArmUnwindInfo.cpp @@ -65,7 +65,7 @@ ArmUnwindInfo::ArmUnwindInfo(ObjectFile &objfile, SectionSP &arm_exidx, // Sort the entries in the exidx section. The entries should be sorted inside // the section but some old compiler isn't sorted them. - llvm::sort(m_exidx_entries.begin(), m_exidx_entries.end()); + llvm::sort(m_exidx_entries); } ArmUnwindInfo::~ArmUnwindInfo() = default; diff --git a/lldb/source/Symbol/CompileUnit.cpp b/lldb/source/Symbol/CompileUnit.cpp index cacb78de24260..2bae08c8b930c 100644 --- a/lldb/source/Symbol/CompileUnit.cpp +++ b/lldb/source/Symbol/CompileUnit.cpp @@ -63,7 +63,7 @@ void CompileUnit::ForeachFunction( sorted_functions.reserve(m_functions_by_uid.size()); for (auto &p : m_functions_by_uid) sorted_functions.push_back(p.second); - llvm::sort(sorted_functions.begin(), sorted_functions.end(), + llvm::sort(sorted_functions, [](const lldb::FunctionSP &a, const lldb::FunctionSP &b) { return a->GetID() < b->GetID(); }); diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp index eb2447efbad1d..936ee04ed492a 100644 --- a/lldb/source/Symbol/Symtab.cpp +++ b/lldb/source/Symbol/Symtab.cpp @@ -1137,7 +1137,7 @@ void Symtab::FindFunctionSymbols(ConstString name, uint32_t name_type_mask, } if (!symbol_indexes.empty()) { - llvm::sort(symbol_indexes.begin(), symbol_indexes.end()); + llvm::sort(symbol_indexes); symbol_indexes.erase( std::unique(symbol_indexes.begin(), symbol_indexes.end()), symbol_indexes.end()); diff --git a/lldb/source/Target/DynamicRegisterInfo.cpp b/lldb/source/Target/DynamicRegisterInfo.cpp index e2962b02ed7f5..14c3faae38dfd 100644 --- a/lldb/source/Target/DynamicRegisterInfo.cpp +++ b/lldb/source/Target/DynamicRegisterInfo.cpp @@ -483,7 +483,7 @@ void DynamicRegisterInfo::Finalize(const ArchSpec &arch) { end = m_invalidate_regs_map.end(); pos != end; ++pos) { if (pos->second.size() > 1) { - llvm::sort(pos->second.begin(), pos->second.end()); + llvm::sort(pos->second); reg_num_collection::iterator unique_end = std::unique(pos->second.begin(), pos->second.end()); if (unique_end != pos->second.end()) diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 292ace6d754c5..6ffe6d3926adf 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -776,7 +776,7 @@ void Target::GetBreakpointNames(std::vector<std::string> &names) { for (auto bp_name : m_breakpoint_names) { names.push_back(bp_name.first.AsCString()); } - llvm::sort(names.begin(), names.end()); + llvm::sort(names); } bool Target::ProcessIsValid() { diff --git a/lldb/source/Utility/ReproducerProvider.cpp b/lldb/source/Utility/ReproducerProvider.cpp index 0d1581abda645..44f24e44f38d7 100644 --- a/lldb/source/Utility/ReproducerProvider.cpp +++ b/lldb/source/Utility/ReproducerProvider.cpp @@ -131,7 +131,7 @@ void SymbolFileProvider::Keep() { return; // Remove duplicates. - llvm::sort(m_symbol_files.begin(), m_symbol_files.end()); + llvm::sort(m_symbol_files); m_symbol_files.erase( std::unique(m_symbol_files.begin(), m_symbol_files.end()), m_symbol_files.end()); diff --git a/lldb/source/Utility/Timer.cpp b/lldb/source/Utility/Timer.cpp index b190f35007d50..477541d7bb3d1 100644 --- a/lldb/source/Utility/Timer.cpp +++ b/lldb/source/Utility/Timer.cpp @@ -150,7 +150,7 @@ void Timer::DumpCategoryTimes(Stream *s) { return; // Later code will break without any elements. // Sort by time - llvm::sort(sorted.begin(), sorted.end(), CategoryMapIteratorSortCriterion); + llvm::sort(sorted, CategoryMapIteratorSortCriterion); for (const auto &stats : sorted) s->Printf("%.9f sec (total: %.3fs; child: %.3fs; count: %" PRIu64 diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index f7d3052c8c4dd..cc7f353330b1d 100644 --- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -544,7 +544,7 @@ static bool collectObjectSources(ObjectFile &Obj, DWARFContext &DICtx, } // Dedup and order the sources. - llvm::sort(Sources.begin(), Sources.end()); + llvm::sort(Sources); Sources.erase(std::unique(Sources.begin(), Sources.end()), Sources.end()); for (StringRef Name : Sources) diff --git a/llvm/unittests/ADT/SmallPtrSetTest.cpp b/llvm/unittests/ADT/SmallPtrSetTest.cpp index 414298c4e67df..a97f2617cbf70 100644 --- a/llvm/unittests/ADT/SmallPtrSetTest.cpp +++ b/llvm/unittests/ADT/SmallPtrSetTest.cpp @@ -299,7 +299,7 @@ TEST(SmallPtrSetTest, dereferenceAndIterate) { // Sort. We should hit the first element just once and the final element N // times. - llvm::sort(std::begin(Found), std::end(Found)); + llvm::sort(Found); for (auto F = std::begin(Found), E = std::end(Found); F != E; ++F) EXPECT_EQ(F - Found + 1, *F); } diff --git a/llvm/unittests/TextAPI/TextStubV1Tests.cpp b/llvm/unittests/TextAPI/TextStubV1Tests.cpp index e1cd64f94b545..a7995df346f8b 100644 --- a/llvm/unittests/TextAPI/TextStubV1Tests.cpp +++ b/llvm/unittests/TextAPI/TextStubV1Tests.cpp @@ -102,7 +102,7 @@ TEST(TBDv1, ReadFile) { ExportedSymbol{Sym->getKind(), std::string(Sym->getName()), Sym->isWeakDefined(), Sym->isThreadLocalValue()}); } - llvm::sort(Exports.begin(), Exports.end()); + llvm::sort(Exports); EXPECT_EQ(sizeof(TBDv1Symbols) / sizeof(ExportedSymbol), Exports.size()); EXPECT_TRUE( diff --git a/llvm/unittests/TextAPI/TextStubV2Tests.cpp b/llvm/unittests/TextAPI/TextStubV2Tests.cpp index cb8493eccf644..a2b4b1a419f40 100644 --- a/llvm/unittests/TextAPI/TextStubV2Tests.cpp +++ b/llvm/unittests/TextAPI/TextStubV2Tests.cpp @@ -103,7 +103,7 @@ TEST(TBDv2, ReadFile) { ExportedSymbol{Sym->getKind(), std::string(Sym->getName()), Sym->isWeakDefined(), Sym->isThreadLocalValue()}); } - llvm::sort(Exports.begin(), Exports.end()); + llvm::sort(Exports); EXPECT_EQ(sizeof(TBDv2Symbols) / sizeof(ExportedSymbol), Exports.size()); EXPECT_TRUE( diff --git a/llvm/unittests/TextAPI/TextStubV3Tests.cpp b/llvm/unittests/TextAPI/TextStubV3Tests.cpp index 61ac44eb0a023..1a42e5440d743 100644 --- a/llvm/unittests/TextAPI/TextStubV3Tests.cpp +++ b/llvm/unittests/TextAPI/TextStubV3Tests.cpp @@ -111,7 +111,7 @@ TEST(TBDv3, ReadFile) { ExportedSymbol{Sym->getKind(), std::string(Sym->getName()), Sym->isWeakDefined(), Sym->isThreadLocalValue()}); } - llvm::sort(Exports.begin(), Exports.end()); + llvm::sort(Exports); EXPECT_EQ(sizeof(TBDv3Symbols) / sizeof(ExportedSymbol), Exports.size()); EXPECT_TRUE( @@ -203,7 +203,7 @@ TEST(TBDv3, ReadMultipleDocuments) { Sym->isWeakDefined(), Sym->isThreadLocalValue()}); } - llvm::sort(Exports.begin(), Exports.end()); + llvm::sort(Exports); EXPECT_EQ(sizeof(TBDv3Symbols) / sizeof(ExportedSymbol), Exports.size()); EXPECT_TRUE( @@ -228,7 +228,7 @@ TEST(TBDv3, ReadMultipleDocuments) { Sym->isWeakDefined(), Sym->isThreadLocalValue()}); } - llvm::sort(Exports.begin(), Exports.end()); + llvm::sort(Exports); ExportedSymbolSeq DocumentSymbols{ {SymbolKind::GlobalSymbol, "_sym5", false, false}, diff --git a/llvm/unittests/TextAPI/TextStubV4Tests.cpp b/llvm/unittests/TextAPI/TextStubV4Tests.cpp index fffbecc37bc62..641f95ff10f29 100644 --- a/llvm/unittests/TextAPI/TextStubV4Tests.cpp +++ b/llvm/unittests/TextAPI/TextStubV4Tests.cpp @@ -125,9 +125,9 @@ TEST(TBDv4, ReadFile) { Sym->isReexported() ? Reexports.emplace_back(std::move(temp)) : Exports.emplace_back(std::move(temp)); } - llvm::sort(Exports.begin(), Exports.end()); - llvm::sort(Reexports.begin(), Reexports.end()); - llvm::sort(Undefineds.begin(), Undefineds.end()); + llvm::sort(Exports); + llvm::sort(Reexports); + llvm::sort(Undefineds); static ExportedSymbol ExpectedExportedSymbols[] = { {SymbolKind::GlobalSymbol, "_symA", false, false}, @@ -296,9 +296,9 @@ TEST(TBDv4, ReadMultipleDocuments) { Sym->isReexported() ? Reexports.emplace_back(std::move(Temp)) : Exports.emplace_back(std::move(Temp)); } - llvm::sort(Exports.begin(), Exports.end()); - llvm::sort(Reexports.begin(), Reexports.end()); - llvm::sort(Undefineds.begin(), Undefineds.end()); + llvm::sort(Exports); + llvm::sort(Reexports); + llvm::sort(Undefineds); static ExportedSymbol ExpectedExportedSymbols[] = { {SymbolKind::GlobalSymbol, "_symA", false, false}, _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits