[cfe-commits] r95704 - in /cfe/trunk: lib/Frontend/ASTMerge.cpp test/ASTMerge/var.c

Douglas Gregor dgregor at apple.com
Tue Feb 9 14:37:58 PST 2010


Author: dgregor
Date: Tue Feb  9 16:37:58 2010
New Revision: 95704

URL: http://llvm.org/viewvc/llvm-project?rev=95704&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Frontend/ASTMerge.cpp
    cfe/trunk/test/ASTMerge/var.c

Modified: cfe/trunk/lib/Frontend/ASTMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTMerge.cpp?rev=95704&r1=95703&r2=95704&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/ASTMerge.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTMerge.cpp Tue Feb  9 16:37:58 2010
@@ -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;
         }
     }
 

Modified: cfe/trunk/test/ASTMerge/var.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/var.c?rev=95704&r1=95703&r2=95704&view=diff

==============================================================================
--- cfe/trunk/test/ASTMerge/var.c (original)
+++ cfe/trunk/test/ASTMerge/var.c Tue Feb  9 16:37:58 2010
@@ -2,4 +2,4 @@
 // RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/var2.c
 // RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s
 
-// CHECK: declared with incompatible types
+// CHECK: error: external variable 'x1' declared with incompatible types in different translation units ('double *' vs. 'float **')





More information about the cfe-commits mailing list