1717#include " llvm/ADT/STLExtras.h"
1818#include " llvm/Support/LineIterator.h"
1919#include " llvm/Support/MemoryBuffer.h"
20+ #include " llvm/Support/Path.h"
2021#include " llvm/Support/VirtualFileSystem.h"
21- #include " llvm/TargetParser/Host.h"
22- #include " llvm/TargetParser/Triple.h"
2322#include < stdio.h>
2423#include < string>
2524#include < system_error>
@@ -59,21 +58,22 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
5958 auto Glob = std::make_unique<Matcher::Glob>();
6059 Glob->Name = Pattern.str ();
6160 Glob->LineNo = LineNumber;
62- // Backslashes are valid in posix-style filenames.
63- bool IsSlashAgnostic = Triple (sys::getDefaultTargetTriple ()).isOSWindows ();
6461 // We must be sure to use the string in `Glob` rather than the provided
6562 // reference which could be destroyed before match() is called
66- if (auto Err = GlobPattern::create (Glob->Name , /* MaxSubPatterns=*/ 1024 ,
67- /* IsSlashAgnostic=*/ IsSlashAgnostic)
63+ if (auto Err = GlobPattern::create (Glob->Name , /* MaxSubPatterns=*/ 1024 )
6864 .moveInto (Glob->Pattern ))
6965 return Err;
7066 Globs.push_back (std::move (Glob));
7167 return Error::success ();
7268}
7369
74- unsigned SpecialCaseList::Matcher::match (StringRef Query) const {
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);
7574 for (const auto &Glob : reverse (Globs))
76- if (Glob->Pattern .match (Query))
75+ if (Glob->Pattern .match (
76+ Query, /* IsSlashAgnostic=*/ (HaveWindowsPathStyle && IsFilename)))
7777 return Glob->LineNo ;
7878 for (const auto &[Regex, LineNumber] : reverse (RegExes))
7979 if (Regex->match (Query))
@@ -223,7 +223,8 @@ std::pair<unsigned, unsigned>
223223SpecialCaseList::inSectionBlame (StringRef Section, StringRef Prefix,
224224 StringRef Query, StringRef Category) const {
225225 for (const auto &S : reverse (Sections)) {
226- if (S.SectionMatcher ->match (Section)) {
226+ bool IsFilename = Prefix == " src" || Prefix == " mainfile" ;
227+ if (S.SectionMatcher ->match (Section, IsFilename)) {
227228 unsigned Blame = inSectionBlame (S.Entries , Prefix, Query, Category);
228229 if (Blame)
229230 return {S.FileIdx , Blame};
@@ -242,7 +243,8 @@ unsigned SpecialCaseList::inSectionBlame(const SectionEntries &Entries,
242243 if (II == I->second .end ())
243244 return 0 ;
244245
245- return II->getValue ().match (Query);
246+ bool IsFilename = Prefix == " src" || Prefix == " mainfile" ;
247+ return II->getValue ().match (Query, IsFilename);
246248}
247249
248250} // namespace llvm
0 commit comments