Skip to content

[clang] Use llvm::stable_sort (NFC) #140413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/lib/AST/VTableBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1595,8 +1595,8 @@ void ItaniumVTableBuilder::AddMethods(
NewVirtualFunctions.push_back(MD);
}

std::stable_sort(
NewImplicitVirtualFunctions.begin(), NewImplicitVirtualFunctions.end(),
llvm::stable_sort(
NewImplicitVirtualFunctions,
[](const CXXMethodDecl *A, const CXXMethodDecl *B) {
if (A == B)
return false;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Lex/ModuleMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ void ModuleMapLoader::handleUmbrellaDirDecl(
}

// Sort header paths so that the pcm doesn't depend on iteration order.
std::stable_sort(Headers.begin(), Headers.end(), compareModuleHeaders);
llvm::stable_sort(Headers, compareModuleHeaders);

for (auto &Header : Headers)
Map.addHeader(ActiveModule, std::move(Header), ModuleMap::TextualHeader);
Expand Down
9 changes: 4 additions & 5 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7526,11 +7526,10 @@ bool DecomposePrintfHandler::GetSpecifiers(
if (H.HadError)
return false;

std::stable_sort(
Args.begin(), Args.end(),
[](const EquatableFormatArgument &A, const EquatableFormatArgument &B) {
return A.getPosition() < B.getPosition();
});
llvm::stable_sort(Args, [](const EquatableFormatArgument &A,
const EquatableFormatArgument &B) {
return A.getPosition() < B.getPosition();
});
return true;
}

Expand Down
9 changes: 4 additions & 5 deletions clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,10 @@ ParsedType Sema::getDestructorName(const IdentifierInfo &II,
FoundDecls.resize(NumNonExtensionDecls);

// List types before non-types.
std::stable_sort(FoundDecls.begin(), FoundDecls.end(),
[](NamedDecl *A, NamedDecl *B) {
return isa<TypeDecl>(A->getUnderlyingDecl()) >
isa<TypeDecl>(B->getUnderlyingDecl());
});
llvm::stable_sort(FoundDecls, [](NamedDecl *A, NamedDecl *B) {
return isa<TypeDecl>(A->getUnderlyingDecl()) >
isa<TypeDecl>(B->getUnderlyingDecl());
});

// Suggest a fixit to properly name the destroyed type.
auto MakeFixItHint = [&]{
Expand Down
9 changes: 4 additions & 5 deletions clang/unittests/Support/TimeProfilerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ std::string buildTraceGraph(StringRef Json) {
// started earlier are first in the list.
// Then do a stable sort, we need it for the trace graph.
std::reverse(Events.begin(), Events.end());
std::stable_sort(
Events.begin(), Events.end(), [](const auto &lhs, const auto &rhs) {
return std::make_pair(lhs.TimestampBegin, -lhs.TimestampEnd) <
std::make_pair(rhs.TimestampBegin, -rhs.TimestampEnd);
});
llvm::stable_sort(Events, [](const auto &lhs, const auto &rhs) {
return std::make_pair(lhs.TimestampBegin, -lhs.TimestampEnd) <
std::make_pair(rhs.TimestampBegin, -rhs.TimestampEnd);
});

std::stringstream Stream;
// Write a newline for better testing with multiline string literal.
Expand Down
18 changes: 8 additions & 10 deletions clang/utils/TableGen/SveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,16 +1275,14 @@ void SVEEmitter::createCoreHeaderIntrinsics(raw_ostream &OS,
// - Architectural guard (i.e. does it require SVE2 or SVE2_AES)
// - Class (is intrinsic overloaded or not)
// - Intrinsic name
std::stable_sort(Defs.begin(), Defs.end(),
[](const std::unique_ptr<Intrinsic> &A,
const std::unique_ptr<Intrinsic> &B) {
auto ToTuple = [](const std::unique_ptr<Intrinsic> &I) {
return std::make_tuple(
I->getSVEGuard().str() + I->getSMEGuard().str(),
(unsigned)I->getClassKind(), I->getName());
};
return ToTuple(A) < ToTuple(B);
});
llvm::stable_sort(Defs, [](const std::unique_ptr<Intrinsic> &A,
const std::unique_ptr<Intrinsic> &B) {
auto ToTuple = [](const std::unique_ptr<Intrinsic> &I) {
return std::make_tuple(I->getSVEGuard().str() + I->getSMEGuard().str(),
(unsigned)I->getClassKind(), I->getName());
};
return ToTuple(A) < ToTuple(B);
});

// Actually emit the intrinsic declarations.
for (auto &I : Defs)
Expand Down
Loading