From 4eca9b93720b8f5746159eed43a0b3c0bf496db0 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 4 Feb 2015 23:37:59 +0000 Subject: [modules] When using -E, we may try to merge decls despite having no Sema object. In such a case, use the TU's DC for merging global decls rather than giving up when we find there is no TU scope. Ultimately, we should probably avoid all loading of decls when preprocessing, but there are other reasonable use cases for loading an AST file with no Sema object for which this is the right thing. llvm-svn: 228234 --- clang/lib/Frontend/CompilerInstance.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'clang/lib/Frontend/CompilerInstance.cpp') diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 041a1e95225..9cb26f86c79 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -388,32 +388,30 @@ void CompilerInstance::createASTContext() { void CompilerInstance::createPCHExternalASTSource( StringRef Path, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors, void *DeserializationListener, bool OwnDeserializationListener) { - IntrusiveRefCntPtr Source; bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0; - Source = createPCHExternalASTSource( + ModuleManager = createPCHExternalASTSource( Path, getHeaderSearchOpts().Sysroot, DisablePCHValidation, AllowPCHWithCompilerErrors, getPreprocessor(), getASTContext(), DeserializationListener, OwnDeserializationListener, Preamble, getFrontendOpts().UseGlobalModuleIndex); - ModuleManager = static_cast(Source.get()); - getASTContext().setExternalSource(Source); } -ExternalASTSource *CompilerInstance::createPCHExternalASTSource( +IntrusiveRefCntPtr CompilerInstance::createPCHExternalASTSource( StringRef Path, const std::string &Sysroot, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context, void *DeserializationListener, bool OwnDeserializationListener, bool Preamble, bool UseGlobalModuleIndex) { HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts(); - std::unique_ptr Reader; - Reader.reset(new ASTReader(PP, Context, - Sysroot.empty() ? "" : Sysroot.c_str(), - DisablePCHValidation, - AllowPCHWithCompilerErrors, - /*AllowConfigurationMismatch*/false, - HSOpts.ModulesValidateSystemHeaders, - UseGlobalModuleIndex)); + IntrusiveRefCntPtr Reader( + new ASTReader(PP, Context, Sysroot.empty() ? "" : Sysroot.c_str(), + DisablePCHValidation, AllowPCHWithCompilerErrors, + /*AllowConfigurationMismatch*/ false, + HSOpts.ModulesValidateSystemHeaders, UseGlobalModuleIndex)); + + // We need the external source to be set up before we read the AST, because + // eagerly-deserialized declarations may use it. + Context.setExternalSource(Reader.get()); Reader->setDeserializationListener( static_cast(DeserializationListener), @@ -427,7 +425,7 @@ ExternalASTSource *CompilerInstance::createPCHExternalASTSource( // Set the predefines buffer as suggested by the PCH reader. Typically, the // predefines buffer will be empty. PP.setPredefines(Reader->getSuggestedPredefines()); - return Reader.release(); + return Reader; case ASTReader::Failure: // Unrecoverable failure: don't even try to process the input file. @@ -442,6 +440,7 @@ ExternalASTSource *CompilerInstance::createPCHExternalASTSource( break; } + Context.setExternalSource(nullptr); return nullptr; } -- cgit v1.2.3