[PATCH] D58213: [FileManager] fillRealPathName even if we aren't opening the file

Jan Korous via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 13 15:32:56 PST 2019


jkorous created this revision.
jkorous added reviewers: sammccall, arphaman.
Herald added subscribers: cfe-commits, kadircet, dexonsmith, ioeric, ilya-biryukov.
Herald added a project: clang.

This fixes an internal test failure in clangd - ClangdTests.GoToInclude.All

rdar://47536127


Repository:
  rC Clang

https://reviews.llvm.org/D58213

Files:
  lib/Basic/FileManager.cpp
  unittests/Basic/FileManagerTest.cpp


Index: unittests/Basic/FileManagerTest.cpp
===================================================================
--- unittests/Basic/FileManagerTest.cpp
+++ unittests/Basic/FileManagerTest.cpp
@@ -346,4 +346,19 @@
   EXPECT_EQ(file->tryGetRealPathName(), ExpectedResult);
 }
 
+// rdar://problem/47536127
+TEST_F(FileManagerTest, getFileDontOpenRealPath) {
+  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);
+
+  ASSERT_TRUE(file != nullptr);
+
+  ASSERT_EQ(file->tryGetRealPathName(), Path);
+}
+
 } // anonymous namespace
Index: lib/Basic/FileManager.cpp
===================================================================
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -267,6 +267,9 @@
   if (UFE.File) {
     if (auto PathName = UFE.File->getName())
       fillRealPathName(&UFE, *PathName);
+  } else if (!openFile) {
+    // Since we didn't return early after getStatValue() call the file exists.
+    fillRealPathName(&UFE, InterndFileName);
   }
   return &UFE;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58213.186760.patch
Type: text/x-patch
Size: 1239 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190213/df521e6d/attachment.bin>


More information about the cfe-commits mailing list