summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/TextDiagnostic.cpp
diff options
context:
space:
mode:
authorIgor Kudrin <ikudrin@accesssoftek.com>2019-05-24 04:46:22 +0000
committerIgor Kudrin <ikudrin@accesssoftek.com>2019-05-24 04:46:22 +0000
commit0de4e935bb591b8c9ee41a9acbb5cda02838d8a6 (patch)
treec09ae9e3168beffad7148356958849241e8401ac /clang/lib/Frontend/TextDiagnostic.cpp
parent0ee23c958bbcf6955568d5287d1495f485426800 (diff)
downloadbcm5719-llvm-0de4e935bb591b8c9ee41a9acbb5cda02838d8a6.tar.gz
bcm5719-llvm-0de4e935bb591b8c9ee41a9acbb5cda02838d8a6.zip
Do not resolve directory junctions for `-fdiagnostics-absolute-paths` on Windows.
If the source file path contains directory junctions, and we resolve them when printing diagnostic messages, these paths look independent for an IDE. For example, both Visual Studio and Visual Studio Code open separate editors for such paths, which is not only inconvenient but might even result in losing changes made in one of them. Differential Revision: https://reviews.llvm.org/D59415 llvm-svn: 361598
Diffstat (limited to 'clang/lib/Frontend/TextDiagnostic.cpp')
-rw-r--r--clang/lib/Frontend/TextDiagnostic.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp
index c6ebdcaf9a8..d0c91286250 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -765,7 +765,28 @@ void TextDiagnostic::emitFilename(StringRef Filename, const SourceManager &SM) {
const DirectoryEntry *Dir = SM.getFileManager().getDirectory(
llvm::sys::path::parent_path(Filename));
if (Dir) {
+ // We want to print a simplified absolute path, i. e. without "dots".
+ //
+ // The hardest part here are the paths like "<part1>/<link>/../<part2>".
+ // On Unix-like systems, we cannot just collapse "<link>/..", because
+ // paths are resolved sequentially, and, thereby, the path
+ // "<part1>/<part2>" may point to a different location. That is why
+ // we use FileManager::getCanonicalName(), which expands all indirections
+ // with llvm::sys::fs::real_path() and caches the result.
+ //
+ // On the other hand, it would be better to preserve as much of the
+ // original path as possible, because that helps a user to recognize it.
+ // real_path() expands all links, which sometimes too much. Luckily,
+ // on Windows we can just use llvm::sys::path::remove_dots(), because,
+ // on that system, both aforementioned paths point to the same place.
+#ifdef _WIN32
+ SmallString<4096> DirName = Dir->getName();
+ llvm::sys::fs::make_absolute(DirName);
+ llvm::sys::path::native(DirName);
+ llvm::sys::path::remove_dots(DirName, /* remove_dot_dot */ true);
+#else
StringRef DirName = SM.getFileManager().getCanonicalName(Dir);
+#endif
llvm::sys::path::append(AbsoluteFilename, DirName,
llvm::sys::path::filename(Filename));
Filename = StringRef(AbsoluteFilename.data(), AbsoluteFilename.size());
OpenPOWER on IntegriCloud