-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[NFC][clang] Don't sort sections of SpecialCaseList #162166
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
vitalybuka
merged 3 commits into
main
from
users/vitalybuka/spr/nfcdiagnostics-dont-sort-sections
Oct 7, 2025
Merged
[NFC][clang] Don't sort sections of SpecialCaseList #162166
vitalybuka
merged 3 commits into
main
from
users/vitalybuka/spr/nfcdiagnostics-dont-sort-sections
Oct 7, 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
Created using spr 1.3.6
@llvm/pr-subscribers-clang Author: Vitaly Buka (vitalybuka) ChangesAfter #112517 in #140127 sections are stored in Full diff: https://github.com/llvm/llvm-project/pull/162166.diff 1 Files Affected:
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index dc3778bbf339c..0a261cac7fde9 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -537,33 +537,16 @@ WarningsSpecialCaseList::create(const llvm::MemoryBuffer &Input,
}
void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
- // Drop the default section introduced by special case list, we only support
- // exact diagnostic group names.
- // FIXME: We should make this configurable in the parser instead.
- // FIXME: C++20 can use std::erase_if(Sections, [](Section &sec) { return
- // sec.SectionStr == "*"; });
- llvm::erase_if(Sections, [](Section &sec) { return sec.SectionStr == "*"; });
- // Make sure we iterate sections by their line numbers.
- std::vector<std::pair<unsigned, const Section *>> LineAndSectionEntry;
- LineAndSectionEntry.reserve(Sections.size());
- for (const auto &Entry : Sections) {
- StringRef DiagName = Entry.SectionStr;
- // Each section has a matcher with that section's name, attached to that
- // line.
- const auto &DiagSectionMatcher = Entry.SectionMatcher;
- unsigned DiagLine = 0;
- for (const auto &Glob : DiagSectionMatcher->Globs)
- if (Glob->Name == DiagName) {
- DiagLine = Glob->LineNo;
- break;
- }
- LineAndSectionEntry.emplace_back(DiagLine, &Entry);
- }
- llvm::sort(LineAndSectionEntry);
static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
- for (const auto &[_, SectionEntry] : LineAndSectionEntry) {
+ for (const auto& SectionEntry : Sections) {
+ StringRef DiagGroup = SectionEntry.SectionStr;
+ if (DiagGroup == "*") {
+ // Drop the default section introduced by special case list, we only support
+ // exact diagnostic group names.
+ // FIXME: We should make this configurable in the parser instead.
+ continue;
+ }
SmallVector<diag::kind> GroupDiags;
- StringRef DiagGroup = SectionEntry->SectionStr;
if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup(
WarningFlavor, DiagGroup, GroupDiags)) {
StringRef Suggestion =
@@ -576,7 +559,7 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
for (diag::kind Diag : GroupDiags)
// We're intentionally overwriting any previous mappings here to make sure
// latest one takes precedence.
- DiagToSection[Diag] = SectionEntry;
+ DiagToSection[Diag] = &SectionEntry;
}
}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
fmayer
approved these changes
Oct 6, 2025
please make commit message a bit more descriptive about which sections |
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
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.
Sorting was introduced in #112517.
But it's not needed after #140127.
SpecialCaseList
storessections in a vector now, to preserve declaration order.
And don't remove default section, just skip it.
Probably faster, but unlikely makes a difference.