Fix ASTUnit to allows require a (persistent) Diagnostic object be provided; propogate and simplify.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90379 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/index-test/index-test.cpp b/tools/index-test/index-test.cpp
index fc8547b..d13b2d4 100644
--- a/tools/index-test/index-test.cpp
+++ b/tools/index-test/index-test.cpp
@@ -238,7 +238,6 @@
   Indexer Idxer(Prog);
   llvm::SmallVector<TUnit*, 4> TUnits;
 
-  TextDiagnosticPrinter DiagClient(llvm::errs(), DiagnosticOptions(), false);
   llvm::OwningPtr<Diagnostic> Diags(
     CompilerInstance::createDiagnostics(DiagnosticOptions(), argc, argv));
 
@@ -248,21 +247,13 @@
 
   for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
     const std::string &InFile = InputFilenames[i];
-
-    std::string ErrMsg;
     llvm::OwningPtr<ASTUnit> AST;
-
-    if (ASTFromSource) {
+    if (ASTFromSource)
       AST.reset(CreateFromSource(InFile, *Diags, argv[0]));
-      if (!AST || Diags->getNumErrors())
-        ErrMsg = "unable to create AST";
-    } else
-      AST.reset(ASTUnit::LoadFromPCHFile(InFile, &ErrMsg));
-
-    if (!AST) {
-      llvm::errs() << "[" << InFile << "] Error: " << ErrMsg << '\n';
+    else
+      AST.reset(ASTUnit::LoadFromPCHFile(InFile, *Diags));
+    if (!AST)
       return 1;
-    }
 
     TUnit *TU = new TUnit(AST.take(), InFile);
     TUnits.push_back(TU);