]> granicus.if.org Git - clang/commitdiff
Fix for PR2100: merge types for variables.
authorEli Friedman <eli.friedman@gmail.com>
Sat, 24 Jan 2009 23:49:55 +0000 (23:49 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 24 Jan 2009 23:49:55 +0000 (23:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62947 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/decl-type-merging.c [new file with mode: 0644]

index 0fb939e23abc2130e71aa8d941c7f77223573f50..9f308842d9ec1e8ef1fd76f1cabe07bffa0c0efe 100644 (file)
@@ -658,15 +658,15 @@ VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
 
   MergeAttributes(New, Old);
 
-  // Verify the types match.
-  QualType OldCType = Context.getCanonicalType(Old->getType());
-  QualType NewCType = Context.getCanonicalType(New->getType());
-  if (OldCType != NewCType && !Context.typesAreCompatible(OldCType, NewCType)) {
+  // Merge the types
+  QualType MergedT = Context.mergeTypes(New->getType(), Old->getType());
+  if (MergedT.isNull()) {
     Diag(New->getLocation(), diag::err_redefinition_different_type) 
       << New->getDeclName();
     Diag(Old->getLocation(), diag::note_previous_definition);
     return New;
   }
+  New->setType(MergedT);
   // C99 6.2.2p4: Check if we have a static decl followed by a non-static.
   if (New->getStorageClass() == VarDecl::Static &&
       (Old->getStorageClass() == VarDecl::None ||
diff --git a/test/Sema/decl-type-merging.c b/test/Sema/decl-type-merging.c
new file mode 100644 (file)
index 0000000..89bc494
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: clang -fsyntax-only -std=c99 -verify -pedantic %s
+
+int x[10];
+int x[] = {1,2,3};
+int testx[(sizeof(x) == sizeof(int) * 10) ? 1 : -1];
+
+int (*a)(int (*x)[10], int (*y)[]);
+int (*a)(int (*x)[], int (*y)[5]);
+int b() {
+int x[10], y[5];
+a(&x, &y);
+a(&y, &y); // expected-warning {{incompatible pointer}}
+a(&x, &x); // expected-warning {{incompatible pointer}}
+}
+
+