[clang] b98ac06 - [NFC][clang] Don't sort sections of SpecialCaseList (#162166)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 7 08:23:59 PDT 2025
Author: Vitaly Buka
Date: 2025-10-07T08:23:55-07:00
New Revision: b98ac0698129e422870260d7ca98f2edd6227aed
URL: https://github.com/llvm/llvm-project/commit/b98ac0698129e422870260d7ca98f2edd6227aed
DIFF: https://github.com/llvm/llvm-project/commit/b98ac0698129e422870260d7ca98f2edd6227aed.diff
LOG: [NFC][clang] Don't sort sections of SpecialCaseList (#162166)
Sorting was introduced in #112517.
But it's not needed after #140127. `SpecialCaseList` stores
sections in a vector now, to preserve declaration order.
And don't remove default section, just skip it.
Probably faster, but unlikely makes a difference.
Added:
Modified:
clang/lib/Basic/Diagnostic.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index dc3778bbf339c..2b89370a42d1b 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;
}
}
More information about the cfe-commits
mailing list