summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-01-24 23:49:55 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-01-24 23:49:55 +0000
commit8b7c52658bd5966c65a74d1404fa2fa96adc9edc (patch)
treef56f13ee5bafbeca0cfd1965e1e25a6bc59c42fb /clang
parent588395702f004f14cd67dad2a62366274391cb09 (diff)
downloadbcm5719-llvm-8b7c52658bd5966c65a74d1404fa2fa96adc9edc.tar.gz
bcm5719-llvm-8b7c52658bd5966c65a74d1404fa2fa96adc9edc.zip
Fix for PR2100: merge types for variables.
llvm-svn: 62947
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp8
-rw-r--r--clang/test/Sema/decl-type-merging.c16
2 files changed, 20 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0fb939e23ab..9f308842d9e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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/clang/test/Sema/decl-type-merging.c b/clang/test/Sema/decl-type-merging.c
new file mode 100644
index 00000000000..89bc4944750
--- /dev/null
+++ b/clang/test/Sema/decl-type-merging.c
@@ -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}}
+}
+
+
OpenPOWER on IntegriCloud