@@ -1853,11 +1853,18 @@ static void diagnoseAutoModuleImport(
1853
1853
// path to the file, build a properly-cased replacement in the vector,
1854
1854
// and return true if the replacement should be suggested.
1855
1855
static bool trySimplifyPath (SmallVectorImpl<StringRef> &Components,
1856
- StringRef RealPathName) {
1856
+ StringRef RealPathName,
1857
+ llvm::sys::path::Style Separator) {
1857
1858
auto RealPathComponentIter = llvm::sys::path::rbegin (RealPathName);
1858
1859
auto RealPathComponentEnd = llvm::sys::path::rend (RealPathName);
1859
1860
int Cnt = 0 ;
1860
1861
bool SuggestReplacement = false ;
1862
+
1863
+ auto IsSep = [Separator](StringRef Component) {
1864
+ return Component.size () == 1 &&
1865
+ llvm::sys::path::is_separator (Component[0 ], Separator);
1866
+ };
1867
+
1861
1868
// Below is a best-effort to handle ".." in paths. It is admittedly
1862
1869
// not 100% correct in the presence of symlinks.
1863
1870
for (auto &Component : llvm::reverse (Components)) {
@@ -1867,10 +1874,11 @@ static bool trySimplifyPath(SmallVectorImpl<StringRef> &Components,
1867
1874
} else if (Cnt) {
1868
1875
--Cnt;
1869
1876
} else if (RealPathComponentIter != RealPathComponentEnd) {
1870
- if (Component != *RealPathComponentIter) {
1871
- // If these path components differ by more than just case, then we
1872
- // may be looking at symlinked paths. Bail on this diagnostic to avoid
1873
- // noisy false positives.
1877
+ if (!IsSep (Component) && !IsSep (*RealPathComponentIter) &&
1878
+ Component != *RealPathComponentIter) {
1879
+ // If these non-separator path components differ by more than just case,
1880
+ // then we may be looking at symlinked paths. Bail on this diagnostic to
1881
+ // avoid noisy false positives.
1874
1882
SuggestReplacement =
1875
1883
RealPathComponentIter->equals_insensitive (Component);
1876
1884
if (!SuggestReplacement)
@@ -2523,7 +2531,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
2523
2531
}
2524
2532
#endif
2525
2533
2526
- if (trySimplifyPath (Components, RealPathName)) {
2534
+ if (trySimplifyPath (Components, RealPathName, BackslashStyle )) {
2527
2535
SmallString<128 > Path;
2528
2536
Path.reserve (Name.size ()+2 );
2529
2537
Path.push_back (isAngled ? ' <' : ' "' );
@@ -2546,7 +2554,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
2546
2554
// got copied when the C: was processed and we want to skip that entry.
2547
2555
if (!(Component.size () == 1 && IsSep (Component[0 ])))
2548
2556
Path.append (Component);
2549
- else if (! Path.empty () )
2557
+ else if (Path.size () != 1 )
2550
2558
continue ;
2551
2559
2552
2560
// Append the separator(s) the user used, or the close quote
0 commit comments