Skip to content

Commit eb76cb4

Browse files
committed
rebase
Created using spr 1.3.7
2 parents cadc8fa + 5f8f1d4 commit eb76cb4

File tree

8 files changed

+202
-181
lines changed

8 files changed

+202
-181
lines changed

clang/lib/Basic/Diagnostic.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,16 +525,15 @@ std::unique_ptr<WarningsSpecialCaseList>
525525
WarningsSpecialCaseList::create(const llvm::MemoryBuffer &Input,
526526
std::string &Err) {
527527
auto WarningSuppressionList = std::make_unique<WarningsSpecialCaseList>();
528-
if (!WarningSuppressionList->createInternal(&Input, Err,
529-
/*OrderBySize=*/true))
528+
if (!WarningSuppressionList->createInternal(&Input, Err))
530529
return nullptr;
531530
return WarningSuppressionList;
532531
}
533532

534533
void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
535534
static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
536535
for (const auto &SectionEntry : sections()) {
537-
StringRef DiagGroup = SectionEntry.SectionStr;
536+
StringRef DiagGroup = SectionEntry.name();
538537
if (DiagGroup == "*") {
539538
// Drop the default section introduced by special case list, we only
540539
// 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: 22 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,11 @@
1212
#ifndef LLVM_SUPPORT_SPECIALCASELIST_H
1313
#define LLVM_SUPPORT_SPECIALCASELIST_H
1414

15-
#include "llvm/ADT/ArrayRef.h"
16-
#include "llvm/ADT/RadixTree.h"
17-
#include "llvm/ADT/SmallVector.h"
18-
#include "llvm/ADT/StringMap.h"
19-
#include "llvm/ADT/iterator_range.h"
2015
#include "llvm/Support/Allocator.h"
21-
#include "llvm/Support/Compiler.h"
22-
#include "llvm/Support/GlobPattern.h"
23-
#include "llvm/Support/Regex.h"
16+
#include "llvm/Support/Error.h"
2417
#include <memory>
2518
#include <string>
2619
#include <utility>
27-
#include <variant>
2820
#include <vector>
2921

3022
namespace llvm {
@@ -118,114 +110,45 @@ class SpecialCaseList {
118110
// classes.
119111
LLVM_ABI bool createInternal(const std::vector<std::string> &Paths,
120112
vfs::FileSystem &VFS, std::string &Error);
121-
LLVM_ABI bool createInternal(const MemoryBuffer *MB, std::string &Error,
122-
bool OrderBySize = false);
113+
LLVM_ABI bool createInternal(const MemoryBuffer *MB, std::string &Error);
123114

124115
SpecialCaseList() = default;
125116
SpecialCaseList(SpecialCaseList const &) = delete;
126117
SpecialCaseList &operator=(SpecialCaseList const &) = delete;
127118

128-
private:
129-
// Lagacy v1 matcher.
130-
class RegexMatcher {
119+
class Section {
131120
public:
132-
LLVM_ABI Error insert(StringRef Pattern, unsigned LineNumber);
133-
LLVM_ABI void preprocess(bool BySize);
134-
135-
LLVM_ABI void
136-
match(StringRef Query,
137-
llvm::function_ref<void(StringRef Rule, unsigned LineNo)> Cb) const;
138-
139-
struct Reg {
140-
Reg(StringRef Name, unsigned LineNo, Regex &&Rg)
141-
: Name(Name), LineNo(LineNo), Rg(std::move(Rg)) {}
142-
StringRef Name;
143-
unsigned LineNo;
144-
Regex Rg;
145-
};
146-
147-
std::vector<Reg> RegExes;
148-
};
149-
150-
class GlobMatcher {
151-
public:
152-
LLVM_ABI Error insert(StringRef Pattern, unsigned LineNumber);
153-
LLVM_ABI void preprocess(bool BySize);
154-
155-
LLVM_ABI void
156-
match(StringRef Query,
157-
llvm::function_ref<void(StringRef Rule, unsigned LineNo)> Cb) const;
158-
159-
struct Glob {
160-
Glob(StringRef Name, unsigned LineNo, GlobPattern &&Pattern)
161-
: Name(Name), LineNo(LineNo), Pattern(std::move(Pattern)) {}
162-
StringRef Name;
163-
unsigned LineNo;
164-
GlobPattern Pattern;
165-
};
166-
167-
std::vector<GlobMatcher::Glob> Globs;
168-
169-
RadixTree<iterator_range<StringRef::const_iterator>,
170-
RadixTree<iterator_range<StringRef::const_reverse_iterator>,
171-
SmallVector<const GlobMatcher::Glob *, 1>>>
172-
PrefixSuffixToGlob;
173-
174-
RadixTree<iterator_range<StringRef::const_iterator>,
175-
SmallVector<const GlobMatcher::Glob *, 1>>
176-
SubstrToGlob;
177-
};
178-
179-
/// Represents a set of patterns and their line numbers
180-
class Matcher {
181-
public:
182-
LLVM_ABI Matcher(bool UseGlobs, bool RemoveDotSlash);
183-
184-
LLVM_ABI Error insert(StringRef Pattern, unsigned LineNumber);
185-
LLVM_ABI void preprocess(bool BySize);
186-
187-
LLVM_ABI void
188-
match(StringRef Query,
189-
llvm::function_ref<void(StringRef Rule, unsigned LineNo)> Cb) const;
121+
LLVM_ABI Section(StringRef Name, unsigned FileIdx, bool UseGlobs);
122+
LLVM_ABI Section(Section &&);
123+
LLVM_ABI ~Section();
190124

191-
LLVM_ABI bool matchAny(StringRef Query) const {
192-
bool R = false;
193-
match(Query, [&](StringRef, unsigned) { R = true; });
194-
return R;
195-
}
125+
// Return name of the section, it's entire string in [].
126+
StringRef name() const { return Name; }
196127

197-
std::variant<RegexMatcher, GlobMatcher> M;
198-
bool RemoveDotSlash;
199-
};
200-
201-
using SectionEntries = StringMap<StringMap<Matcher>>;
128+
// Returns true of string 'Name' matches section name interpreted as a glob.
129+
LLVM_ABI bool matchName(StringRef Name) const;
202130

203-
protected:
204-
struct Section {
205-
Section(StringRef Str, unsigned FileIdx, bool UseGlobs)
206-
: SectionMatcher(UseGlobs, /*RemoveDotSlash=*/false), SectionStr(Str),
207-
FileIdx(FileIdx) {}
208-
209-
Section(Section &&) = default;
210-
211-
Matcher SectionMatcher;
212-
SectionEntries Entries;
213-
std::string SectionStr;
214-
unsigned FileIdx;
131+
// Return sequence number of the file where this section is defined.
132+
unsigned fileIndex() const { return FileIdx; }
215133

216134
// Helper method to search by Prefix, Query, and Category. Returns
217135
// 1-based line number on which rule is defined, or 0 if there is no match.
218136
LLVM_ABI unsigned getLastMatch(StringRef Prefix, StringRef Query,
219137
StringRef Category) const;
220138

139+
/// Returns true if the section has any entries for the given prefix.
140+
LLVM_ABI bool hasPrefix(StringRef Prefix) const;
141+
221142
private:
222143
friend class SpecialCaseList;
223-
LLVM_ABI void preprocess(bool OrderBySize);
224-
LLVM_ABI const SpecialCaseList::Matcher *
225-
findMatcher(StringRef Prefix, StringRef Category) const;
144+
class SectionImpl;
145+
146+
StringRef Name;
147+
unsigned FileIdx;
148+
std::unique_ptr<SectionImpl> Impl;
226149
};
227150

228-
ArrayRef<const Section> sections() const { return Sections; }
151+
const std::vector<Section> &sections() const;
229152

230153
private:
231154
BumpPtrAllocator StrAlloc;
@@ -237,7 +160,7 @@ class SpecialCaseList {
237160

238161
/// Parses just-constructed SpecialCaseList entries from a memory buffer.
239162
LLVM_ABI bool parse(unsigned FileIdx, const MemoryBuffer *MB,
240-
std::string &Error, bool OrderBySize);
163+
std::string &Error);
241164
};
242165

243166
} // namespace llvm

llvm/lib/ObjectYAML/ELFYAML.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO,
670670
for (unsigned K = ELF::EF_AMDGPU_GENERIC_VERSION_MIN;
671671
K <= ELF::EF_AMDGPU_GENERIC_VERSION_MAX; ++K) {
672672
std::string Key = "EF_AMDGPU_GENERIC_VERSION_V" + std::to_string(K);
673-
IO.maskedBitSetCase(Value, Key.c_str(),
673+
IO.maskedBitSetCase(Value, Key,
674674
K << ELF::EF_AMDGPU_GENERIC_VERSION_OFFSET,
675675
ELF::EF_AMDGPU_GENERIC_VERSION);
676676
}

0 commit comments

Comments
 (0)