ikudrin created this revision. ikudrin added reviewers: ioeric, bkramer, hans, thakis, rsmith, zturner. Herald added a project: clang.
This patch partially reverts D46942 <https://reviews.llvm.org/D46942>. 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 loss of the changes made in one of them. Repository: rC Clang https://reviews.llvm.org/D59415 Files: lib/Basic/FileManager.cpp test/Frontend/absolute-paths-windows.test test/Frontend/lit.local.cfg Index: test/Frontend/lit.local.cfg =================================================================== --- test/Frontend/lit.local.cfg +++ test/Frontend/lit.local.cfg @@ -1 +1 @@ -config.suffixes = ['.c', '.cpp', '.m', '.mm', '.ll', '.cl'] +config.suffixes = ['.c', '.cpp', '.m', '.mm', '.ll', '.cl', '.test'] Index: test/Frontend/absolute-paths-windows.test =================================================================== --- /dev/null +++ test/Frontend/absolute-paths-windows.test @@ -0,0 +1,9 @@ +// REQUIRES: system-windows +// RUN: rm -rf %t.dir +// RUN: mkdir -p %t.dir\real +// RUN: cmd /c mklink /j %t.dir\junc %t.dir\real +// RUN: echo "wrong code" > %t.dir\real\foo.cpp +// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-absolute-paths %t.dir\junc\foo.cpp 2>&1 | FileCheck %s + +// CHECK-NOT: .dir\real\foo.cpp +// CHECK: .dir\junc\foo.cpp Index: lib/Basic/FileManager.cpp =================================================================== --- lib/Basic/FileManager.cpp +++ lib/Basic/FileManager.cpp @@ -497,8 +497,22 @@ StringRef CanonicalName(Dir->getName()); SmallString<4096> CanonicalNameBuf; +#ifdef _WIN32 + CanonicalNameBuf = CanonicalName; + llvm::sys::fs::make_absolute(CanonicalNameBuf); + llvm::sys::path::native(CanonicalNameBuf); + // We've run into needing to remove '..' here in the wild though, so + // remove it. + // On Windows, symlinks are significantly less prevalent, so removing + // '..' is pretty safe. + // Ideally we'd have an equivalent of `realpath` and could implement + // sys::fs::canonical across all the platforms. + llvm::sys::path::remove_dots(CanonicalNameBuf, /* remove_dot_dot */ true); + CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage); +#else if (!FS->getRealPath(Dir->getName(), CanonicalNameBuf)) CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage); +#endif CanonicalDirNames.insert({Dir, CanonicalName}); return CanonicalName;
Index: test/Frontend/lit.local.cfg =================================================================== --- test/Frontend/lit.local.cfg +++ test/Frontend/lit.local.cfg @@ -1 +1 @@ -config.suffixes = ['.c', '.cpp', '.m', '.mm', '.ll', '.cl'] +config.suffixes = ['.c', '.cpp', '.m', '.mm', '.ll', '.cl', '.test'] Index: test/Frontend/absolute-paths-windows.test =================================================================== --- /dev/null +++ test/Frontend/absolute-paths-windows.test @@ -0,0 +1,9 @@ +// REQUIRES: system-windows +// RUN: rm -rf %t.dir +// RUN: mkdir -p %t.dir\real +// RUN: cmd /c mklink /j %t.dir\junc %t.dir\real +// RUN: echo "wrong code" > %t.dir\real\foo.cpp +// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-absolute-paths %t.dir\junc\foo.cpp 2>&1 | FileCheck %s + +// CHECK-NOT: .dir\real\foo.cpp +// CHECK: .dir\junc\foo.cpp Index: lib/Basic/FileManager.cpp =================================================================== --- lib/Basic/FileManager.cpp +++ lib/Basic/FileManager.cpp @@ -497,8 +497,22 @@ StringRef CanonicalName(Dir->getName()); SmallString<4096> CanonicalNameBuf; +#ifdef _WIN32 + CanonicalNameBuf = CanonicalName; + llvm::sys::fs::make_absolute(CanonicalNameBuf); + llvm::sys::path::native(CanonicalNameBuf); + // We've run into needing to remove '..' here in the wild though, so + // remove it. + // On Windows, symlinks are significantly less prevalent, so removing + // '..' is pretty safe. + // Ideally we'd have an equivalent of `realpath` and could implement + // sys::fs::canonical across all the platforms. + llvm::sys::path::remove_dots(CanonicalNameBuf, /* remove_dot_dot */ true); + CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage); +#else if (!FS->getRealPath(Dir->getName(), CanonicalNameBuf)) CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage); +#endif CanonicalDirNames.insert({Dir, CanonicalName}); return CanonicalName;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits