diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-02-04 23:37:59 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-02-04 23:37:59 +0000 |
commit | 4eca9b93720b8f5746159eed43a0b3c0bf496db0 (patch) | |
tree | 6bef588cf2e4f659f1dc6daf772ec5b19b14e43e /clang/lib/Frontend/CompilerInstance.cpp | |
parent | 712d5c393b7d5d336e60b528788e3f2e46bb8777 (diff) | |
download | llvm-4eca9b93720b8f5746159eed43a0b3c0bf496db0.zip llvm-4eca9b93720b8f5746159eed43a0b3c0bf496db0.tar.gz llvm-4eca9b93720b8f5746159eed43a0b3c0bf496db0.tar.bz2 |
[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
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 041a1e9..9cb26f8 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<ExternalASTSource> 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<ASTReader*>(Source.get()); - getASTContext().setExternalSource(Source); } -ExternalASTSource *CompilerInstance::createPCHExternalASTSource( +IntrusiveRefCntPtr<ASTReader> 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<ASTReader> Reader; - Reader.reset(new ASTReader(PP, Context, - Sysroot.empty() ? "" : Sysroot.c_str(), - DisablePCHValidation, - AllowPCHWithCompilerErrors, - /*AllowConfigurationMismatch*/false, - HSOpts.ModulesValidateSystemHeaders, - UseGlobalModuleIndex)); + IntrusiveRefCntPtr<ASTReader> 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<ASTDeserializationListener *>(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; } |