aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2025-11-10 13:03:20 -0800
committerGitHub <noreply@github.com>2025-11-10 21:03:20 +0000
commita37c4e0fad5289e5fdd017ea5ac6162d71fb73ae (patch)
tree0f6b0f278bc58da9f20e0de5353517f78ffbb447
parent17e26411f8b8a404e07a628ba17986a2392c1f79 (diff)
downloadllvm-a37c4e0fad5289e5fdd017ea5ac6162d71fb73ae.zip
llvm-a37c4e0fad5289e5fdd017ea5ac6162d71fb73ae.tar.gz
llvm-a37c4e0fad5289e5fdd017ea5ac6162d71fb73ae.tar.bz2
[NFC][SpecialCaseList] Hide Section internals in private section (#167276)
Preparing to moving most of implementation out of the header file. * https://github.com/llvm/llvm-project/pull/167280 --------- Co-authored-by: Naveen Seth Hanig <naveen.hanig@outlook.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
-rw-r--r--clang/lib/Basic/Diagnostic.cpp2
-rw-r--r--clang/lib/Basic/ProfileList.cpp2
-rw-r--r--clang/lib/Basic/SanitizerSpecialCaseList.cpp4
-rw-r--r--llvm/include/llvm/Support/SpecialCaseList.h23
-rw-r--r--llvm/lib/Support/SpecialCaseList.cpp8
5 files changed, 30 insertions, 9 deletions
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 2dec26e..5e9da24 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -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.
diff --git a/clang/lib/Basic/ProfileList.cpp b/clang/lib/Basic/ProfileList.cpp
index 9cb1188..8727057 100644
--- a/clang/lib/Basic/ProfileList.cpp
+++ b/clang/lib/Basic/ProfileList.cpp
@@ -36,7 +36,7 @@ public:
bool hasPrefix(StringRef Prefix) const {
for (const auto &It : sections())
- if (It.Entries.count(Prefix) > 0)
+ if (It.hasPrefix(Prefix))
return true;
return false;
}
diff --git a/clang/lib/Basic/SanitizerSpecialCaseList.cpp b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
index 56f5516..928c086 100644
--- a/clang/lib/Basic/SanitizerSpecialCaseList.cpp
+++ b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
@@ -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)
@@ -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;
diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h
index cb8e568de..dcc68b7 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -201,17 +201,22 @@ private:
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, its entire string in [].
+ StringRef name() const { return SectionStr; }
+
+ // Returns true if 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.
@@ -223,11 +228,19 @@ protected:
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; }
diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp
index 246d90c..465e10a 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -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 {
@@ -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