]> granicus.if.org Git - clang/commitdiff
Attempt to fix null ASTContext in ASTUnit error path
authorBen Langmuir <blangmuir@apple.com>
Tue, 22 Apr 2014 17:40:12 +0000 (17:40 +0000)
committerBen Langmuir <blangmuir@apple.com>
Tue, 22 Apr 2014 17:40:12 +0000 (17:40 +0000)
We don't need the ASTContext for the diagnostics, only the language
options, which we can get from the compiler invocation. It worries me
how many categorically different states the ASTUnit class can be in
depending on how it is being constructed/used.

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

include/clang/Frontend/ASTUnit.h
lib/Frontend/ASTUnit.cpp
tools/libclang/CIndex.cpp

index f8cb14e29d171fef8f763d37875342da3005feb1..ceabaa75e9b2e354b52775ed73a298c3f337284b 100644 (file)
@@ -501,6 +501,11 @@ public:
     assert(TheSema && "ASTUnit does not have a Sema object!");
     return *TheSema;
   }
+
+  const LangOptions &getLangOpts() const {
+    assert(LangOpts && " ASTUnit does not have language options");
+    return *LangOpts;
+  }
   
   const FileManager &getFileManager() const { return *FileMgr; }
         FileManager &getFileManager()       { return *FileMgr; }
index 240acc2f50c155038790523b7e5544345c11ce38..b35fcf196d7e00093357d80be0ffd1b39851a2db 100644 (file)
@@ -1714,7 +1714,10 @@ void ASTUnit::RealizeTopLevelDeclsFromPreamble() {
 }
 
 void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) {
-  // Steal the created target, context, and preprocessor.
+  // Steal the created target, context, and preprocessor if they have been
+  // created.
+  assert(CI.hasInvocation() && "missing invocation");
+  LangOpts = CI.getInvocation().getLangOpts();
   TheSema.reset(CI.takeSema());
   Consumer.reset(CI.takeASTConsumer());
   if (CI.hasASTContext())
index 1290c7206706b6bbe27eeb50542e1c8132bbf9ee..9d59fa7c7b5ba7edeeda7cf6ec9cb16ce8f1a386 100644 (file)
@@ -6720,7 +6720,7 @@ void cxindex::printDiagsToStderr(ASTUnit *Unit) {
   for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(), 
                                   DEnd = Unit->stored_diag_end();
        D != DEnd; ++D) {
-    CXStoredDiagnostic Diag(*D, Unit->getASTContext().getLangOpts());
+    CXStoredDiagnostic Diag(*D, Unit->getLangOpts());
     CXString Msg = clang_formatDiagnostic(&Diag,
                                 clang_defaultDiagnosticDisplayOptions());
     fprintf(stderr, "%s\n", clang_getCString(Msg));