diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -1224,6 +1224,11 @@ ExternalFS->getCurrentWorkingDirectory()) { WorkingDirectory = *ExternalWorkingDirectory; } + if (WorkingDirectory == "") { + SmallString<256> cwd; + llvm::sys::fs::current_path(cwd); + WorkingDirectory = std::string(cwd); + } } /// Directory iterator implementation for \c RedirectingFileSystem's @@ -1927,7 +1932,7 @@ EC = FS->makeAbsolute(FullPath, Name); Name = canonicalize(Name); } else { - EC = sys::fs::make_absolute(Name); + EC = FS->makeAbsolute(Name); } if (EC) { assert(NameValueNode && "Name presence should be checked earlier"); diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -2408,8 +2408,6 @@ TEST_F(VFSFromYAMLTest, RelativePaths) { IntrusiveRefCntPtr Lower(new DummyFileSystem()); std::error_code EC; - SmallString<128> CWD; - EC = llvm::sys::fs::current_path(CWD); ASSERT_FALSE(EC); // Filename at root level without a parent directory. @@ -2421,9 +2419,12 @@ "] }", Lower); ASSERT_TRUE(FS.get() != nullptr); + llvm::ErrorOr CWD = FS->getCurrentWorkingDirectory(); + ASSERT_TRUE(CWD); + SmallString<128> ExpectedPathNotInDir("file-not-in-directory.h"); llvm::sys::fs::make_absolute(ExpectedPathNotInDir); - checkContents(FS->dir_begin(CWD, EC), {ExpectedPathNotInDir}); + checkContents(FS->dir_begin(CWD.get(), EC), {ExpectedPathNotInDir}); // Relative file path. FS = getFromYAMLString("{ 'roots': [\n" @@ -2439,7 +2440,7 @@ ASSERT_FALSE(EC); // Convert to POSIX path for comparison of windows paths ASSERT_EQ("relative/path.h", - getPosixPath(std::string(I->path().substr(CWD.size() + 1)))); + getPosixPath(std::string(I->path().substr(CWD->size() + 1)))); // Relative directory path. FS = getFromYAMLString(