diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2019-03-12 18:38:04 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2019-03-12 18:38:04 +0000 |
commit | 2d59837707f71a996e38d3e1a2b0c178f9965f7e (patch) | |
tree | 89630644c525137aa8e2f16a51e90c600aa3632b /lib | |
parent | e77c4ca4a3d47530ca65446400002fe525f6fbe5 (diff) | |
download | clang-2d59837707f71a996e38d3e1a2b0c178f9965f7e.tar.gz |
Modules: Add LangOptions::CacheGeneratedPCH
Add an option to cache the generated PCH in the ModuleCache when
emitting it. This protects clients that build PCHs and read them in the
same process, allowing them to avoid race conditions between parallel
jobs the same way that Clang's implicit module build system does.
rdar://problem/48740787
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355950 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Frontend/FrontendActions.cpp | 4 | ||||
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 5 | ||||
-rw-r--r-- | lib/Serialization/GeneratePCH.cpp | 9 |
3 files changed, 12 insertions, 6 deletions
diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index 5ad9a1cc03..9cb2ab2d5e 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -112,7 +112,7 @@ GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer, FrontendOpts.ModuleFileExtensions, CI.getPreprocessorOpts().AllowPCHWithCompilerErrors, - FrontendOpts.IncludeTimestamps)); + FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH)); Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator( CI, InFile, OutputFile, std::move(OS), Buffer)); @@ -176,6 +176,8 @@ GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI, CI.getFrontendOpts().ModuleFileExtensions, /*AllowASTWithErrors=*/false, /*IncludeTimestamps=*/ + +CI.getFrontendOpts().BuildingImplicitModule, + /*ShouldCacheASTInMemory=*/ +CI.getFrontendOpts().BuildingImplicitModule)); Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator( CI, InFile, OutputFile, std::move(OS), Buffer)); diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 85bc281839..933cc6b12c 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -4596,7 +4596,8 @@ time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, const std::string &OutputFile, Module *WritingModule, StringRef isysroot, - bool hasErrors) { + bool hasErrors, + bool ShouldCacheASTInMemory) { WritingAST = true; ASTHasCompilerErrors = hasErrors; @@ -4620,7 +4621,7 @@ ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, this->BaseDirectory.clear(); WritingAST = false; - if (SemaRef.Context.getLangOpts().ImplicitModules && WritingModule) { + if (ShouldCacheASTInMemory) { // Construct MemoryBuffer and update buffer manager. ModuleCache.addBuiltPCM(OutputFile, llvm::MemoryBuffer::getMemBufferCopy( diff --git a/lib/Serialization/GeneratePCH.cpp b/lib/Serialization/GeneratePCH.cpp index 7c2ef5a13a..6d98524636 100644 --- a/lib/Serialization/GeneratePCH.cpp +++ b/lib/Serialization/GeneratePCH.cpp @@ -24,12 +24,14 @@ PCHGenerator::PCHGenerator( const Preprocessor &PP, InMemoryModuleCache &ModuleCache, StringRef OutputFile, StringRef isysroot, std::shared_ptr<PCHBuffer> Buffer, ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, - bool AllowASTWithErrors, bool IncludeTimestamps) + bool AllowASTWithErrors, bool IncludeTimestamps, + bool ShouldCacheASTInMemory) : PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()), SemaPtr(nullptr), Buffer(std::move(Buffer)), Stream(this->Buffer->Data), Writer(Stream, this->Buffer->Data, ModuleCache, Extensions, IncludeTimestamps), - AllowASTWithErrors(AllowASTWithErrors) { + AllowASTWithErrors(AllowASTWithErrors), + ShouldCacheASTInMemory(ShouldCacheASTInMemory) { this->Buffer->IsComplete = false; } @@ -61,7 +63,8 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) { Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot, // For serialization we are lenient if the errors were // only warn-as-error kind. - PP.getDiagnostics().hasUncompilableErrorOccurred()); + PP.getDiagnostics().hasUncompilableErrorOccurred(), + ShouldCacheASTInMemory); Buffer->IsComplete = true; } |