llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-driver Author: Kazu Hirata (kazutakahirata) <details> <summary>Changes</summary> - **[clang] Use llvm::unique (NFC)** - **[clangd] Use llvm::unique (NFC)** - **[PBQP] Use llvm::interleaved (NFC)** --- Full diff: https://github.com/llvm/llvm-project/pull/136461.diff 21 Files Affected: - (modified) clang-tools-extra/clangd/IncludeFixer.cpp (+1-1) - (modified) clang-tools-extra/clangd/InlayHints.cpp (+1-1) - (modified) clang-tools-extra/clangd/SemanticHighlighting.cpp (+1-1) - (modified) clang-tools-extra/clangd/SourceCode.cpp (+1-1) - (modified) clang-tools-extra/clangd/XRefs.cpp (+13-13) - (modified) clang-tools-extra/clangd/index/FileIndex.cpp (+1-2) - (modified) clang-tools-extra/clangd/index/Relation.cpp (+1-2) - (modified) clang-tools-extra/clangd/index/dex/Trigram.cpp (+1-1) - (modified) clang-tools-extra/clangd/refactor/Rename.cpp (+2-3) - (modified) clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp (+1-3) - (modified) clang/lib/AST/ASTContext.cpp (+1-1) - (modified) clang/lib/AST/ItaniumMangle.cpp (+2-3) - (modified) clang/lib/Driver/ToolChain.cpp (+1-1) - (modified) clang/lib/Driver/XRayArgs.cpp (+1-1) - (modified) clang/lib/Format/Format.cpp (+9-9) - (modified) clang/lib/Sema/SemaDeclAttr.cpp (+2-2) - (modified) clang/lib/Sema/SemaStmt.cpp (+2-4) - (modified) clang/lib/Serialization/ASTWriter.cpp (+1-2) - (modified) clang/utils/TableGen/NeonEmitter.cpp (+1-2) - (modified) clang/utils/TableGen/SveEmitter.cpp (+1-2) - (modified) llvm/include/llvm/CodeGen/PBQP/Math.h (+2-6) ``````````diff diff --git a/clang-tools-extra/clangd/IncludeFixer.cpp b/clang-tools-extra/clangd/IncludeFixer.cpp index 8b74c761d23ca..4ff021c4c390a 100644 --- a/clang-tools-extra/clangd/IncludeFixer.cpp +++ b/clang-tools-extra/clangd/IncludeFixer.cpp @@ -484,7 +484,7 @@ collectAccessibleScopes(Sema &Sem, const DeclarationNameInfo &Typo, Scope *S, /*IncludeGlobalScope=*/false, /*LoadExternal=*/false); llvm::sort(Scopes); - Scopes.erase(std::unique(Scopes.begin(), Scopes.end()), Scopes.end()); + Scopes.erase(llvm::unique(Scopes), Scopes.end()); return Scopes; } diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp index 1b1bcf78c9855..40a824618f782 100644 --- a/clang-tools-extra/clangd/InlayHints.cpp +++ b/clang-tools-extra/clangd/InlayHints.cpp @@ -1194,7 +1194,7 @@ std::vector<InlayHint> inlayHints(ParsedAST &AST, // De-duplicate hints. Duplicates can sometimes occur due to e.g. explicit // template instantiations. llvm::sort(Results); - Results.erase(std::unique(Results.begin(), Results.end()), Results.end()); + Results.erase(llvm::unique(Results), Results.end()); return Results; } diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index 86ca05644c703..dc574dcd11703 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -489,7 +489,7 @@ class HighlightingsBuilder { // Initializer lists can give duplicates of tokens, therefore all tokens // must be deduplicated. llvm::sort(Tokens); - auto Last = std::unique(Tokens.begin(), Tokens.end()); + auto Last = llvm::unique(Tokens); Tokens.erase(Last, Tokens.end()); // Macros can give tokens that have the same source range but conflicting diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 780aaa471dc8b..1e1f7c68350ea 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -864,7 +864,7 @@ std::vector<std::string> visibleNamespaces(llvm::StringRef Code, return true; return LHS < RHS; }); - Found.erase(std::unique(Found.begin(), Found.end()), Found.end()); + Found.erase(llvm::unique(Found), Found.end()); return Found; } diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp index 8b9fffa3f64cd..053e2c044c774 100644 --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -909,13 +909,13 @@ class ReferenceFinder : public index::IndexDataConsumer { return std::tie(LTok, L.Role) < std::tie(RTok, R.Role); }); // We sometimes see duplicates when parts of the AST get traversed twice. - References.erase(std::unique(References.begin(), References.end(), - [](const Reference &L, const Reference &R) { - auto LTok = L.SpelledTok.location(); - auto RTok = R.SpelledTok.location(); - return std::tie(LTok, L.Role) == - std::tie(RTok, R.Role); - }), + References.erase(llvm::unique(References, + [](const Reference &L, const Reference &R) { + auto LTok = L.SpelledTok.location(); + auto RTok = R.SpelledTok.location(); + return std::tie(LTok, L.Role) == + std::tie(RTok, R.Role); + }), References.end()); return std::move(References); } @@ -1502,12 +1502,12 @@ ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit, // We may get multiple refs with the same location and different Roles, as // cross-reference is only interested in locations, we deduplicate them // by the location to avoid emitting duplicated locations. - MainFileRefs.erase(std::unique(MainFileRefs.begin(), MainFileRefs.end(), - [](const ReferenceFinder::Reference &L, - const ReferenceFinder::Reference &R) { - return L.SpelledTok.location() == - R.SpelledTok.location(); - }), + MainFileRefs.erase(llvm::unique(MainFileRefs, + [](const ReferenceFinder::Reference &L, + const ReferenceFinder::Reference &R) { + return L.SpelledTok.location() == + R.SpelledTok.location(); + }), MainFileRefs.end()); for (const auto &Ref : MainFileRefs) { ReferencesResult::Reference Result; diff --git a/clang-tools-extra/clangd/index/FileIndex.cpp b/clang-tools-extra/clangd/index/FileIndex.cpp index aa573e312a756..c8f354de3c00f 100644 --- a/clang-tools-extra/clangd/index/FileIndex.cpp +++ b/clang-tools-extra/clangd/index/FileIndex.cpp @@ -370,8 +370,7 @@ FileSymbols::buildIndex(IndexType Type, DuplicateHandling DuplicateHandle, // relations being stored in both the shards containing their // subject and object. llvm::sort(AllRelations); - AllRelations.erase(std::unique(AllRelations.begin(), AllRelations.end()), - AllRelations.end()); + AllRelations.erase(llvm::unique(AllRelations), AllRelations.end()); size_t StorageSize = RefsStorage.size() * sizeof(Ref) + SymsStorage.size() * sizeof(Symbol); diff --git a/clang-tools-extra/clangd/index/Relation.cpp b/clang-tools-extra/clangd/index/Relation.cpp index 2e5ae33939b0e..3b3e0ddc6d375 100644 --- a/clang-tools-extra/clangd/index/Relation.cpp +++ b/clang-tools-extra/clangd/index/Relation.cpp @@ -43,8 +43,7 @@ RelationSlab RelationSlab::Builder::build() && { llvm::sort(Relations); // Remove duplicates. - Relations.erase(std::unique(Relations.begin(), Relations.end()), - Relations.end()); + Relations.erase(llvm::unique(Relations), Relations.end()); return RelationSlab{std::move(Relations)}; } diff --git a/clang-tools-extra/clangd/index/dex/Trigram.cpp b/clang-tools-extra/clangd/index/dex/Trigram.cpp index c52af4e275a42..8a07086ff23e7 100644 --- a/clang-tools-extra/clangd/index/dex/Trigram.cpp +++ b/clang-tools-extra/clangd/index/dex/Trigram.cpp @@ -116,7 +116,7 @@ void generateIdentifierTrigrams(llvm::StringRef Identifier, } else { identifierTrigrams(Identifier, [&](Trigram T) { Result.push_back(T); }); llvm::sort(Result); - Result.erase(std::unique(Result.begin(), Result.end()), Result.end()); + Result.erase(llvm::unique(Result), Result.end()); } } diff --git a/clang-tools-extra/clangd/refactor/Rename.cpp b/clang-tools-extra/clangd/refactor/Rename.cpp index 26059167208aa..e464f1ad45c52 100644 --- a/clang-tools-extra/clangd/refactor/Rename.cpp +++ b/clang-tools-extra/clangd/refactor/Rename.cpp @@ -906,7 +906,7 @@ findOccurrencesOutsideFile(const NamedDecl &RenameDecl, for (auto &FileAndOccurrences : AffectedFiles) { auto &Ranges = FileAndOccurrences.getValue(); llvm::sort(Ranges); - Ranges.erase(std::unique(Ranges.begin(), Ranges.end()), Ranges.end()); + Ranges.erase(llvm::unique(Ranges), Ranges.end()); SPAN_ATTACH(Tracer, FileAndOccurrences.first(), static_cast<int64_t>(Ranges.size())); @@ -1210,8 +1210,7 @@ llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath, static_cast<int64_t>(Occurrences.size())); assert(llvm::is_sorted(Occurrences)); - assert(std::unique(Occurrences.begin(), Occurrences.end()) == - Occurrences.end() && + assert(llvm::unique(Occurrences) == Occurrences.end() && "Occurrences must be unique"); // These two always correspond to the same position. diff --git a/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp b/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp index da32e00a0ee06..5baa970bcb0c5 100644 --- a/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp @@ -196,9 +196,7 @@ Expected<Tweak::Effect> RemoveUsingNamespace::apply(const Selection &Inputs) { } // Remove duplicates. llvm::sort(IdentsToQualify); - IdentsToQualify.erase( - std::unique(IdentsToQualify.begin(), IdentsToQualify.end()), - IdentsToQualify.end()); + IdentsToQualify.erase(llvm::unique(IdentsToQualify), IdentsToQualify.end()); // Produce replacements to remove the using directives. tooling::Replacements R; diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 860e6ec0fb47e..2836d68b05ff6 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -5975,7 +5975,7 @@ SortAndUniqueProtocols(SmallVectorImpl<ObjCProtocolDecl *> &Protocols) { P = P->getCanonicalDecl(); // Remove duplicates. - auto ProtocolsEnd = std::unique(Protocols.begin(), Protocols.end()); + auto ProtocolsEnd = llvm::unique(Protocols); Protocols.erase(ProtocolsEnd, Protocols.end()); } diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 97ef1c0d46960..33a8728728574 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -328,7 +328,7 @@ class CXXNameMangler { } llvm::sort(TagList); - TagList.erase(std::unique(TagList.begin(), TagList.end()), TagList.end()); + TagList.erase(llvm::unique(TagList), TagList.end()); writeSortedUniqueAbiTags(Out, TagList); } @@ -344,8 +344,7 @@ class CXXNameMangler { const AbiTagList &getSortedUniqueUsedAbiTags() { llvm::sort(UsedAbiTags); - UsedAbiTags.erase(std::unique(UsedAbiTags.begin(), UsedAbiTags.end()), - UsedAbiTags.end()); + UsedAbiTags.erase(llvm::unique(UsedAbiTags), UsedAbiTags.end()); return UsedAbiTags; } diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 97317579c8a50..5cd5755e01587 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -378,7 +378,7 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { // Sort and remove duplicates. std::sort(Result.begin(), Result.end()); - Result.erase(std::unique(Result.begin(), Result.end()), Result.end()); + Result.erase(llvm::unique(Result), Result.end()); return Result; } diff --git a/clang/lib/Driver/XRayArgs.cpp b/clang/lib/Driver/XRayArgs.cpp index 6649ed14c3982..701dd2906dccb 100644 --- a/clang/lib/Driver/XRayArgs.cpp +++ b/clang/lib/Driver/XRayArgs.cpp @@ -174,7 +174,7 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) { // Then we want to sort and unique the modes we've collected. llvm::sort(Modes); - Modes.erase(std::unique(Modes.begin(), Modes.end()), Modes.end()); + Modes.erase(llvm::unique(Modes), Modes.end()); } void XRayArgs::addArgs(const ToolChain &TC, const ArgList &Args, diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 0667813110454..5a1c3f556b331 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -3244,11 +3244,11 @@ static void sortCppIncludes(const FormatStyle &Style, } // Deduplicate #includes. - Indices.erase(std::unique(Indices.begin(), Indices.end(), - [&](unsigned LHSI, unsigned RHSI) { - return Includes[LHSI].Text.trim() == - Includes[RHSI].Text.trim(); - }), + Indices.erase(llvm::unique(Indices, + [&](unsigned LHSI, unsigned RHSI) { + return Includes[LHSI].Text.trim() == + Includes[RHSI].Text.trim(); + }), Indices.end()); int CurrentCategory = Includes.front().Category; @@ -3476,10 +3476,10 @@ static void sortJavaImports(const FormatStyle &Style, }); // Deduplicate imports. - Indices.erase(std::unique(Indices.begin(), Indices.end(), - [&](unsigned LHSI, unsigned RHSI) { - return Imports[LHSI].Text == Imports[RHSI].Text; - }), + Indices.erase(llvm::unique(Indices, + [&](unsigned LHSI, unsigned RHSI) { + return Imports[LHSI].Text == Imports[RHSI].Text; + }), Indices.end()); bool CurrentIsStatic = Imports[Indices.front()].IsStatic; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index cb230774d56fc..0cadbff13bdbf 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -909,7 +909,7 @@ static void handleNoBuiltinAttr(Sema &S, Decl *D, const ParsedAttr &AL) { // Repeating the same attribute is fine. llvm::sort(Names); - Names.erase(std::unique(Names.begin(), Names.end()), Names.end()); + Names.erase(llvm::unique(Names), Names.end()); // Empty no_builtin must be on its own. if (HasWildcard && Names.size() > 1) @@ -6037,7 +6037,7 @@ static void handleAbiTagAttr(Sema &S, Decl *D, const ParsedAttr &AL) { // Store tags sorted and without duplicates. llvm::sort(Tags); - Tags.erase(std::unique(Tags.begin(), Tags.end()), Tags.end()); + Tags.erase(llvm::unique(Tags), Tags.end()); D->addAttr(::new (S.Context) AbiTagAttr(S.Context, AL, Tags.data(), Tags.size())); diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 39c2e157591df..87a400e8a6291 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -1623,8 +1623,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, EnumVals.push_back(std::make_pair(Val, EDI)); } llvm::stable_sort(EnumVals, CmpEnumVals); - auto EI = EnumVals.begin(), EIEnd = - std::unique(EnumVals.begin(), EnumVals.end(), EqEnumVals); + auto EI = EnumVals.begin(), EIEnd = llvm::unique(EnumVals, EqEnumVals); // See which case values aren't in enum. for (CaseValsTy::const_iterator CI = CaseVals.begin(); @@ -1777,8 +1776,7 @@ Sema::DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, if (EnumVals.empty()) return; llvm::stable_sort(EnumVals, CmpEnumVals); - EnumValsTy::iterator EIend = - std::unique(EnumVals.begin(), EnumVals.end(), EqEnumVals); + EnumValsTy::iterator EIend = llvm::unique(EnumVals, EqEnumVals); // See which values aren't in the enum. EnumValsTy::const_iterator EI = EnumVals.begin(); diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 04e73b17af3bc..bea8fd5055358 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -6094,8 +6094,7 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema *SemaPtr, StringRef isysroot, // Sort and deduplicate module IDs. llvm::sort(Imports, Cmp); - Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq), - Imports.end()); + Imports.erase(llvm::unique(Imports, Eq), Imports.end()); RecordData ImportedModules; for (const auto &Import : Imports) { diff --git a/clang/utils/TableGen/NeonEmitter.cpp b/clang/utils/TableGen/NeonEmitter.cpp index 51bfe212464cf..c8cd214417efe 100644 --- a/clang/utils/TableGen/NeonEmitter.cpp +++ b/clang/utils/TableGen/NeonEmitter.cpp @@ -2052,8 +2052,7 @@ void NeonEmitter::createIntrinsic(const Record *R, } sort(NewTypeSpecs); - NewTypeSpecs.erase(std::unique(NewTypeSpecs.begin(), NewTypeSpecs.end()), - NewTypeSpecs.end()); + NewTypeSpecs.erase(llvm::unique(NewTypeSpecs), NewTypeSpecs.end()); auto &Entry = IntrinsicMap[Name]; for (auto &I : NewTypeSpecs) { diff --git a/clang/utils/TableGen/SveEmitter.cpp b/clang/utils/TableGen/SveEmitter.cpp index 200f57960fff8..c48210633516e 100644 --- a/clang/utils/TableGen/SveEmitter.cpp +++ b/clang/utils/TableGen/SveEmitter.cpp @@ -1231,8 +1231,7 @@ void SVEEmitter::createIntrinsic( // Remove duplicate type specs. sort(TypeSpecs); - TypeSpecs.erase(std::unique(TypeSpecs.begin(), TypeSpecs.end()), - TypeSpecs.end()); + TypeSpecs.erase(llvm::unique(TypeSpecs), TypeSpecs.end()); // Create an Intrinsic for each type spec. for (auto TS : TypeSpecs) { diff --git a/llvm/include/llvm/CodeGen/PBQP/Math.h b/llvm/include/llvm/CodeGen/PBQP/Math.h index 6a8942e08b101..2b2b498e54fce 100644 --- a/llvm/include/llvm/CodeGen/PBQP/Math.h +++ b/llvm/include/llvm/CodeGen/PBQP/Math.h @@ -11,6 +11,7 @@ #include "llvm/ADT/Hashing.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/Support/InterleavedRange.h" #include <algorithm> #include <cassert> #include <functional> @@ -111,12 +112,7 @@ inline hash_code hash_value(const Vector &V) { template <typename OStream> OStream& operator<<(OStream &OS, const Vector &V) { assert((V.getLength() != 0) && "Zero-length vector badness."); - - OS << "[ " << V[0]; - for (unsigned i = 1; i < V.getLength(); ++i) - OS << ", " << V[i]; - OS << " ]"; - + OS << "[ " << llvm::interleaved(V) << " ]"; return OS; } `````````` </details> https://github.com/llvm/llvm-project/pull/136461 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits