diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index 538c1d18a8ac1..586273ab88bd3 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -533,16 +533,20 @@ 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. - Sections.erase("*"); + // FIXME: C++20 can use std::erase_if(Sections, [](Section &sec) { return + // sec.SectionStr == "*"; }); + Sections.erase( + std::remove_if(Sections.begin(), Sections.end(), + [](Section &sec) { return sec.SectionStr == "*"; }), + Sections.end()); // Make sure we iterate sections by their line numbers. - std::vector *>> - LineAndSectionEntry; + std::vector> LineAndSectionEntry; LineAndSectionEntry.reserve(Sections.size()); for (const auto &Entry : Sections) { - StringRef DiagName = Entry.getKey(); + StringRef DiagName = Entry.SectionStr; // Each section has a matcher with that section's name, attached to that // line. - const auto &DiagSectionMatcher = Entry.getValue().SectionMatcher; + const auto &DiagSectionMatcher = Entry.SectionMatcher; unsigned DiagLine = DiagSectionMatcher->Globs.at(DiagName).second; LineAndSectionEntry.emplace_back(DiagLine, &Entry); } @@ -550,7 +554,7 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) { static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError; for (const auto &[_, SectionEntry] : LineAndSectionEntry) { SmallVector GroupDiags; - StringRef DiagGroup = SectionEntry->getKey(); + StringRef DiagGroup = SectionEntry->SectionStr; if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup( WarningFlavor, DiagGroup, GroupDiags)) { StringRef Suggestion = @@ -563,7 +567,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->getValue(); + DiagToSection[Diag] = SectionEntry; } } diff --git a/clang/lib/Basic/ProfileList.cpp b/clang/lib/Basic/ProfileList.cpp index 01b8d7a073432..f2383c76853ec 100644 --- a/clang/lib/Basic/ProfileList.cpp +++ b/clang/lib/Basic/ProfileList.cpp @@ -37,7 +37,7 @@ class ProfileSpecialCaseList : public llvm::SpecialCaseList { bool hasPrefix(StringRef Prefix) const { for (const auto &It : Sections) - if (It.second.Entries.count(Prefix) > 0) + if (It.Entries.count(Prefix) > 0) return true; return false; } diff --git a/clang/lib/Basic/SanitizerSpecialCaseList.cpp b/clang/lib/Basic/SanitizerSpecialCaseList.cpp index b02e868cdaa44..2dbf04c6ede97 100644 --- a/clang/lib/Basic/SanitizerSpecialCaseList.cpp +++ b/clang/lib/Basic/SanitizerSpecialCaseList.cpp @@ -37,8 +37,7 @@ SanitizerSpecialCaseList::createOrDie(const std::vector &Paths, } void SanitizerSpecialCaseList::createSanitizerSections() { - for (auto &It : Sections) { - auto &S = It.second; + for (auto &S : Sections) { SanitizerMask Mask; #define SANITIZER(NAME, ID) \ diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h index ca2030abdc1f5..fc6dc93651f38 100644 --- a/llvm/include/llvm/Support/SpecialCaseList.h +++ b/llvm/include/llvm/Support/SpecialCaseList.h @@ -132,14 +132,15 @@ class SpecialCaseList { using SectionEntries = StringMap>; struct Section { - Section(std::unique_ptr M) : SectionMatcher(std::move(M)){}; - Section() : Section(std::make_unique()) {} + Section(std::unique_ptr M) : SectionMatcher(std::move(M)) {}; + Section() : Section(std::make_unique()) {}; std::unique_ptr SectionMatcher; SectionEntries Entries; + std::string SectionStr; }; - StringMap
Sections; + std::vector
Sections; LLVM_ABI Expected
addSection(StringRef SectionStr, unsigned LineNo, bool UseGlobs = true); @@ -154,6 +155,6 @@ class SpecialCaseList { StringRef Category) const; }; -} // namespace llvm +} // namespace llvm #endif // LLVM_SUPPORT_SPECIALCASELIST_H diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp index 7a23421eaeb89..335965f80d830 100644 --- a/llvm/lib/Support/SpecialCaseList.cpp +++ b/llvm/lib/Support/SpecialCaseList.cpp @@ -132,14 +132,17 @@ bool SpecialCaseList::createInternal(const MemoryBuffer *MB, Expected SpecialCaseList::addSection(StringRef SectionStr, unsigned LineNo, bool UseGlobs) { - auto [It, DidEmplace] = Sections.try_emplace(SectionStr); - auto &Section = It->getValue(); - if (DidEmplace) - if (auto Err = Section.SectionMatcher->insert(SectionStr, LineNo, UseGlobs)) - return createStringError(errc::invalid_argument, - "malformed section at line " + Twine(LineNo) + - ": '" + SectionStr + - "': " + toString(std::move(Err))); + Sections.emplace_back(); + auto &Section = Sections.back(); + Section.SectionStr = SectionStr; + + if (auto Err = Section.SectionMatcher->insert(SectionStr, LineNo, UseGlobs)) { + return createStringError(errc::invalid_argument, + "malformed section at line " + Twine(LineNo) + + ": '" + SectionStr + + "': " + toString(std::move(Err))); + } + return &Section; } @@ -212,8 +215,7 @@ bool SpecialCaseList::inSection(StringRef Section, StringRef Prefix, unsigned SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix, StringRef Query, StringRef Category) const { - for (const auto &It : Sections) { - const auto &S = It.getValue(); + for (const auto &S : Sections) { if (S.SectionMatcher->match(Section)) { unsigned Blame = inSectionBlame(S.Entries, Prefix, Query, Category); if (Blame)