[PATCH] D57165: [FileManager] Revert r347205 to avoid PCH file-descriptor leak.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 24 09:46:09 PST 2019


sammccall created this revision.
sammccall added reviewers: bkramer, thakis.
Herald added subscribers: cfe-commits, kadircet, ioeric, ilya-biryukov.

r347205 fixed a bug in FileManager: first calling
getFile(shouldOpen=false) and then getFile(shouldOpen=true) results in
the file not being open.

Unfortunately, some code was (inadvertently?) relying on this bug: when
building with a PCH, the file entries are obtained first by passing
shouldOpen=false, and then later shouldOpen=true, without any intention
of reading them. After r347205, they do get unneccesarily opened.
Aside from extra operations, this means they need to be closed. Normally
files are closed when their contents are read. As these files are never
read, they stay open until clang exits. On platforms with a low
open-files limit (e.g. Mac), this can lead to spurious file-not-found
errors when building large projects with PCH enabled, e.g.

  https://bugs.chromium.org/p/chromium/issues/detail?id=924225

Fixing the callsites to pass shouldOpen=false when the file won't be
read is not quite trivial (that info isn't available at the direct
callsite), and passing shouldOpen=false is a performance regression (it
results in open+fstat pairs being replaced by stat+open).

So an ideal fix is going to be a little risky and we need some fix soon
(especially for the llvm 8 branch).
The problem addressed by r347205 is rare and has only been observed in
clangd. It was present in llvm-7, so we can live with it for now.


Repository:
  rC Clang

https://reviews.llvm.org/D57165

Files:
  include/clang/Basic/FileManager.h
  lib/Basic/FileManager.cpp
  test/PCH/leakfiles
  unittests/Basic/FileManagerTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57165.183332.patch
Type: text/x-patch
Size: 6716 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190124/d31f02a6/attachment-0001.bin>


More information about the cfe-commits mailing list