Skip to content

Commit a37c4e0

Browse files
vitalybukanaveen-sethCopilot
authored
[NFC][SpecialCaseList] Hide Section internals in private section (#167276)
Preparing to moving most of implementation out of the header file. * #167280 --------- Co-authored-by: Naveen Seth Hanig <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 17e2641 commit a37c4e0

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

clang/lib/Basic/Diagnostic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ WarningsSpecialCaseList::create(const llvm::MemoryBuffer &Input,
534534
void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
535535
static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
536536
for (const auto &SectionEntry : sections()) {
537-
StringRef DiagGroup = SectionEntry.SectionStr;
537+
StringRef DiagGroup = SectionEntry.name();
538538
if (DiagGroup == "*") {
539539
// Drop the default section introduced by special case list, we only
540540
// support exact diagnostic group names.

clang/lib/Basic/ProfileList.cpp

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

3737
bool hasPrefix(StringRef Prefix) const {
3838
for (const auto &It : sections())
39-
if (It.Entries.count(Prefix) > 0)
39+
if (It.hasPrefix(Prefix))
4040
return true;
4141
return false;
4242
}

clang/lib/Basic/SanitizerSpecialCaseList.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void SanitizerSpecialCaseList::createSanitizerSections() {
4242
SanitizerMask Mask;
4343

4444
#define SANITIZER(NAME, ID) \
45-
if (S.SectionMatcher.matchAny(NAME)) \
45+
if (S.matchName(NAME)) \
4646
Mask |= SanitizerKind::ID;
4747
#define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID)
4848

@@ -68,7 +68,7 @@ SanitizerSpecialCaseList::inSectionBlame(SanitizerMask Mask, StringRef Prefix,
6868
if (S.Mask & Mask) {
6969
unsigned LineNum = S.S.getLastMatch(Prefix, Query, Category);
7070
if (LineNum > 0)
71-
return {S.S.FileIdx, LineNum};
71+
return {S.S.fileIndex(), LineNum};
7272
}
7373
}
7474
return NotFound;

llvm/include/llvm/Support/SpecialCaseList.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,22 @@ class SpecialCaseList {
201201
using SectionEntries = StringMap<StringMap<Matcher>>;
202202

203203
protected:
204-
struct Section {
204+
class Section {
205+
public:
205206
Section(StringRef Str, unsigned FileIdx, bool UseGlobs)
206207
: SectionMatcher(UseGlobs, /*RemoveDotSlash=*/false), SectionStr(Str),
207208
FileIdx(FileIdx) {}
208209

209210
Section(Section &&) = default;
210211

211-
Matcher SectionMatcher;
212-
SectionEntries Entries;
213-
std::string SectionStr;
214-
unsigned FileIdx;
212+
// Return name of the section, its entire string in [].
213+
StringRef name() const { return SectionStr; }
214+
215+
// Returns true if string 'Name' matches section name interpreted as a glob.
216+
LLVM_ABI bool matchName(StringRef Name) const;
217+
218+
// Return sequence number of the file where this section is defined.
219+
unsigned fileIndex() const { return FileIdx; }
215220

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

231+
/// Returns true if the section has any entries for the given prefix.
232+
LLVM_ABI bool hasPrefix(StringRef Prefix) const;
233+
226234
private:
227235
friend class SpecialCaseList;
228236
LLVM_ABI void preprocess(bool OrderBySize);
229237
LLVM_ABI const SpecialCaseList::Matcher *
230238
findMatcher(StringRef Prefix, StringRef Category) const;
239+
240+
Matcher SectionMatcher;
241+
std::string SectionStr;
242+
SectionEntries Entries;
243+
unsigned FileIdx;
231244
};
232245

233246
ArrayRef<const Section> sections() const { return Sections; }

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix,
348348
return NotFound;
349349
}
350350

351+
bool SpecialCaseList::Section::matchName(StringRef Name) const {
352+
return SectionMatcher.matchAny(Name);
353+
}
354+
351355
const SpecialCaseList::Matcher *
352356
SpecialCaseList::Section::findMatcher(StringRef Prefix,
353357
StringRef Category) const {
@@ -393,4 +397,8 @@ StringRef SpecialCaseList::Section::getLongestMatch(StringRef Prefix,
393397
return LongestRule;
394398
}
395399

400+
bool SpecialCaseList::Section::hasPrefix(StringRef Prefix) const {
401+
return Entries.find(Prefix) != Entries.end();
402+
}
403+
396404
} // namespace llvm

0 commit comments

Comments
 (0)