Index: lib/Basic/FileManager.cpp =================================================================== --- lib/Basic/FileManager.cpp +++ lib/Basic/FileManager.cpp @@ -390,6 +390,11 @@ UFE->UID = NextFileUID++; UFE->IsValid = true; UFE->File.reset(); + + SmallString<128> RealPathName; + if (!FS->getRealPath(InterndFileName, RealPathName)) + UFE->RealPathName = RealPathName.str(); + return UFE; } Index: unittests/Basic/FileManagerTest.cpp =================================================================== --- unittests/Basic/FileManagerTest.cpp +++ unittests/Basic/FileManagerTest.cpp @@ -322,4 +322,40 @@ EXPECT_EQ(Path, ExpectedResult); } +/// When calling getVirtualFile then getFile for the same file, the real path +/// should be computed (in other words, getVirtualFile should compute the real +/// path). +TEST_F(FileManagerTest, getVirtualFileThenGetFileRealPathName) { + SmallString<64> RealPath; + SmallString<64> NonRealPath; + SmallString<64> WorkingDirectory; + +#ifdef _WIN32 + RealPath = "C:\\a\\b"; + NonRealPath = "C:\\a\\..\\a\\b"; + WorkingDirectory = "C:\\"; +#else + RealPath = "/a/b"; + NonRealPath = "/a/../a/b"; + WorkingDirectory = "/"; +#endif + + auto FS = + IntrusiveRefCntPtr(new vfs::InMemoryFileSystem); + ASSERT_TRUE(!FS->setCurrentWorkingDirectory(WorkingDirectory)); + + FS->addFile(RealPath, 0, llvm::MemoryBuffer::getMemBuffer("")); + + FileSystemOptions Opts; + FileManager Manager(Opts, FS); + + const FileEntry *VFE = Manager.getVirtualFile(NonRealPath, 0, 0); + ASSERT_TRUE(VFE != nullptr); + EXPECT_EQ(VFE->tryGetRealPathName(), RealPath); + + const FileEntry *FE = Manager.getFile(NonRealPath); + ASSERT_TRUE(FE != nullptr); + EXPECT_EQ(FE->tryGetRealPathName(), RealPath); +} + } // anonymous namespace