llvm-project/clang/test/PCH/leakfiles.test

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
1.1 KiB
Plaintext
Raw Normal View History

[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 llvm-svn: 352079
2019-01-25 02:55:24 +08:00
// 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