-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[Clang][NFC] Use llvm::sort()
#140337
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
Open
el-ev
wants to merge
3
commits into
main
Choose a base branch
from
users/el-ev/05-17-_clang_nfc_use_llvm_sort_
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Clang][NFC] Use llvm::sort()
#140337
+21
−23
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 @llvm/pr-subscribers-clang-driver Author: Iris Shi (el-ev) ChangesFull diff: https://github.com/llvm/llvm-project/pull/140337.diff 6 Files Affected:
diff --git a/clang/lib/APINotes/APINotesWriter.cpp b/clang/lib/APINotes/APINotesWriter.cpp
index 7578bc37b5c68..37d4f2e5617fd 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -446,13 +446,13 @@ void emitVersionedInfo(
llvm::function_ref<void(raw_ostream &,
const typename MakeDependent<T>::Type &)>
emitInfo) {
- std::sort(VI.begin(), VI.end(),
- [](const std::pair<VersionTuple, T> &LHS,
- const std::pair<VersionTuple, T> &RHS) -> bool {
- assert((&LHS == &RHS || LHS.first != RHS.first) &&
- "two entries for the same version");
- return LHS.first < RHS.first;
- });
+ llvm::sort(VI,
+ [](const std::pair<VersionTuple, T> &LHS,
+ const std::pair<VersionTuple, T> &RHS) -> bool {
+ assert((&LHS == &RHS || LHS.first != RHS.first) &&
+ "two entries for the same version");
+ return LHS.first < RHS.first;
+ });
llvm::support::endian::Writer writer(OS, llvm::endianness::little);
writer.write<uint16_t>(VI.size());
diff --git a/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp b/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
index 3c385ed8ef663..af23e634a47e1 100644
--- a/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
+++ b/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
@@ -161,15 +161,15 @@ void simplifyConstraints(llvm::SetVector<const Formula *> &Constraints,
atomsInEquivalenceClass(EquivalentAtoms, At);
if (Atoms.size() == 1)
continue;
- std::sort(Atoms.begin(), Atoms.end());
+ llvm::sort(Atoms);
Info->EquivalentAtoms.push_back(std::move(Atoms));
}
for (Atom At : TrueAtoms)
Info->TrueAtoms.append(atomsInEquivalenceClass(EquivalentAtoms, At));
- std::sort(Info->TrueAtoms.begin(), Info->TrueAtoms.end());
+ llvm::sort(Info->TrueAtoms);
for (Atom At : FalseAtoms)
Info->FalseAtoms.append(atomsInEquivalenceClass(EquivalentAtoms, At));
- std::sort(Info->FalseAtoms.begin(), Info->FalseAtoms.end());
+ llvm::sort(Info->FalseAtoms);
}
}
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index ec648e1a17af9..b508ca1046563 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -2622,11 +2622,10 @@ bool clang::internal::anyConflict(const SmallVectorImpl<FixItHint> &FixIts,
for (const FixItHint &H : FixIts)
All.push_back(&H);
- std::sort(All.begin(), All.end(),
- [&SM](const FixItHint *H1, const FixItHint *H2) {
- return SM.isBeforeInTranslationUnit(H1->RemoveRange.getBegin(),
- H2->RemoveRange.getBegin());
- });
+ llvm::sort(All, [&SM](const FixItHint *H1, const FixItHint *H2) {
+ return SM.isBeforeInTranslationUnit(H1->RemoveRange.getBegin(),
+ H2->RemoveRange.getBegin());
+ });
const FixItHint *CurrHint = nullptr;
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 664aafad0f680..59f1dd12aae70 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -377,7 +377,7 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const {
Result.push_back("-fexceptions");
// Sort and remove duplicates.
- std::sort(Result.begin(), Result.end());
+ llvm::sort(Result);
Result.erase(llvm::unique(Result), Result.end());
return Result;
}
diff --git a/clang/lib/Interpreter/CodeCompletion.cpp b/clang/lib/Interpreter/CodeCompletion.cpp
index aa90663538128..cce6434ca71b6 100644
--- a/clang/lib/Interpreter/CodeCompletion.cpp
+++ b/clang/lib/Interpreter/CodeCompletion.cpp
@@ -203,7 +203,7 @@ void ReplCompletionConsumer::ProcessCodeCompleteResults(
}
}
- std::sort(Results.begin(), Results.end());
+ llvm::sort(Results);
}
class IncrementalSyntaxOnlyAction : public SyntaxOnlyAction {
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index c4dcfd3eb8f99..a5f95b277e298 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -268,12 +268,11 @@ static void validatePackoffset(Sema &S, HLSLBufferDecl *BufDecl) {
// and compare adjacent values.
bool IsValid = true;
ASTContext &Context = S.getASTContext();
- std::sort(PackOffsetVec.begin(), PackOffsetVec.end(),
- [](const std::pair<VarDecl *, HLSLPackOffsetAttr *> &LHS,
- const std::pair<VarDecl *, HLSLPackOffsetAttr *> &RHS) {
- return LHS.second->getOffsetInBytes() <
- RHS.second->getOffsetInBytes();
- });
+ llvm::sort(
+ PackOffsetVec, [](const std::pair<VarDecl *, HLSLPackOffsetAttr *> &LHS,
+ const std::pair<VarDecl *, HLSLPackOffsetAttr *> &RHS) {
+ return LHS.second->getOffsetInBytes() < RHS.second->getOffsetInBytes();
+ });
for (unsigned i = 0; i < PackOffsetVec.size() - 1; i++) {
VarDecl *Var = PackOffsetVec[i].first;
HLSLPackOffsetAttr *Attr = PackOffsetVec[i].second;
|
@llvm/pr-subscribers-hlsl Author: Iris Shi (el-ev) ChangesFull diff: https://github.com/llvm/llvm-project/pull/140337.diff 6 Files Affected:
diff --git a/clang/lib/APINotes/APINotesWriter.cpp b/clang/lib/APINotes/APINotesWriter.cpp
index 7578bc37b5c68..37d4f2e5617fd 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -446,13 +446,13 @@ void emitVersionedInfo(
llvm::function_ref<void(raw_ostream &,
const typename MakeDependent<T>::Type &)>
emitInfo) {
- std::sort(VI.begin(), VI.end(),
- [](const std::pair<VersionTuple, T> &LHS,
- const std::pair<VersionTuple, T> &RHS) -> bool {
- assert((&LHS == &RHS || LHS.first != RHS.first) &&
- "two entries for the same version");
- return LHS.first < RHS.first;
- });
+ llvm::sort(VI,
+ [](const std::pair<VersionTuple, T> &LHS,
+ const std::pair<VersionTuple, T> &RHS) -> bool {
+ assert((&LHS == &RHS || LHS.first != RHS.first) &&
+ "two entries for the same version");
+ return LHS.first < RHS.first;
+ });
llvm::support::endian::Writer writer(OS, llvm::endianness::little);
writer.write<uint16_t>(VI.size());
diff --git a/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp b/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
index 3c385ed8ef663..af23e634a47e1 100644
--- a/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
+++ b/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
@@ -161,15 +161,15 @@ void simplifyConstraints(llvm::SetVector<const Formula *> &Constraints,
atomsInEquivalenceClass(EquivalentAtoms, At);
if (Atoms.size() == 1)
continue;
- std::sort(Atoms.begin(), Atoms.end());
+ llvm::sort(Atoms);
Info->EquivalentAtoms.push_back(std::move(Atoms));
}
for (Atom At : TrueAtoms)
Info->TrueAtoms.append(atomsInEquivalenceClass(EquivalentAtoms, At));
- std::sort(Info->TrueAtoms.begin(), Info->TrueAtoms.end());
+ llvm::sort(Info->TrueAtoms);
for (Atom At : FalseAtoms)
Info->FalseAtoms.append(atomsInEquivalenceClass(EquivalentAtoms, At));
- std::sort(Info->FalseAtoms.begin(), Info->FalseAtoms.end());
+ llvm::sort(Info->FalseAtoms);
}
}
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index ec648e1a17af9..b508ca1046563 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -2622,11 +2622,10 @@ bool clang::internal::anyConflict(const SmallVectorImpl<FixItHint> &FixIts,
for (const FixItHint &H : FixIts)
All.push_back(&H);
- std::sort(All.begin(), All.end(),
- [&SM](const FixItHint *H1, const FixItHint *H2) {
- return SM.isBeforeInTranslationUnit(H1->RemoveRange.getBegin(),
- H2->RemoveRange.getBegin());
- });
+ llvm::sort(All, [&SM](const FixItHint *H1, const FixItHint *H2) {
+ return SM.isBeforeInTranslationUnit(H1->RemoveRange.getBegin(),
+ H2->RemoveRange.getBegin());
+ });
const FixItHint *CurrHint = nullptr;
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 664aafad0f680..59f1dd12aae70 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -377,7 +377,7 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const {
Result.push_back("-fexceptions");
// Sort and remove duplicates.
- std::sort(Result.begin(), Result.end());
+ llvm::sort(Result);
Result.erase(llvm::unique(Result), Result.end());
return Result;
}
diff --git a/clang/lib/Interpreter/CodeCompletion.cpp b/clang/lib/Interpreter/CodeCompletion.cpp
index aa90663538128..cce6434ca71b6 100644
--- a/clang/lib/Interpreter/CodeCompletion.cpp
+++ b/clang/lib/Interpreter/CodeCompletion.cpp
@@ -203,7 +203,7 @@ void ReplCompletionConsumer::ProcessCodeCompleteResults(
}
}
- std::sort(Results.begin(), Results.end());
+ llvm::sort(Results);
}
class IncrementalSyntaxOnlyAction : public SyntaxOnlyAction {
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index c4dcfd3eb8f99..a5f95b277e298 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -268,12 +268,11 @@ static void validatePackoffset(Sema &S, HLSLBufferDecl *BufDecl) {
// and compare adjacent values.
bool IsValid = true;
ASTContext &Context = S.getASTContext();
- std::sort(PackOffsetVec.begin(), PackOffsetVec.end(),
- [](const std::pair<VarDecl *, HLSLPackOffsetAttr *> &LHS,
- const std::pair<VarDecl *, HLSLPackOffsetAttr *> &RHS) {
- return LHS.second->getOffsetInBytes() <
- RHS.second->getOffsetInBytes();
- });
+ llvm::sort(
+ PackOffsetVec, [](const std::pair<VarDecl *, HLSLPackOffsetAttr *> &LHS,
+ const std::pair<VarDecl *, HLSLPackOffsetAttr *> &RHS) {
+ return LHS.second->getOffsetInBytes() < RHS.second->getOffsetInBytes();
+ });
for (unsigned i = 0; i < PackOffsetVec.size() - 1; i++) {
VarDecl *Var = PackOffsetVec[i].first;
HLSLPackOffsetAttr *Attr = PackOffsetVec[i].second;
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:analysis
clang:dataflow
Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html
clang:driver
'clang' and 'clang++' user-facing binaries. Not 'clang-cl'
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
HLSL
HLSL Language Support
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.