]> granicus.if.org Git - clang/commitdiff
Teach AST merging that variables with incomplete array types can be
authorDouglas Gregor <dgregor@apple.com>
Wed, 10 Feb 2010 17:16:49 +0000 (17:16 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 10 Feb 2010 17:16:49 +0000 (17:16 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95782 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTImporter.cpp
lib/Frontend/ASTMerge.cpp
test/ASTMerge/Inputs/var1.c
test/ASTMerge/Inputs/var2.c
test/ASTMerge/var.c

index 75917cf04c8a431b16280ca343494a06a25ee8b3..9fb695e4e10dc7ea2540096e8e4d585f57923833 100644 (file)
@@ -500,6 +500,33 @@ Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) {
             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)
index d51647bb161d03ddf109028f2c3a70ee2d59df9b..f2de09a74ccb1a5c8f765b0ae7abd2435c232b27 100644 (file)
@@ -32,6 +32,8 @@ bool ASTMergeAction::BeginSourceFileAction(CompilerInstance &CI,
 
 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 @@ void ASTMergeAction::ExecuteAction() {
     delete Unit;
   }
 
-
-  return AdaptedAction->ExecuteAction();
+  AdaptedAction->ExecuteAction();
+  CI.getDiagnostics().getClient()->EndSourceFile();
 }
 
 void ASTMergeAction::EndSourceFileAction() {
index 465258988b015f8d428bdfb76c538c07bf31d5d5..4f5cbe16ab6cc2631580983e9f6a7b2dac6ab9ac 100644 (file)
@@ -1,3 +1,7 @@
 int *x0;
 float **x1;
 #include "var1.h"
+int xarray0[17];
+int xarray1[];
+int xarray2[18];
+int xarray3[18];
index e93a010cbfea2383506dbfe594115fbd46186fff..01986e4208caab3539e9f5921e0f08fe3c4aa6a0 100644 (file)
@@ -1,3 +1,7 @@
 int *x0;
 double *x1;
 int x2;
+int xarray0[17];
+int xarray1[17];
+int xarray2[];
+int xarray3[17];
index 98ad7ab4a0794e6b647c76558158cdb296647419..06bebd5ee89eba7fd4bbcef9456e4a3a9419c703 100644 (file)
@@ -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]'