forked from OSchip/llvm-project
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. llvm-svn: 95704
This commit is contained in:
parent
b618f66c5f
commit
6b2a474531
|
@ -10,6 +10,7 @@
|
||||||
#include "clang/Frontend/CompilerInstance.h"
|
#include "clang/Frontend/CompilerInstance.h"
|
||||||
#include "clang/Frontend/FrontendActions.h"
|
#include "clang/Frontend/FrontendActions.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
|
#include "clang/AST/ASTDiagnostic.h"
|
||||||
#include "clang/AST/ASTImporter.h"
|
#include "clang/AST/ASTImporter.h"
|
||||||
|
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
@ -31,15 +32,20 @@ bool ASTMergeAction::BeginSourceFileAction(CompilerInstance &CI,
|
||||||
|
|
||||||
void ASTMergeAction::ExecuteAction() {
|
void ASTMergeAction::ExecuteAction() {
|
||||||
CompilerInstance &CI = getCompilerInstance();
|
CompilerInstance &CI = getCompilerInstance();
|
||||||
|
CI.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
|
||||||
|
&CI.getASTContext());
|
||||||
for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) {
|
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);
|
false, true);
|
||||||
if (!Unit)
|
if (!Unit)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
ASTDiags.SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
|
||||||
|
&Unit->getASTContext());
|
||||||
ASTImporter Importer(CI.getASTContext(), CI.getDiagnostics(),
|
ASTImporter Importer(CI.getASTContext(), CI.getDiagnostics(),
|
||||||
Unit->getASTContext(), CI.getDiagnostics());
|
Unit->getASTContext(), ASTDiags);
|
||||||
|
|
||||||
TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
|
TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
|
||||||
for (DeclContext::decl_iterator D = TU->decls_begin(),
|
for (DeclContext::decl_iterator D = TU->decls_begin(),
|
||||||
|
@ -51,8 +57,7 @@ void ASTMergeAction::ExecuteAction() {
|
||||||
if (VD->getIdentifier() &&
|
if (VD->getIdentifier() &&
|
||||||
*VD->getIdentifier()->getNameStart() == 'x') {
|
*VD->getIdentifier()->getNameStart() == 'x') {
|
||||||
Decl *Merged = Importer.Import(VD);
|
Decl *Merged = Importer.Import(VD);
|
||||||
if (Merged)
|
(void)Merged;
|
||||||
Merged->dump();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/var2.c
|
// 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
|
// 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 **')
|
||||||
|
|
Loading…
Reference in New Issue