diff options
author | Sam McCall <sam.mccall@gmail.com> | 2022-11-25 14:01:06 +0100 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2022-11-25 14:01:39 +0100 |
commit | 1dc0a1e5d220b83c1074204bd3afd54f3bac4270 (patch) | |
tree | a9926f543ee225c997915c0a50a0408947ee6fcd /clang/lib/Lex/HeaderSearch.cpp | |
parent | c4ce8a40fa255099c16ff0965e7db8403fb87633 (diff) | |
download | llvm-1dc0a1e5d220b83c1074204bd3afd54f3bac4270.zip llvm-1dc0a1e5d220b83c1074204bd3afd54f3bac4270.tar.gz llvm-1dc0a1e5d220b83c1074204bd3afd54f3bac4270.tar.bz2 |
Revert "[Lex] Fix suggested spelling of /usr/bin/../include/foo"
This reverts commit 8bed59c7e7da2fea41a9167e15c15a8f58a5ede7.
Breaks bots e.g. https://lab.llvm.org/buildbot/#/builders/216/builds/13282
Diffstat (limited to 'clang/lib/Lex/HeaderSearch.cpp')
-rw-r--r-- | clang/lib/Lex/HeaderSearch.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 0615002..e6af122 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1928,24 +1928,32 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics( llvm::StringRef File, llvm::StringRef WorkingDir, llvm::StringRef MainFile, bool *IsSystem) { using namespace llvm::sys; - - llvm::SmallString<32> FilePath = File; - path::remove_dots(FilePath, /*remove_dot_dot=*/true); - File = FilePath; unsigned BestPrefixLength = 0; // Checks whether `Dir` is a strict path prefix of `File`. If so and that's // the longest prefix we've seen so for it, returns true and updates the // `BestPrefixLength` accordingly. - auto CheckDir = [&](llvm::SmallString<32> Dir) -> bool { + auto CheckDir = [&](llvm::StringRef Dir) -> bool { + llvm::SmallString<32> DirPath(Dir.begin(), Dir.end()); if (!WorkingDir.empty() && !path::is_absolute(Dir)) - fs::make_absolute(WorkingDir, Dir); - path::remove_dots(Dir, /*remove_dot_dot=*/true); + fs::make_absolute(WorkingDir, DirPath); + path::remove_dots(DirPath, /*remove_dot_dot=*/true); + Dir = DirPath; for (auto NI = path::begin(File), NE = path::end(File), DI = path::begin(Dir), DE = path::end(Dir); - NI != NE; ++NI, ++DI) { + /*termination condition in loop*/; ++NI, ++DI) { + // '.' components in File are ignored. + while (NI != NE && *NI == ".") + ++NI; + if (NI == NE) + break; + + // '.' components in Dir are ignored. + while (DI != DE && *DI == ".") + ++DI; if (DI == DE) { - // Dir is a prefix of File, up to choice of path separators. + // Dir is a prefix of File, up to '.' components and choice of path + // separators. unsigned PrefixLength = NI - path::begin(File); if (PrefixLength > BestPrefixLength) { BestPrefixLength = PrefixLength; |