diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 7 | ||||
-rw-r--r-- | clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Frontend/ASTMerge.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 23 | ||||
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 4 |
5 files changed, 18 insertions, 22 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 5f199bd3a4c..062c7be47b7 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -82,11 +82,8 @@ namespace clang { } void Initialize(ASTContext &Ctx) override { - if (Context) { - assert(Context == &Ctx); - return; - } - + assert(!Context && "initialized multiple times"); + Context = &Ctx; if (llvm::TimePassesIsEnabled) diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp index 526c0c71de5..3611d9aa86f 100644 --- a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp +++ b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp @@ -71,10 +71,7 @@ public: virtual ~PCHContainerGenerator() {} void Initialize(ASTContext &Context) override { - if (Ctx) { - assert(Ctx == &Context); - return; - } + assert(!Ctx && "initialized multiple times"); Ctx = &Context; VMContext.reset(new llvm::LLVMContext()); diff --git a/clang/lib/Frontend/ASTMerge.cpp b/clang/lib/Frontend/ASTMerge.cpp index 762c7a5da5e..b499fa2b0e6 100644 --- a/clang/lib/Frontend/ASTMerge.cpp +++ b/clang/lib/Frontend/ASTMerge.cpp @@ -59,7 +59,6 @@ void ASTMergeAction::ExecuteAction() { /*MinimalImport=*/false); TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl(); - CI.getASTConsumer().Initialize(CI.getASTContext()); for (auto *D : TU->decls()) { // Don't re-import __va_list_tag, __builtin_va_list. if (const auto *ND = dyn_cast<NamedDecl>(D)) diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 5079353226c..dfd71afca48 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -96,7 +96,12 @@ void CompilerInstance::setSourceManager(SourceManager *Value) { void CompilerInstance::setPreprocessor(Preprocessor *Value) { PP = Value; } -void CompilerInstance::setASTContext(ASTContext *Value) { Context = Value; } +void CompilerInstance::setASTContext(ASTContext *Value) { + Context = Value; + + if (Context && Consumer) + getASTConsumer().Initialize(getASTContext()); +} void CompilerInstance::setSema(Sema *S) { TheSema.reset(S); @@ -104,6 +109,9 @@ void CompilerInstance::setSema(Sema *S) { void CompilerInstance::setASTConsumer(std::unique_ptr<ASTConsumer> Value) { Consumer = std::move(Value); + + if (Context && Consumer) + getASTConsumer().Initialize(getASTContext()); } void CompilerInstance::setCodeCompletionConsumer(CodeCompleteConsumer *Value) { @@ -385,10 +393,11 @@ std::string CompilerInstance::getSpecificModuleCachePath() { void CompilerInstance::createASTContext() { Preprocessor &PP = getPreprocessor(); - Context = new ASTContext(getLangOpts(), PP.getSourceManager(), - PP.getIdentifierTable(), PP.getSelectorTable(), - PP.getBuiltinInfo()); + auto *Context = new ASTContext(getLangOpts(), PP.getSourceManager(), + PP.getIdentifierTable(), PP.getSelectorTable(), + PP.getBuiltinInfo()); Context->InitBuiltinTypes(getTarget()); + setASTContext(Context); } // ExternalASTSource @@ -1249,7 +1258,7 @@ void CompilerInstance::createModuleManager() { ReadTimer = llvm::make_unique<llvm::Timer>("Reading modules", *FrontendTimerGroup); ModuleManager = new ASTReader( - getPreprocessor(), *Context, getPCHContainerReader(), + getPreprocessor(), getASTContext(), getPCHContainerReader(), Sysroot.empty() ? "" : Sysroot.c_str(), PPOpts.DisablePCHValidation, /*AllowASTWithCompilerErrors=*/false, /*AllowConfigurationMismatch=*/false, @@ -1265,10 +1274,8 @@ void CompilerInstance::createModuleManager() { getASTContext().setExternalSource(ModuleManager); if (hasSema()) ModuleManager->InitializeSema(getSema()); - if (hasASTConsumer()) { - getASTConsumer().Initialize(getASTContext()); + if (hasASTConsumer()) ModuleManager->StartTranslationUnit(&getASTConsumer()); - } if (TheDependencyFileGenerator) TheDependencyFileGenerator->AttachToASTReader(*ModuleManager); diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index b8c290672e1..728032b8562 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -138,10 +138,6 @@ void Sema::addImplicitTypedef(StringRef Name, QualType T) { } void Sema::Initialize() { - // Tell the AST consumer about this Sema object. - Consumer.Initialize(Context); - - // FIXME: Isn't this redundant with the initialization above? if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer)) SC->InitializeSema(*this); |