Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions clang/lib/Basic/Diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,24 +533,28 @@ 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<std::pair<unsigned, const llvm::StringMapEntry<Section> *>>
LineAndSectionEntry;
std::vector<std::pair<unsigned, const Section *>> 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);
}
llvm::sort(LineAndSectionEntry);
static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
for (const auto &[_, SectionEntry] : LineAndSectionEntry) {
SmallVector<diag::kind> GroupDiags;
StringRef DiagGroup = SectionEntry->getKey();
StringRef DiagGroup = SectionEntry->SectionStr;
if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup(
WarningFlavor, DiagGroup, GroupDiags)) {
StringRef Suggestion =
Expand All @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/ProfileList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/Basic/SanitizerSpecialCaseList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,18 @@ SanitizerSpecialCaseList::createOrDie(const std::vector<std::string> &Paths,

void SanitizerSpecialCaseList::createSanitizerSections() {
for (auto &It : Sections) {
auto &S = It.second;
SanitizerMask Mask;

#define SANITIZER(NAME, ID) \
if (S.SectionMatcher->match(NAME)) \
if (It.SectionMatcher->match(NAME)) \
Mask |= SanitizerKind::ID;
#define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID)

#include "clang/Basic/Sanitizers.def"
#undef SANITIZER
#undef SANITIZER_GROUP

SanitizerSections.emplace_back(Mask, S.Entries);
SanitizerSections.emplace_back(Mask, It.Entries);
}
}

Expand Down
9 changes: 5 additions & 4 deletions llvm/include/llvm/Support/SpecialCaseList.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ class SpecialCaseList {
using SectionEntries = StringMap<StringMap<Matcher>>;

struct Section {
Section(std::unique_ptr<Matcher> M) : SectionMatcher(std::move(M)){};
Section() : Section(std::make_unique<Matcher>()) {}
Section(std::unique_ptr<Matcher> M) : SectionMatcher(std::move(M)) {};
Section() : Section(std::make_unique<Matcher>()) {};

std::unique_ptr<Matcher> SectionMatcher;
SectionEntries Entries;
std::string SectionStr;
};

StringMap<Section> Sections;
std::vector<Section> Sections;

LLVM_ABI Expected<Section *> addSection(StringRef SectionStr, unsigned LineNo,
bool UseGlobs = true);
Expand All @@ -154,6 +155,6 @@ class SpecialCaseList {
StringRef Category) const;
};

} // namespace llvm
} // namespace llvm

#endif // LLVM_SUPPORT_SPECIALCASELIST_H
30 changes: 17 additions & 13 deletions llvm/lib/Support/SpecialCaseList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,17 @@ bool SpecialCaseList::createInternal(const MemoryBuffer *MB,
Expected<SpecialCaseList::Section *>
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;
}

Expand Down Expand Up @@ -213,9 +216,8 @@ unsigned SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix,
StringRef Query,
StringRef Category) const {
for (const auto &It : Sections) {
const auto &S = It.getValue();
if (S.SectionMatcher->match(Section)) {
unsigned Blame = inSectionBlame(S.Entries, Prefix, Query, Category);
if (It.SectionMatcher->match(Section)) {
unsigned Blame = inSectionBlame(It.Entries, Prefix, Query, Category);
if (Blame)
return Blame;
}
Expand All @@ -227,9 +229,11 @@ unsigned SpecialCaseList::inSectionBlame(const SectionEntries &Entries,
StringRef Prefix, StringRef Query,
StringRef Category) const {
SectionEntries::const_iterator I = Entries.find(Prefix);
if (I == Entries.end()) return 0;
if (I == Entries.end())
return 0;
StringMap<Matcher>::const_iterator II = I->second.find(Category);
if (II == I->second.end()) return 0;
if (II == I->second.end())
return 0;

return II->getValue().match(Query);
}
Expand Down