aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2008-02-06 04:53:22 +0000
committerEli Friedman <eli.friedman@gmail.com>2008-02-06 04:53:22 +0000
commit4e92acf3b747b994e50fbf7bfe8ef71cdda20c50 (patch)
tree1d3025c4d4729fed65362bf128cbb68f584d9aea
parent9eee0f8593fcd2426b043fb0164f87ff36bd213f (diff)
Be a bit stricter about array type compatibility.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46799 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--AST/ASTContext.cpp16
-rw-r--r--test/Sema/compare.c7
2 files changed, 16 insertions, 7 deletions
diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp
index 823a20bb03..535f69271f 100644
--- a/AST/ASTContext.cpp
+++ b/AST/ASTContext.cpp
@@ -1627,14 +1627,18 @@ bool ASTContext::functionTypesAreCompatible(QualType lhs, QualType rhs) {
}
bool ASTContext::arrayTypesAreCompatible(QualType lhs, QualType rhs) {
- QualType ltype = cast<ArrayType>(lhs.getCanonicalType())->getElementType();
- QualType rtype = cast<ArrayType>(rhs.getCanonicalType())->getElementType();
-
+ // Compatible arrays must have compatible element types
+ QualType ltype = lhs->getAsArrayType()->getElementType();
+ QualType rtype = rhs->getAsArrayType()->getElementType();
+
if (!typesAreCompatible(ltype, rtype))
return false;
-
- // FIXME: If both types specify constant sizes, then the sizes must also be
- // the same. Even if the sizes are the same, GCC produces an error.
+
+ // Compatible arrays must be the same size
+ if (const ConstantArrayType* LCAT = lhs->getAsConstantArrayType())
+ if (const ConstantArrayType* RCAT = rhs->getAsConstantArrayType())
+ return RCAT->getSize() == LCAT->getSize();
+
return true;
}
diff --git a/test/Sema/compare.c b/test/Sema/compare.c
index 25d7a9169b..e1ebf575ac 100644
--- a/test/Sema/compare.c
+++ b/test/Sema/compare.c
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify %s
+// RUN: clang -fsyntax-only -pedantic -verify %s
int test(char *C) { // nothing here should warn.
return C != ((void*)0);
@@ -10,3 +10,8 @@ int equal(char *a, const char *b)
{
return a == b;
}
+
+int arrays(char (*a)[5], char(*b)[10], char(*c)[5]) {
+ int d = (a == c);
+ return a == b; // expected-warning {{comparison of distinct pointer types}}
+}