1717#include " llvm/ADT/STLExtras.h"
1818#include " llvm/Support/LineIterator.h"
1919#include " llvm/Support/MemoryBuffer.h"
20- #include " llvm/Support/Path.h"
2120#include " llvm/Support/VirtualFileSystem.h"
2221#include < stdio.h>
2322#include < string>
@@ -67,13 +66,9 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
6766 return Error::success ();
6867}
6968
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 {
7470 for (const auto &Glob : reverse (Globs))
75- if (Glob->Pattern .match (
76- Query, /* IsSlashAgnostic=*/ (HaveWindowsPathStyle && IsFilename)))
71+ if (Glob->Pattern .match (Query))
7772 return Glob->LineNo ;
7873 for (const auto &[Regex, LineNumber] : reverse (RegExes))
7974 if (Regex->match (Query))
@@ -158,12 +153,17 @@ bool SpecialCaseList::parse(unsigned FileIdx, const MemoryBuffer *MB,
158153 return false ;
159154 }
160155
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 ();
161159 // In https://reviews.llvm.org/D154014 we added glob support and planned to
162160 // 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
165163 // 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 " );
167167
168168 for (line_iterator LineIt (*MB, /* SkipBlanks=*/ true , /* CommentMarker=*/ ' #' );
169169 !LineIt.is_at_eof (); LineIt++) {
@@ -223,8 +223,7 @@ std::pair<unsigned, unsigned>
223223SpecialCaseList::inSectionBlame (StringRef Section, StringRef Prefix,
224224 StringRef Query, StringRef Category) const {
225225 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)) {
228227 unsigned Blame = inSectionBlame (S.Entries , Prefix, Query, Category);
229228 if (Blame)
230229 return {S.FileIdx , Blame};
@@ -243,8 +242,12 @@ unsigned SpecialCaseList::inSectionBlame(const SectionEntries &Entries,
243242 if (II == I->second .end ())
244243 return 0 ;
245244
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+ }
248251}
249252
250253} // namespace llvm
0 commit comments