17
17
#include " llvm/ADT/STLExtras.h"
18
18
#include " llvm/Support/LineIterator.h"
19
19
#include " llvm/Support/MemoryBuffer.h"
20
- #include " llvm/Support/Path.h"
21
20
#include " llvm/Support/VirtualFileSystem.h"
22
21
#include < stdio.h>
23
22
#include < string>
@@ -67,13 +66,9 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
67
66
return Error::success ();
68
67
}
69
68
70
- unsigned SpecialCaseList::Matcher::match (StringRef Query,
71
- bool IsFilename) const {
72
- static bool HaveWindowsPathStyle =
73
- llvm::sys::path::is_style_windows (llvm::sys::path::Style::native);
69
+ unsigned SpecialCaseList::Matcher::match (StringRef Query) const {
74
70
for (const auto &Glob : reverse (Globs))
75
- if (Glob->Pattern .match (
76
- Query, /* IsSlashAgnostic=*/ (HaveWindowsPathStyle && IsFilename)))
71
+ if (Glob->Pattern .match (Query))
77
72
return Glob->LineNo ;
78
73
for (const auto &[Regex, LineNumber] : reverse (RegExes))
79
74
if (Regex->match (Query))
@@ -158,12 +153,17 @@ bool SpecialCaseList::parse(unsigned FileIdx, const MemoryBuffer *MB,
158
153
return false ;
159
154
}
160
155
156
+ // Scan the start of the file for special comments. These don't appear when
157
+ // iterating below because comment lines are automatically skipped.
158
+ StringRef Buffer = MB->getBuffer ();
161
159
// In https://reviews.llvm.org/D154014 we added glob support and planned to
162
160
// remove regex support in patterns. We temporarily support the original
163
- // behavior using regexes if "#!special-case-list-v1" is the first line of the
164
- // file. For more details, see
161
+ // behavior using regexes if "#!special-case-list-v1" is the first line of
162
+ // the file. For more details, see
165
163
// https://discourse.llvm.org/t/use-glob-instead-of-regex-for-specialcaselists/71666
166
- bool UseGlobs = !MB->getBuffer ().starts_with (" #!special-case-list-v1\n " );
164
+ bool UseGlobs = !Buffer.consume_front (" #!special-case-list-v1\n " );
165
+ // Specifies that patterns should be matched against canonicalized filepaths.
166
+ CanonicalizePaths = Buffer.consume_front (" #!canonical-paths\n " );
167
167
168
168
for (line_iterator LineIt (*MB, /* SkipBlanks=*/ true , /* CommentMarker=*/ ' #' );
169
169
!LineIt.is_at_eof (); LineIt++) {
@@ -223,8 +223,7 @@ std::pair<unsigned, unsigned>
223
223
SpecialCaseList::inSectionBlame (StringRef Section, StringRef Prefix,
224
224
StringRef Query, StringRef Category) const {
225
225
for (const auto &S : reverse (Sections)) {
226
- bool IsFilename = Prefix == " src" || Prefix == " mainfile" ;
227
- if (S.SectionMatcher ->match (Section, IsFilename)) {
226
+ if (S.SectionMatcher ->match (Section)) {
228
227
unsigned Blame = inSectionBlame (S.Entries , Prefix, Query, Category);
229
228
if (Blame)
230
229
return {S.FileIdx , Blame};
@@ -243,8 +242,12 @@ unsigned SpecialCaseList::inSectionBlame(const SectionEntries &Entries,
243
242
if (II == I->second .end ())
244
243
return 0 ;
245
244
246
- bool IsFilename = Prefix == " src" || Prefix == " mainfile" ;
247
- return II->getValue ().match (Query, IsFilename);
245
+ if (CanonicalizePaths && (Prefix == " src" || Prefix == " mainfile" )) {
246
+ return II->getValue ().match (llvm::sys::path::convert_to_slash (
247
+ llvm::sys::path::remove_leading_dotslash (Query)));
248
+ } else {
249
+ return II->getValue ().match (Query);
250
+ }
248
251
}
249
252
250
253
} // namespace llvm
0 commit comments