-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
------------------------------------------------------------------------ r352079 | sammccall | 2019-01-24 19:55:24 +0100 (Thu, 24 Jan 2019) | 33 lines [FileManager] Revert r347205 to avoid PCH file-descriptor leak. Summary: 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. Reviewers: bkramer, thakis Subscribers: ilya-biryukov, ioeric, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D57165 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_80@352225 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
4 changed files
with
42 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Test that compiling using a PCH doesn't leak file descriptors. | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=924225 | ||
// | ||
// This test requires bash loops and ulimit. | ||
// REQUIRES: shell | ||
// UNSUPPORTED: win32 | ||
// | ||
// Set up source files. lib/lib.h includes lots of lib*.h files in that dir. | ||
// client.c includes lib/lib.h, and also the individual files directly. | ||
// | ||
// RUN: rm -rf %t | ||
// RUN: mkdir %t | ||
// RUN: cd %t | ||
// RUN: mkdir lib | ||
// RUN: for i in {1..300}; do touch lib/lib$i.h; done | ||
// RUN: for i in {1..300}; do echo "#include \"lib$i.h\"" >> lib/lib.h; done | ||
// RUN: echo "#include \"lib/lib.h\"" > client.c | ||
// RUN: for i in {1..300}; do echo "#include \"lib/lib$i.h\"" >> client.c; done | ||
// | ||
// We want to verify that we don't hold all the files open at the same time. | ||
// This is important e.g. on mac, which has a low default FD limit. | ||
// RUN: ulimit -n 100 | ||
// | ||
// Test without PCH. | ||
// RUN: %clang_cc1 -fsyntax-only -Ilib/ client.c | ||
// | ||
// Test with PCH. | ||
// RUN: %clang_cc1 -emit-pch -o pch -Ilib/ client.c | ||
// RUN: %clang_cc1 -include-pch pch -Ilib/ client.c -fsyntax-only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters