Skip to content

Commit 4628b85

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6
1 parent 2661e99 commit 4628b85

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

clang/lib/Basic/Diagnostic.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -533,24 +533,28 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
533533
// Drop the default section introduced by special case list, we only support
534534
// exact diagnostic group names.
535535
// FIXME: We should make this configurable in the parser instead.
536-
Sections.erase("*");
536+
// FIXME: C++20 can use std::erase_if(Sections, [](Section &sec) { return
537+
// sec.SectionStr == "*"; });
538+
Sections.erase(
539+
std::remove_if(Sections.begin(), Sections.end(),
540+
[](Section &sec) { return sec.SectionStr == "*"; }),
541+
Sections.end());
537542
// Make sure we iterate sections by their line numbers.
538-
std::vector<std::pair<unsigned, const llvm::StringMapEntry<Section> *>>
539-
LineAndSectionEntry;
543+
std::vector<std::pair<unsigned, const Section *>> LineAndSectionEntry;
540544
LineAndSectionEntry.reserve(Sections.size());
541545
for (const auto &Entry : Sections) {
542-
StringRef DiagName = Entry.getKey();
546+
StringRef DiagName = Entry.SectionStr;
543547
// Each section has a matcher with that section's name, attached to that
544548
// line.
545-
const auto &DiagSectionMatcher = Entry.getValue().SectionMatcher;
549+
const auto &DiagSectionMatcher = Entry.SectionMatcher;
546550
unsigned DiagLine = DiagSectionMatcher->Globs.at(DiagName).second;
547551
LineAndSectionEntry.emplace_back(DiagLine, &Entry);
548552
}
549553
llvm::sort(LineAndSectionEntry);
550554
static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
551555
for (const auto &[_, SectionEntry] : LineAndSectionEntry) {
552556
SmallVector<diag::kind> GroupDiags;
553-
StringRef DiagGroup = SectionEntry->getKey();
557+
StringRef DiagGroup = SectionEntry->SectionStr;
554558
if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup(
555559
WarningFlavor, DiagGroup, GroupDiags)) {
556560
StringRef Suggestion =
@@ -563,7 +567,7 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
563567
for (diag::kind Diag : GroupDiags)
564568
// We're intentionally overwriting any previous mappings here to make sure
565569
// latest one takes precedence.
566-
DiagToSection[Diag] = &SectionEntry->getValue();
570+
DiagToSection[Diag] = SectionEntry;
567571
}
568572
}
569573

clang/lib/Basic/ProfileList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ProfileSpecialCaseList : public llvm::SpecialCaseList {
3737

3838
bool hasPrefix(StringRef Prefix) const {
3939
for (const auto &It : Sections)
40-
if (It.second.Entries.count(Prefix) > 0)
40+
if (It.Entries.count(Prefix) > 0)
4141
return true;
4242
return false;
4343
}

clang/lib/Basic/SanitizerSpecialCaseList.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,18 @@ SanitizerSpecialCaseList::createOrDie(const std::vector<std::string> &Paths,
3838

3939
void SanitizerSpecialCaseList::createSanitizerSections() {
4040
for (auto &It : Sections) {
41-
auto &S = It.second;
4241
SanitizerMask Mask;
4342

4443
#define SANITIZER(NAME, ID) \
45-
if (S.SectionMatcher->match(NAME)) \
44+
if (It.SectionMatcher->match(NAME)) \
4645
Mask |= SanitizerKind::ID;
4746
#define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID)
4847

4948
#include "clang/Basic/Sanitizers.def"
5049
#undef SANITIZER
5150
#undef SANITIZER_GROUP
5251

53-
SanitizerSections.emplace_back(Mask, S.Entries);
52+
SanitizerSections.emplace_back(Mask, It.Entries);
5453
}
5554
}
5655

llvm/include/llvm/Support/SpecialCaseList.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,16 @@ class SpecialCaseList {
132132
using SectionEntries = StringMap<StringMap<Matcher>>;
133133

134134
struct Section {
135-
Section(std::unique_ptr<Matcher> M) : SectionMatcher(std::move(M)){};
136-
Section() : Section(std::make_unique<Matcher>()) {}
135+
Section(std::unique_ptr<Matcher> M, StringRef str)
136+
: SectionMatcher(std::move(M)), SectionStr(SectionStr) {};
137+
Section(StringRef str) : Section(std::make_unique<Matcher>(), str) {};
137138

138139
std::unique_ptr<Matcher> SectionMatcher;
139140
SectionEntries Entries;
141+
std::string SectionStr;
140142
};
141143

142-
StringMap<Section> Sections;
144+
std::vector<Section> Sections;
143145

144146
LLVM_ABI Expected<Section *> addSection(StringRef SectionStr, unsigned LineNo,
145147
bool UseGlobs = true);
@@ -154,6 +156,6 @@ class SpecialCaseList {
154156
StringRef Category) const;
155157
};
156158

157-
} // namespace llvm
159+
} // namespace llvm
158160

159161
#endif // LLVM_SUPPORT_SPECIALCASELIST_H

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,16 @@ bool SpecialCaseList::createInternal(const MemoryBuffer *MB,
132132
Expected<SpecialCaseList::Section *>
133133
SpecialCaseList::addSection(StringRef SectionStr, unsigned LineNo,
134134
bool UseGlobs) {
135-
auto [It, DidEmplace] = Sections.try_emplace(SectionStr);
136-
auto &Section = It->getValue();
137-
if (DidEmplace)
138-
if (auto Err = Section.SectionMatcher->insert(SectionStr, LineNo, UseGlobs))
139-
return createStringError(errc::invalid_argument,
140-
"malformed section at line " + Twine(LineNo) +
141-
": '" + SectionStr +
142-
"': " + toString(std::move(Err)));
135+
Sections.emplace_back(SectionStr);
136+
auto &Section = Sections.back();
137+
138+
if (auto Err = Section.SectionMatcher->insert(SectionStr, LineNo, UseGlobs)) {
139+
return createStringError(errc::invalid_argument,
140+
"malformed section at line " + Twine(LineNo) +
141+
": '" + SectionStr +
142+
"': " + toString(std::move(Err)));
143+
}
144+
143145
return &Section;
144146
}
145147

@@ -213,9 +215,8 @@ unsigned SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix,
213215
StringRef Query,
214216
StringRef Category) const {
215217
for (const auto &It : Sections) {
216-
const auto &S = It.getValue();
217-
if (S.SectionMatcher->match(Section)) {
218-
unsigned Blame = inSectionBlame(S.Entries, Prefix, Query, Category);
218+
if (It.SectionMatcher->match(Section)) {
219+
unsigned Blame = inSectionBlame(It.Entries, Prefix, Query, Category);
219220
if (Blame)
220221
return Blame;
221222
}
@@ -227,9 +228,11 @@ unsigned SpecialCaseList::inSectionBlame(const SectionEntries &Entries,
227228
StringRef Prefix, StringRef Query,
228229
StringRef Category) const {
229230
SectionEntries::const_iterator I = Entries.find(Prefix);
230-
if (I == Entries.end()) return 0;
231+
if (I == Entries.end())
232+
return 0;
231233
StringMap<Matcher>::const_iterator II = I->second.find(Category);
232-
if (II == I->second.end()) return 0;
234+
if (II == I->second.end())
235+
return 0;
233236

234237
return II->getValue().match(Query);
235238
}

0 commit comments

Comments
 (0)