llvm-project/clang/unittests
Duncan P. N. Exon Smith 030d7d6daa Reapply "Modules: Cache PCMs in memory and avoid a use-after-free"
This reverts commit r298185, effectively reapplying r298165, after fixing the
new unit tests (PR32338).  The memory buffer generator doesn't null-terminate
the MemoryBuffer it creates; this version of the commit informs getMemBuffer
about that to avoid the assert.

Original commit message follows:

----

Clang's internal build system for implicit modules uses lock files to
ensure that after a process writes a PCM it will read the same one back
in (without contention from other -cc1 commands).  Since PCMs are read
from disk repeatedly while invalidating, building, and importing, the
lock is not released quickly.  Furthermore, the LockFileManager is not
robust in every environment.  Other -cc1 commands can stall until
timeout (after about eight minutes).

This commit changes the lock file from being necessary for correctness
to a (possibly dubious) performance hack.  The remaining benefit is to
reduce duplicate work in competing -cc1 commands which depend on the
same module.  Follow-up commits will change the internal build system to
continue after a timeout, and reduce the timeout.  Perhaps we should
reconsider blocking at all.

This also fixes a use-after-free, when one part of a compilation
validates a PCM and starts using it, and another tries to swap out the
PCM for something new.

The PCMCache is a new type called MemoryBufferCache, which saves memory
buffers based on their filename.  Its ownership is shared by the
CompilerInstance and ModuleManager.

- The ModuleManager stores PCMs there that it loads from disk, never
touching the disk if the cache is hot.

- When modules fail to validate, they're removed from the cache.

- When a CompilerInstance is spawned to build a new module, each
already-loaded PCM is assumed to be valid, and is frozen to avoid
the use-after-free.

- Any newly-built module is written directly to the cache to avoid the
round-trip to the filesystem, making lock files unnecessary for
correctness.

Original patch by Manman Ren; most testcases by Adrian Prantl!

llvm-svn: 298278
2017-03-20 17:58:26 +00:00
..
AST Tracking exception specification source locations 2017-01-12 16:11:28 +00:00
ASTMatchers Add AST matchers for ObjCProtocolDecl, ObjCCategoryDecl, ObjCMethodDecl, ObjCIvarDecl, and ObjCPropertyDecl. 2017-03-15 20:14:25 +00:00
Analysis [analyzer] Fix crash when building CFG with variable of incomplete type 2017-03-07 08:42:37 +00:00
Basic Reapply "Modules: Cache PCMs in memory and avoid a use-after-free" 2017-03-20 17:58:26 +00:00
CodeGen Make sure the LLVMContext outlive the CompilerInstance 2016-04-14 05:37:41 +00:00
Driver Fix shared library build after r291938 by adding missing dependency on libOption 2017-01-13 19:47:55 +00:00
Format [clang-format] disable adding extra space after MSVC '__super' keyword 2017-03-16 10:21:35 +00:00
Frontend Reapply "IntrusiveRefCntPtr -> std::shared_ptr for CompilerInvocationBase and CodeCompleteConsumer" 2017-01-06 19:49:01 +00:00
Lex Reapply "Modules: Cache PCMs in memory and avoid a use-after-free" 2017-03-20 17:58:26 +00:00
Rewrite Remove autoconf support 2016-01-26 21:30:40 +00:00
Sema [Sema] Allow an external sema source to handle delayed typo corrections. 2016-05-19 10:46:10 +00:00
StaticAnalyzer Add a method to get the list of registered static analyzer checkers. 2016-11-08 07:23:32 +00:00
Tooling Add missing implementation for AtomicChange::replace(...) 2017-03-08 15:53:10 +00:00
libclang Fixed more signed/unsigned mismatch warnings introduced in my change at r279076 2016-08-18 20:56:48 +00:00
CMakeLists.txt CFGBuilder: Fix crash when visiting a range-based for over a dependent type 2016-07-08 10:50:51 +00:00