Skip to content

Commit f0fb292

Browse files
committed
Enable only for special case list
1 parent fb0d93f commit f0fb292

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

llvm/include/llvm/Support/GlobPattern.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ class GlobPattern {
5656
/// \param MaxSubPatterns if provided limit the number of allowed subpatterns
5757
/// created from expanding braces otherwise disable
5858
/// brace expansion
59+
/// \param IsSlashAgnostic whether to treat '/' as matching '\\' as well
5960
LLVM_ABI static Expected<GlobPattern>
60-
create(StringRef Pat, std::optional<size_t> MaxSubPatterns = {});
61+
create(StringRef Pat, std::optional<size_t> MaxSubPatterns = {},
62+
bool IsSlashAgnostic = false);
6163
/// \returns \p true if \p S matches this glob pattern
6264
LLVM_ABI bool match(StringRef S) const;
6365

@@ -76,7 +78,9 @@ class GlobPattern {
7678

7779
struct SubGlobPattern {
7880
/// \param Pat the pattern to match against
79-
LLVM_ABI static Expected<SubGlobPattern> create(StringRef Pat);
81+
/// \param SlashAgnostic whether to treat '/' as matching '\\' as well
82+
LLVM_ABI static Expected<SubGlobPattern> create(StringRef Pat,
83+
bool SlashAgnostic);
8084
/// \returns \p true if \p S matches this glob pattern
8185
LLVM_ABI bool match(StringRef S) const;
8286
StringRef getPat() const { return StringRef(Pat.data(), Pat.size()); }
@@ -88,6 +92,7 @@ class GlobPattern {
8892
};
8993
SmallVector<Bracket, 0> Brackets;
9094
SmallVector<char, 0> Pat;
95+
bool IsSlashAgnostic;
9196
};
9297
SmallVector<SubGlobPattern, 1> SubGlobs;
9398
};

llvm/lib/Support/GlobPattern.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ parseBraceExpansions(StringRef S, std::optional<size_t> MaxSubPatterns) {
132132
return std::move(SubPatterns);
133133
}
134134

135-
Expected<GlobPattern>
136-
GlobPattern::create(StringRef S, std::optional<size_t> MaxSubPatterns) {
135+
Expected<GlobPattern> GlobPattern::create(StringRef S,
136+
std::optional<size_t> MaxSubPatterns,
137+
bool IsSlashAgnostic) {
137138
GlobPattern Pat;
138139

139140
// Store the prefix that does not contain any metacharacter.
@@ -147,7 +148,7 @@ GlobPattern::create(StringRef S, std::optional<size_t> MaxSubPatterns) {
147148
if (auto Err = parseBraceExpansions(S, MaxSubPatterns).moveInto(SubPats))
148149
return std::move(Err);
149150
for (StringRef SubPat : SubPats) {
150-
auto SubGlobOrErr = SubGlobPattern::create(SubPat);
151+
auto SubGlobOrErr = SubGlobPattern::create(SubPat, IsSlashAgnostic);
151152
if (!SubGlobOrErr)
152153
return SubGlobOrErr.takeError();
153154
Pat.SubGlobs.push_back(*SubGlobOrErr);
@@ -157,8 +158,9 @@ GlobPattern::create(StringRef S, std::optional<size_t> MaxSubPatterns) {
157158
}
158159

159160
Expected<GlobPattern::SubGlobPattern>
160-
GlobPattern::SubGlobPattern::create(StringRef S) {
161+
GlobPattern::SubGlobPattern::create(StringRef S, bool SlashAgnostic) {
161162
SubGlobPattern Pat;
163+
Pat.IsSlashAgnostic = SlashAgnostic;
162164

163165
// Parse brackets.
164166
Pat.Pat.assign(S.begin(), S.end());
@@ -231,7 +233,7 @@ bool GlobPattern::SubGlobPattern::match(StringRef Str) const {
231233
++S;
232234
continue;
233235
}
234-
} else if (*P == '/' && (*S == '/' || *S == '\\')) {
236+
} else if (IsSlashAgnostic && *P == '/' && (*S == '/' || *S == '\\')) {
235237
++P;
236238
++S;
237239
continue;

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
5959
Glob->LineNo = LineNumber;
6060
// We must be sure to use the string in `Glob` rather than the provided
6161
// reference which could be destroyed before match() is called
62-
if (auto Err = GlobPattern::create(Glob->Name, /*MaxSubPatterns=*/1024)
62+
if (auto Err = GlobPattern::create(Glob->Name, /*MaxSubPatterns=*/1024,
63+
/*IsSlashAgnostic=*/true)
6364
.moveInto(Glob->Pattern))
6465
return Err;
6566
Globs.push_back(std::move(Glob));

0 commit comments

Comments
 (0)