From: Jan Korous Date: Thu, 14 Feb 2019 23:02:35 +0000 (+0000) Subject: [clang][FileManager] fillRealPathName even if we aren't opening the file X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5cb19f0ba23af57719f876ab5d34c5122b366ee8;p=clang [clang][FileManager] fillRealPathName even if we aren't opening the file The pathname wasn't previously filled when the getFile() method was called with openFile = false. We are caching FileEntry-s in ParsedAST::Includes in clangd and this caused the problem. This fixes an internal test failure in clangd - ClangdTests.GoToInclude.All rdar://47536127 Differential Revision: https://reviews.llvm.org/D58213 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354075 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp index 75caff9555..4102676337 100644 --- a/lib/Basic/FileManager.cpp +++ b/lib/Basic/FileManager.cpp @@ -267,6 +267,9 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile, if (UFE.File) { if (auto PathName = UFE.File->getName()) fillRealPathName(&UFE, *PathName); + } else if (!openFile) { + // We should still fill the path even if we aren't opening the file. + fillRealPathName(&UFE, InterndFileName); } return &UFE; } diff --git a/unittests/Basic/FileManagerTest.cpp b/unittests/Basic/FileManagerTest.cpp index 9f051976ca..14c7879a09 100644 --- a/unittests/Basic/FileManagerTest.cpp +++ b/unittests/Basic/FileManagerTest.cpp @@ -346,4 +346,18 @@ TEST_F(FileManagerTest, getVirtualFileFillsRealPathName) { EXPECT_EQ(file->tryGetRealPathName(), ExpectedResult); } +TEST_F(FileManagerTest, getFileDontOpenRealPath) { + auto statCache = llvm::make_unique(); + statCache->InjectDirectory("/tmp/abc", 42); + SmallString<64> Path("/tmp/abc/foo.cpp"); + statCache->InjectFile(Path.str().str().c_str(), 43); + manager.setStatCache(std::move(statCache)); + + const FileEntry *file = manager.getFile(Path, /*openFile=*/false); + + ASSERT_TRUE(file != nullptr); + + ASSERT_EQ(file->tryGetRealPathName(), Path); +} + } // anonymous namespace