-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_range_llvm_stable_sort_clang
May 18, 2025
Merged
[clang] Use llvm::stable_sort (NFC) #140413
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_range_llvm_stable_sort_clang
May 18, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/140413.diff 6 Files Affected:
diff --git a/clang/lib/AST/VTableBuilder.cpp b/clang/lib/AST/VTableBuilder.cpp
index 6c97b8718c65e..0001745a6ff22 100644
--- a/clang/lib/AST/VTableBuilder.cpp
+++ b/clang/lib/AST/VTableBuilder.cpp
@@ -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;
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index d0732375f814e..4175959d8f55b 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -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);
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 84b84de28c511..df04c37b9df0d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -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;
}
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index b2a982e953012..b071c98051bbe 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -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 = [&]{
diff --git a/clang/unittests/Support/TimeProfilerTest.cpp b/clang/unittests/Support/TimeProfilerTest.cpp
index 7698742426dfc..a92b0eb11c423 100644
--- a/clang/unittests/Support/TimeProfilerTest.cpp
+++ b/clang/unittests/Support/TimeProfilerTest.cpp
@@ -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.
diff --git a/clang/utils/TableGen/SveEmitter.cpp b/clang/utils/TableGen/SveEmitter.cpp
index c48210633516e..1bae1c6a27afd 100644
--- a/clang/utils/TableGen/SveEmitter.cpp
+++ b/clang/utils/TableGen/SveEmitter.cpp
@@ -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)
|
@llvm/pr-subscribers-clang-modules Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/140413.diff 6 Files Affected:
diff --git a/clang/lib/AST/VTableBuilder.cpp b/clang/lib/AST/VTableBuilder.cpp
index 6c97b8718c65e..0001745a6ff22 100644
--- a/clang/lib/AST/VTableBuilder.cpp
+++ b/clang/lib/AST/VTableBuilder.cpp
@@ -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;
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index d0732375f814e..4175959d8f55b 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -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);
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 84b84de28c511..df04c37b9df0d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -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;
}
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index b2a982e953012..b071c98051bbe 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -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 = [&]{
diff --git a/clang/unittests/Support/TimeProfilerTest.cpp b/clang/unittests/Support/TimeProfilerTest.cpp
index 7698742426dfc..a92b0eb11c423 100644
--- a/clang/unittests/Support/TimeProfilerTest.cpp
+++ b/clang/unittests/Support/TimeProfilerTest.cpp
@@ -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.
diff --git a/clang/utils/TableGen/SveEmitter.cpp b/clang/utils/TableGen/SveEmitter.cpp
index c48210633516e..1bae1c6a27afd 100644
--- a/clang/utils/TableGen/SveEmitter.cpp
+++ b/clang/utils/TableGen/SveEmitter.cpp
@@ -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)
|
shiltian
approved these changes
May 17, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang:modules
C++20 modules and Clang Header Modules
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.