From 532fdc0d4f51bd753a33102f3c6074e0c35846da Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Fri, 18 Apr 2014 20:39:48 +0000 Subject: [PATCH] Don't read CompilerInstance fields that don't exist in ASTUnit When transferring data from a CompilerInstance in an error path we need to consider cases where the various fields are uninitialized. llvm-svn: 206644 --- clang/lib/Frontend/ASTUnit.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 5035dac53cfb..240acc2f50c1 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1717,11 +1717,14 @@ void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) { // Steal the created target, context, and preprocessor. TheSema.reset(CI.takeSema()); Consumer.reset(CI.takeASTConsumer()); - Ctx = &CI.getASTContext(); - PP = &CI.getPreprocessor(); + if (CI.hasASTContext()) + Ctx = &CI.getASTContext(); + if (CI.hasPreprocessor()) + PP = &CI.getPreprocessor(); CI.setSourceManager(0); CI.setFileManager(0); - Target = &CI.getTarget(); + if (CI.hasTarget()) + Target = &CI.getTarget(); Reader = CI.getModuleManager(); HadModuleLoaderFatalFailure = CI.hadModuleLoaderFatalFailure(); }