r354291 - Reland "[clang][FileManager] fillRealPathName even if we aren't opening the file"
Jan Korous via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 18 14:33:40 PST 2019
Author: jkorous
Date: Mon Feb 18 14:33:40 2019
New Revision: 354291
URL: http://llvm.org/viewvc/llvm-project?rev=354291&view=rev
Log:
Reland "[clang][FileManager] fillRealPathName even if we aren't opening the file"
This reverts commit e2bb3121fd4ab5b01f9ec1d2e3e9877db9c6a54c.
+ fixed test for Windows
Modified:
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/unittests/Basic/FileManagerTest.cpp
Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=354291&r1=354290&r2=354291&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Mon Feb 18 14:33:40 2019
@@ -267,6 +267,9 @@ const FileEntry *FileManager::getFile(St
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;
}
Modified: cfe/trunk/unittests/Basic/FileManagerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/FileManagerTest.cpp?rev=354291&r1=354290&r2=354291&view=diff
==============================================================================
--- cfe/trunk/unittests/Basic/FileManagerTest.cpp (original)
+++ cfe/trunk/unittests/Basic/FileManagerTest.cpp Mon Feb 18 14:33:40 2019
@@ -346,4 +346,33 @@ TEST_F(FileManagerTest, getVirtualFileFi
EXPECT_EQ(file->tryGetRealPathName(), ExpectedResult);
}
+TEST_F(FileManagerTest, getFileDontOpenRealPath) {
+ SmallString<64> CustomWorkingDir;
+#ifdef _WIN32
+ CustomWorkingDir = "C:/";
+#else
+ CustomWorkingDir = "/";
+#endif
+
+ auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>(
+ new llvm::vfs::InMemoryFileSystem);
+ // setCurrentworkingdirectory must finish without error.
+ ASSERT_TRUE(!FS->setCurrentWorkingDirectory(CustomWorkingDir));
+
+ FileSystemOptions Opts;
+ FileManager Manager(Opts, FS);
+
+ auto statCache = llvm::make_unique<FakeStatCache>();
+ 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
More information about the cfe-commits
mailing list