From bd97f35339719480001ff96efb5785d9cfd29edf Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 25 Aug 2016 18:26:30 +0000 Subject: [PATCH] Refactor to remove the assumption that we know the name of the module we're emitting at the point when we create a PCHGenerator (with the C++ modules TS, we find that out part way through parsing the input). llvm-svn: 279766 --- clang/include/clang/Serialization/ASTWriter.h | 3 +-- clang/lib/Frontend/ASTUnit.cpp | 2 +- clang/lib/Frontend/ChainedIncludesSource.cpp | 2 +- clang/lib/Frontend/FrontendActions.cpp | 4 ++-- clang/lib/Serialization/GeneratePCH.cpp | 19 +++++++++++++------ 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index b07b36cc..f247855 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -909,7 +909,6 @@ public: class PCHGenerator : public SemaConsumer { const Preprocessor &PP; std::string OutputFile; - clang::Module *Module; std::string isysroot; Sema *SemaPtr; std::shared_ptr Buffer; @@ -925,7 +924,7 @@ protected: public: PCHGenerator( const Preprocessor &PP, StringRef OutputFile, - clang::Module *Module, StringRef isysroot, + StringRef isysroot, std::shared_ptr Buffer, ArrayRef> Extensions, bool AllowASTWithErrors = false, diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 3a34f85..f66ff14 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -925,7 +925,7 @@ public: PrecompilePreambleConsumer(ASTUnit &Unit, PrecompilePreambleAction *Action, const Preprocessor &PP, StringRef isysroot, std::unique_ptr Out) - : PCHGenerator(PP, "", nullptr, isysroot, std::make_shared(), + : PCHGenerator(PP, "", isysroot, std::make_shared(), ArrayRef>(), /*AllowASTWithErrors=*/true), Unit(Unit), Hash(Unit.getCurrentTopLevelHashValue()), Action(Action), diff --git a/clang/lib/Frontend/ChainedIncludesSource.cpp b/clang/lib/Frontend/ChainedIncludesSource.cpp index 7687b24..c5b77ee 100644 --- a/clang/lib/Frontend/ChainedIncludesSource.cpp +++ b/clang/lib/Frontend/ChainedIncludesSource.cpp @@ -161,7 +161,7 @@ IntrusiveRefCntPtr clang::createChainedIncludesSource( auto Buffer = std::make_shared(); ArrayRef> Extensions; auto consumer = llvm::make_unique( - Clang->getPreprocessor(), "-", nullptr, /*isysroot=*/"", Buffer, + Clang->getPreprocessor(), "-", /*isysroot=*/"", Buffer, Extensions, /*AllowASTWithErrors=*/true); Clang->getASTContext().setASTMutationListener( consumer->GetASTMutationListener()); diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 706ccea..d73d469 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -91,7 +91,7 @@ GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { auto Buffer = std::make_shared(); std::vector> Consumers; Consumers.push_back(llvm::make_unique( - CI.getPreprocessor(), OutputFile, nullptr, Sysroot, + CI.getPreprocessor(), OutputFile, Sysroot, Buffer, CI.getFrontendOpts().ModuleFileExtensions, /*AllowASTWithErrors*/false, /*IncludeTimestamps*/ @@ -141,7 +141,7 @@ GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI, std::vector> Consumers; Consumers.push_back(llvm::make_unique( - CI.getPreprocessor(), OutputFile, Module, Sysroot, + CI.getPreprocessor(), OutputFile, Sysroot, Buffer, CI.getFrontendOpts().ModuleFileExtensions, /*AllowASTWithErrors=*/false, /*IncludeTimestamps=*/ diff --git a/clang/lib/Serialization/GeneratePCH.cpp b/clang/lib/Serialization/GeneratePCH.cpp index 47dce37..b2d79a2 100644 --- a/clang/lib/Serialization/GeneratePCH.cpp +++ b/clang/lib/Serialization/GeneratePCH.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "clang/AST/ASTContext.h" +#include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Preprocessor.h" #include "clang/Sema/SemaConsumer.h" #include "clang/Serialization/ASTWriter.h" @@ -21,12 +22,11 @@ using namespace clang; PCHGenerator::PCHGenerator( - const Preprocessor &PP, StringRef OutputFile, - clang::Module *Module, StringRef isysroot, - std::shared_ptr Buffer, - ArrayRef> Extensions, - bool AllowASTWithErrors, bool IncludeTimestamps) - : PP(PP), OutputFile(OutputFile), Module(Module), isysroot(isysroot.str()), + const Preprocessor &PP, StringRef OutputFile, StringRef isysroot, + std::shared_ptr Buffer, + ArrayRef> Extensions, + bool AllowASTWithErrors, bool IncludeTimestamps) + : PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()), SemaPtr(nullptr), Buffer(Buffer), Stream(Buffer->Data), Writer(Stream, Extensions, IncludeTimestamps), AllowASTWithErrors(AllowASTWithErrors) { @@ -45,6 +45,13 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) { if (hasErrors && !AllowASTWithErrors) return; + Module *Module = nullptr; + if (PP.getLangOpts().CompilingModule) { + Module = PP.getHeaderSearchInfo().lookupModule( + PP.getLangOpts().CurrentModule, /*AllowSearch*/ false); + assert(Module && "emitting module but current module doesn't exist"); + } + // Emit the PCH file to the Buffer. assert(SemaPtr && "No Sema?"); Buffer->Signature = -- 2.7.4