CIndex: For the time being, don't return translation units if we encounter an error during parsing.
 - We need to be more careful in the rest of CIndex if we are to handle
   possibly-invalid ASTs, and don't have much experience with this yet.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90643 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index 12c3935..9259818 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -508,10 +508,20 @@
                 command_line_args + num_command_line_args);
 
     void *MainAddr = (void *)(uintptr_t)clang_createTranslationUnit;
-    return ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(),
-                                        CXXIdx->getDiags(), "<clang>", MainAddr,
-                                        CXXIdx->getOnlyLocalDecls(),
-                                        /* UseBumpAllocator = */ true);
+
+    unsigned NumErrors = CXXIdx->getDiags().getNumErrors();
+    llvm::OwningPtr<ASTUnit> Unit(
+      ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(),
+                                   CXXIdx->getDiags(), "<clang>", MainAddr,
+                                   CXXIdx->getOnlyLocalDecls(),
+                                   /* UseBumpAllocator = */ true));
+
+    // FIXME: Until we have broader testing, just drop the entire AST if we
+    // encountered an error.
+    if (NumErrors != CXXIdx->getDiags().getNumErrors())
+      return 0;
+
+    return Unit.take();
   }
 
   // Build up the arguments for invoking 'clang'.