diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -727,6 +727,7 @@ /// MainFile location, if none of the include search directories were prefix /// of File. /// + /// \param File A canonical absolute path to the file to be included. /// \param WorkingDir If non-empty, this will be prepended to search directory /// paths that are relative. std::string suggestPathToFileForDiagnostics(llvm::StringRef File, diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1723,7 +1723,13 @@ if (!WorkingDir.empty() && !path::is_absolute(Dir)) fs::make_absolute(WorkingDir, DirPath); path::remove_dots(DirPath, /*remove_dot_dot=*/true); - Dir = DirPath; + // Find the canonical absolute path, as that's what we expect in File + auto& FS = FileMgr.getVirtualFileSystem(); + SmallString<4096> CanonicalNameBuf; + if (!FS.getRealPath(DirPath, CanonicalNameBuf)) + Dir = CanonicalNameBuf; + else + Dir = DirPath; for (auto NI = path::begin(File), NE = path::end(File), DI = path::begin(Dir), DE = path::end(Dir); /*termination condition in loop*/; ++NI, ++DI) {