aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp27
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;
}