<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">I didn't realize it just copied a string. I just saw a call to "fillRealPathName" and the "RealPath" bit sounded slow. From clicking around in <a href="http://llvm-cs.pcc.me.uk/tools/clang/lib/Basic/FileManager.cpp#361">http://llvm-cs.pcc.me.uk/tools/clang/lib/Basic/FileManager.cpp#361</a> it looks like it's not really computing a realpath (for symlinks). It still does quite a bit of string processing if InterndFileName isn't absolute, but that's probably fine. It's still the kind of thing I'd carefully measure since getFile(openFile=false) was performance-sensitive in a certain case iirc (I think when using pch files?)</div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 18, 2019 at 5:26 PM Jan Korous <<a href="mailto:jkorous@apple.com">jkorous@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;">Hi Nico,<div><br></div><div>I didn't think it necessary as the change doesn't introduce any interaction with filesystem - it's just copying a string.</div><div><br></div><div>Do you mean it causes a performance regression?</div><div><br></div><div>Thanks.</div><div><br></div><div>Jan<br><div><br><blockquote type="cite"><div>On Feb 15, 2019, at 6:15 AM, Nico Weber <<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>> wrote:</div><br class="gmail-m_-3085581552019888486Apple-interchange-newline"><div><div dir="ltr">Did you do any performance testing to check if this slows down clang?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Feb 14, 2019 at 6:02 PM Jan Korous via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: jkorous<br>
Date: Thu Feb 14 15:02:35 2019<br>
New Revision: 354075<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=354075&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=354075&view=rev</a><br>
Log:<br>
[clang][FileManager] fillRealPathName even if we aren't opening the file<br>
<br>
The pathname wasn't previously filled when the getFile() method was called with openFile = false.<br>
We are caching FileEntry-s in ParsedAST::Includes in clangd and this caused the problem.<br>
<br>
This fixes an internal test failure in clangd - ClangdTests.GoToInclude.All<br>
<br>
<a>rdar://47536127</a><br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D58213" rel="noreferrer" target="_blank">https://reviews.llvm.org/D58213</a><br>
<br>
Modified:<br>
    cfe/trunk/lib/Basic/FileManager.cpp<br>
    cfe/trunk/unittests/Basic/FileManagerTest.cpp<br>
<br>
Modified: cfe/trunk/lib/Basic/FileManager.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=354075&r1=354074&r2=354075&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=354075&r1=354074&r2=354075&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Basic/FileManager.cpp (original)<br>
+++ cfe/trunk/lib/Basic/FileManager.cpp Thu Feb 14 15:02:35 2019<br>
@@ -267,6 +267,9 @@ const FileEntry *FileManager::getFile(St<br>
   if (UFE.File) {<br>
     if (auto PathName = UFE.File->getName())<br>
       fillRealPathName(&UFE, *PathName);<br>
+  } else if (!openFile) {<br>
+    // We should still fill the path even if we aren't opening the file.<br>
+    fillRealPathName(&UFE, InterndFileName);<br>
   }<br>
   return &UFE;<br>
 }<br>
<br>
Modified: cfe/trunk/unittests/Basic/FileManagerTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/FileManagerTest.cpp?rev=354075&r1=354074&r2=354075&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/FileManagerTest.cpp?rev=354075&r1=354074&r2=354075&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/unittests/Basic/FileManagerTest.cpp (original)<br>
+++ cfe/trunk/unittests/Basic/FileManagerTest.cpp Thu Feb 14 15:02:35 2019<br>
@@ -346,4 +346,18 @@ TEST_F(FileManagerTest, getVirtualFileFi<br>
   EXPECT_EQ(file->tryGetRealPathName(), ExpectedResult);<br>
 }<br>
<br>
+TEST_F(FileManagerTest, getFileDontOpenRealPath) {<br>
+  auto statCache = llvm::make_unique<FakeStatCache>();<br>
+  statCache->InjectDirectory("/tmp/abc", 42);<br>
+  SmallString<64> Path("/tmp/abc/foo.cpp");<br>
+  statCache->InjectFile(Path.str().str().c_str(), 43);<br>
+  manager.setStatCache(std::move(statCache));<br>
+<br>
+  const FileEntry *file = manager.getFile(Path, /*openFile=*/false);<br>
+<br>
+  ASSERT_TRUE(file != nullptr);<br>
+<br>
+  ASSERT_EQ(file->tryGetRealPathName(), Path);<br>
+}<br>
+<br>
 } // anonymous namespace<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>
</div></blockquote></div><br></div></div></blockquote></div>