Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion clang/lib/Basic/Diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ WarningsSpecialCaseList::create(const llvm::MemoryBuffer &Input,
void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
for (const auto &SectionEntry : sections()) {
StringRef DiagGroup = SectionEntry.SectionStr;
StringRef DiagGroup = SectionEntry.name();
if (DiagGroup == "*") {
// Drop the default section introduced by special case list, we only
// support exact diagnostic group names.
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 @@ -36,7 +36,7 @@ class ProfileSpecialCaseList : public llvm::SpecialCaseList {

bool hasPrefix(StringRef Prefix) const {
for (const auto &It : sections())
if (It.Entries.count(Prefix) > 0)
if (It.hasPrefix(Prefix))
return true;
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Basic/SanitizerSpecialCaseList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void SanitizerSpecialCaseList::createSanitizerSections() {
SanitizerMask Mask;

#define SANITIZER(NAME, ID) \
if (S.SectionMatcher.matchAny(NAME)) \
if (S.matchName(NAME)) \
Mask |= SanitizerKind::ID;
#define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID)

Expand All @@ -68,7 +68,7 @@ SanitizerSpecialCaseList::inSectionBlame(SanitizerMask Mask, StringRef Prefix,
if (S.Mask & Mask) {
unsigned LineNum = S.S.getLastMatch(Prefix, Query, Category);
if (LineNum > 0)
return {S.S.FileIdx, LineNum};
return {S.S.fileIndex(), LineNum};
}
}
return NotFound;
Expand Down
23 changes: 18 additions & 5 deletions llvm/include/llvm/Support/SpecialCaseList.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,22 @@ class SpecialCaseList {
using SectionEntries = StringMap<StringMap<Matcher>>;

protected:
struct Section {
class Section {
public:
Section(StringRef Str, unsigned FileIdx, bool UseGlobs)
: SectionMatcher(UseGlobs, /*RemoveDotSlash=*/false), SectionStr(Str),
FileIdx(FileIdx) {}

Section(Section &&) = default;

Matcher SectionMatcher;
SectionEntries Entries;
std::string SectionStr;
unsigned FileIdx;
// Return name of the section, it's entire string in [].
StringRef name() const { return SectionStr; }

// Returns true of string 'Name' matches section name interpreted as a glob.
LLVM_ABI bool matchName(StringRef Name) const;

// Return sequence number of the file where this section is defined.
unsigned fileIndex() const { return FileIdx; }

// Helper method to search by Prefix, Query, and Category. Returns
// 1-based line number on which rule is defined, or 0 if there is no match.
Expand All @@ -223,11 +228,19 @@ class SpecialCaseList {
LLVM_ABI StringRef getLongestMatch(StringRef Prefix, StringRef Query,
StringRef Category) const;

/// Returns true if the section has any entries for the given prefix.
LLVM_ABI bool hasPrefix(StringRef Prefix) const;

private:
friend class SpecialCaseList;
LLVM_ABI void preprocess(bool OrderBySize);
LLVM_ABI const SpecialCaseList::Matcher *
findMatcher(StringRef Prefix, StringRef Category) const;

Matcher SectionMatcher;
std::string SectionStr;
SectionEntries Entries;
unsigned FileIdx;
};

ArrayRef<const Section> sections() const { return Sections; }
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/Support/SpecialCaseList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix,
return NotFound;
}

bool SpecialCaseList::Section::matchName(StringRef Name) const {
return SectionMatcher.matchAny(Name);
}

const SpecialCaseList::Matcher *
SpecialCaseList::Section::findMatcher(StringRef Prefix,
StringRef Category) const {
Expand Down Expand Up @@ -393,4 +397,8 @@ StringRef SpecialCaseList::Section::getLongestMatch(StringRef Prefix,
return LongestRule;
}

bool SpecialCaseList::Section::hasPrefix(StringRef Prefix) const {
return Entries.find(Prefix) != Entries.end();
}

} // namespace llvm
Loading