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/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: 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']