]> granicus.if.org Git - clang/commitdiff
Don't read CompilerInstance fields that don't exist in ASTUnit
authorBen Langmuir <blangmuir@apple.com>
Fri, 18 Apr 2014 20:39:48 +0000 (20:39 +0000)
committerBen Langmuir <blangmuir@apple.com>
Fri, 18 Apr 2014 20:39:48 +0000 (20:39 +0000)
When transferring data from a CompilerInstance in an error path we need
to consider cases where the various fields are uninitialized.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206644 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/ASTUnit.cpp

index 5035dac53cfb78c0eb0dc9e64656de1cbe8a847d..240acc2f50c155038790523b7e5544345c11ce38 100644 (file)
@@ -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();
 }