Hook up the diagnostics-argument printer when merging AST files, so
that we get readable diagnostics such as:

error: external variable 'x1' declared with incompatible types in
different translation units ('double *' vs. 'float **')

However, there is no translation of source locations, yet.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95704 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/ASTMerge.cpp b/lib/Frontend/ASTMerge.cpp
index 649af9e..e88d295 100644
--- a/lib/Frontend/ASTMerge.cpp
+++ b/lib/Frontend/ASTMerge.cpp
@@ -10,6 +10,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTDiagnostic.h"
 #include "clang/AST/ASTImporter.h"
 
 using namespace clang;
@@ -31,15 +32,20 @@
 
 void ASTMergeAction::ExecuteAction() {
   CompilerInstance &CI = getCompilerInstance();
-
+  CI.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
+                                       &CI.getASTContext());
   for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) {
-    ASTUnit *Unit = ASTUnit::LoadFromPCHFile(ASTFiles[I], CI.getDiagnostics(),
+    Diagnostic ASTDiags(CI.getDiagnostics().getClient());
+    
+    ASTUnit *Unit = ASTUnit::LoadFromPCHFile(ASTFiles[I], ASTDiags,
                                              false, true);
     if (!Unit)
       continue;
 
+    ASTDiags.SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
+                              &Unit->getASTContext());
     ASTImporter Importer(CI.getASTContext(), CI.getDiagnostics(),
-                         Unit->getASTContext(), CI.getDiagnostics());
+                         Unit->getASTContext(), ASTDiags);
 
     TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
     for (DeclContext::decl_iterator D = TU->decls_begin(), 
@@ -51,8 +57,7 @@
         if (VD->getIdentifier() && 
             *VD->getIdentifier()->getNameStart() == 'x') {
           Decl *Merged = Importer.Import(VD);
-          if (Merged)
-            Merged->dump();
+          (void)Merged;
         }
     }