llvm-project/clang/lib/Serialization
Ben Barham 766a08df12 [Frontend] Only compile modules if not already finalized
It was possible to re-add a module to a shared in-memory module cache
when search paths are changed. This can eventually cause a crash if the
original module is referenced after this occurs.
  1. Module A depends on B
  2. B exists in two paths C and D
  3. First run only has C on the search path, finds A and B and loads
     them
  4. Second run adds D to the front of the search path. A is loaded and
     contains a reference to the already compiled module from C. But
     searching finds the module from D instead, causing a mismatch
  5. B and the modules that depend on it are considered out of date and
     thus rebuilt
  6. The recompiled module A is added to the in-memory cache, freeing
     the previously inserted one

This can never occur from a regular clang process, but is very easy to
do through the API - whether through the use of a shared case or just
running multiple compilations from a single `CompilerInstance`. Update
the compilation to return early if a module is already finalized so that
the pre-condition in the in-memory module cache holds.

Resolves rdar://78180255

Differential Revision: https://reviews.llvm.org/D105328
2021-07-15 18:27:08 -07:00
..
ASTCommon.cpp [clang] p1099 using enum part 2 2021-06-08 11:11:46 -07:00
ASTCommon.h
ASTReader.cpp [Frontend] Only compile modules if not already finalized 2021-07-15 18:27:08 -07:00
ASTReaderDecl.cpp Support for merging UsingPackDecls across modules. 2021-07-01 18:43:49 -07:00
ASTReaderInternals.h
ASTReaderStmt.cpp Move variable only used inside an assert into the assert. 2021-06-10 13:14:45 -07:00
ASTWriter.cpp [clang][AST] Make `getLocalOrImportedSubmoduleID` work with const `Module*`. NFC. 2021-06-17 17:29:12 -07:00
ASTWriterDecl.cpp [clang] p1099 using enum part 2 2021-06-08 11:11:46 -07:00
ASTWriterStmt.cpp [OpenMP] Implement '#pragma omp unroll'. 2021-06-10 14:30:17 -05:00
CMakeLists.txt [openmp] Base of tablegen generated OpenMP common declaration 2020-06-23 10:32:32 -04:00
GeneratePCH.cpp [pch] Honour -fallow-pch-with-compiler-errors for overall compilation status 2020-03-31 13:50:12 -07:00
GlobalModuleIndex.cpp [clang][NFC] Use SmallString instead of SmallVector<char 2020-11-17 13:02:58 +00:00
InMemoryModuleCache.cpp Revert "[modules] Do not cache invalid state for modules that we attempted to load." 2020-03-10 10:59:26 -07:00
ModuleFile.cpp clang/Modules: Move Serialization/Module.{h,cpp} to ModuleFile, NFC 2019-11-21 19:07:00 -08:00
ModuleFileExtension.cpp [clang][modules] Use extensible RTTI for ModuleFileExtension 2021-03-05 11:11:05 +01:00
ModuleManager.cpp Change Module::ASTFile and ModuleFile::File => Optional<FileEntryRef>, NFC 2020-11-02 15:11:51 -05:00
MultiOnDiskHashTable.h
PCHContainerOperations.cpp [Clang] Migrate llvm::make_unique to std::make_unique 2019-08-14 23:04:18 +00:00