diff options
author | Karl-Johan Karlsson <karl-johan.karlsson@ericsson.com> | 2019-12-20 08:07:22 +0100 |
---|---|---|
committer | Karl-Johan Karlsson <karl-johan.karlsson@ericsson.com> | 2019-12-20 09:16:33 +0100 |
commit | e8efac4b15303932581c128dc3976f4359388338 (patch) | |
tree | 54eb78ed9fb4092070250e9b255eddd89e711a3d /clang/lib/Frontend/TextDiagnostic.cpp | |
parent | 92211bf0f15ba46b5eeb88b7ea580ff539dcdd4e (diff) | |
download | bcm5719-llvm-e8efac4b15303932581c128dc3976f4359388338.tar.gz bcm5719-llvm-e8efac4b15303932581c128dc3976f4359388338.zip |
[clang] Fix the canonicalization of paths in -fdiagnostics-absolute-paths
In the current implementation of clang the canonicalization of paths in
diagnostic messages (when using -fdiagnostics-absolute-paths) only works
if the symbolic link is in the directory part of the filename, not if
the file itself is a symbolic link to another file.
This patch adds support to canonicalize the complete path including the
file.
Reviewers: rsmith, hans, rnk, ikudrin
Reviewed By: rnk
Differential Revision: https://reviews.llvm.org/D70527
Diffstat (limited to 'clang/lib/Frontend/TextDiagnostic.cpp')
-rw-r--r-- | clang/lib/Frontend/TextDiagnostic.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp index 7bb6c5b74d5..78acaaf9f96 100644 --- a/clang/lib/Frontend/TextDiagnostic.cpp +++ b/clang/lib/Frontend/TextDiagnostic.cpp @@ -761,11 +761,12 @@ void TextDiagnostic::printDiagnosticMessage(raw_ostream &OS, } void TextDiagnostic::emitFilename(StringRef Filename, const SourceManager &SM) { - SmallVector<char, 128> AbsoluteFilename; +#ifdef _WIN32 + SmallString<4096> TmpFilename; +#endif if (DiagOpts->AbsolutePath) { - auto Dir = SM.getFileManager().getDirectory( - llvm::sys::path::parent_path(Filename)); - if (Dir) { + auto File = SM.getFileManager().getFile(Filename); + if (File) { // We want to print a simplified absolute path, i. e. without "dots". // // The hardest part here are the paths like "<part1>/<link>/../<part2>". @@ -781,16 +782,14 @@ void TextDiagnostic::emitFilename(StringRef Filename, const SourceManager &SM) { // 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); + TmpFilename = (*File)->getName(); + llvm::sys::fs::make_absolute(TmpFilename); + llvm::sys::path::native(TmpFilename); + llvm::sys::path::remove_dots(TmpFilename, /* remove_dot_dot */ true); + Filename = StringRef(TmpFilename.data(), TmpFilename.size()); #else - StringRef DirName = SM.getFileManager().getCanonicalName(*Dir); + Filename = SM.getFileManager().getCanonicalName(*File); #endif - llvm::sys::path::append(AbsoluteFilename, DirName, - llvm::sys::path::filename(Filename)); - Filename = StringRef(AbsoluteFilename.data(), AbsoluteFilename.size()); } } |