[cfe-commits] r95782 - in /cfe/trunk: lib/AST/ASTImporter.cpp lib/Frontend/ASTMerge.cpp test/ASTMerge/Inputs/var1.c test/ASTMerge/Inputs/var2.c test/ASTMerge/var.c
Douglas Gregor
dgregor at apple.com
Wed Feb 10 09:16:55 PST 2010
Author: dgregor
Date: Wed Feb 10 11:16:49 2010
New Revision: 95782
URL: http://llvm.org/viewvc/llvm-project?rev=95782&view=rev
Log:
Teach AST merging that variables with incomplete array types can be
merged with variables of constant array types. Also, make sure that we
call DiagnosticClient's BeginSourceFile/EndSourceFile, so that it has
a LangOptions to work with.
Modified:
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/Frontend/ASTMerge.cpp
cfe/trunk/test/ASTMerge/Inputs/var1.c
cfe/trunk/test/ASTMerge/Inputs/var2.c
cfe/trunk/test/ASTMerge/var.c
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=95782&r1=95781&r2=95782&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Feb 10 11:16:49 2010
@@ -500,6 +500,33 @@
break;
}
+ if (const IncompleteArrayType *FoundArray
+ = Importer.getToContext().getAsIncompleteArrayType(
+ FoundVar->getType())) {
+ if (const ConstantArrayType *TArray
+ = Importer.getToContext().getAsConstantArrayType(T)) {
+ if (Importer.getToContext().typesAreCompatible(
+ TArray->getElementType(),
+ FoundArray->getElementType())) {
+ FoundVar->setType(T);
+ MergeWithVar = FoundVar;
+ break;
+ }
+ }
+ } else if (const IncompleteArrayType *TArray
+ = Importer.getToContext().getAsIncompleteArrayType(T)) {
+ if (const ConstantArrayType *FoundArray
+ = Importer.getToContext().getAsConstantArrayType(
+ FoundVar->getType())) {
+ if (Importer.getToContext().typesAreCompatible(
+ TArray->getElementType(),
+ FoundArray->getElementType())) {
+ MergeWithVar = FoundVar;
+ break;
+ }
+ }
+ }
+
Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent)
<< Name << T << FoundVar->getType();
Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
Modified: cfe/trunk/lib/Frontend/ASTMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTMerge.cpp?rev=95782&r1=95781&r2=95782&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTMerge.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTMerge.cpp Wed Feb 10 11:16:49 2010
@@ -32,6 +32,8 @@
void ASTMergeAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
+ CI.getDiagnostics().getClient()->BeginSourceFile(
+ CI.getASTContext().getLangOptions());
CI.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
&CI.getASTContext());
for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) {
@@ -68,8 +70,8 @@
delete Unit;
}
-
- return AdaptedAction->ExecuteAction();
+ AdaptedAction->ExecuteAction();
+ CI.getDiagnostics().getClient()->EndSourceFile();
}
void ASTMergeAction::EndSourceFileAction() {
Modified: cfe/trunk/test/ASTMerge/Inputs/var1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/var1.c?rev=95782&r1=95781&r2=95782&view=diff
==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/var1.c (original)
+++ cfe/trunk/test/ASTMerge/Inputs/var1.c Wed Feb 10 11:16:49 2010
@@ -1,3 +1,7 @@
int *x0;
float **x1;
#include "var1.h"
+int xarray0[17];
+int xarray1[];
+int xarray2[18];
+int xarray3[18];
Modified: cfe/trunk/test/ASTMerge/Inputs/var2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/Inputs/var2.c?rev=95782&r1=95781&r2=95782&view=diff
==============================================================================
--- cfe/trunk/test/ASTMerge/Inputs/var2.c (original)
+++ cfe/trunk/test/ASTMerge/Inputs/var2.c Wed Feb 10 11:16:49 2010
@@ -1,3 +1,7 @@
int *x0;
double *x1;
int x2;
+int xarray0[17];
+int xarray1[17];
+int xarray2[];
+int xarray3[17];
Modified: cfe/trunk/test/ASTMerge/var.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/var.c?rev=95782&r1=95781&r2=95782&view=diff
==============================================================================
--- cfe/trunk/test/ASTMerge/var.c (original)
+++ cfe/trunk/test/ASTMerge/var.c Wed Feb 10 11:16:49 2010
@@ -7,3 +7,5 @@
// CHECK: var2.c:3:5: error: external variable 'x2' declared with incompatible types in different translation units ('int' vs. 'double')
// CHECK: In file included from{{.*}}var1.c:3:
// CHECK: var1.h:1:8: note: declared here with type 'double'
+// CHECK: error: external variable 'xarray3' declared with incompatible types in different translation units ('int [17]' vs. 'int [18]')
+// CHECK: var1.c:7:5: note: declared here with type 'int [18]'
More information about the cfe-commits
mailing list