summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-04-07 06:56:55 +0000
committerChris Lattner <sabre@nondot.org>2008-04-07 06:56:55 +0000
commite6b27c6ecdd57c12f70c133fdaa8d3fbe63e1a43 (patch)
tree469be12ee9783a3c97da2bb1a326762f1ec64419 /clang
parent7460fd297dc401697f28fd540513331ff22f1345 (diff)
downloadbcm5719-llvm-e6b27c6ecdd57c12f70c133fdaa8d3fbe63e1a43.tar.gz
bcm5719-llvm-e6b27c6ecdd57c12f70c133fdaa8d3fbe63e1a43.zip
simplify array compatibility testing.
llvm-svn: 49326
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/ASTContext.h1
-rw-r--r--clang/lib/AST/ASTContext.cpp24
2 files changed, 12 insertions, 13 deletions
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index 411fba3a164..2f669b131de 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -330,7 +330,6 @@ public:
bool pointerTypesAreCompatible(QualType, QualType); // C99 6.7.5.1p2
bool referenceTypesAreCompatible(QualType, QualType); // C++ 5.17p6
bool functionTypesAreCompatible(QualType, QualType); // C99 6.7.5.3p15
- bool arrayTypesAreCompatible(QualType, QualType); // C99 6.7.5.2p6
bool isObjCIdType(QualType T) const {
if (!IdStructType) // ObjC isn't enabled
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index e781040172c..4de367551f0 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1513,20 +1513,19 @@ bool ASTContext::functionTypesAreCompatible(QualType lhs, QualType rhs) {
return true;
}
-bool ASTContext::arrayTypesAreCompatible(QualType lhs, QualType rhs) {
+// C99 6.7.5.2p6
+static bool areCompatArrayTypes(ArrayType *LHS, ArrayType *RHS, ASTContext &C) {
// Compatible arrays must have compatible element types
- QualType ltype = lhs->getAsArrayType()->getElementType();
- QualType rtype = rhs->getAsArrayType()->getElementType();
+ QualType ltype = LHS->getElementType();
+ QualType rtype = RHS->getElementType();
- if (!typesAreCompatible(ltype, rtype))
- return false;
-
- // Compatible arrays must be the same size
- if (const ConstantArrayType* LCAT = lhs->getAsConstantArrayType())
- if (const ConstantArrayType* RCAT = rhs->getAsConstantArrayType())
- return RCAT->getSize() == LCAT->getSize();
+ // Constant arrays must be the same size to be compatible.
+ if (const ConstantArrayType* LCAT = dyn_cast<ConstantArrayType>(LHS))
+ if (const ConstantArrayType* RCAT = dyn_cast<ConstantArrayType>(RHS))
+ if (RCAT->getSize() != LCAT->getSize())
+ return false;
- return true;
+ return C.typesAreCompatible(QualType(LHS, 0), QualType(RHS, 0));
}
/// areCompatVectorTypes - Return true if the two specified vector types are
@@ -1681,7 +1680,8 @@ bool ASTContext::typesAreCompatible(QualType LHS_NC, QualType RHS_NC) {
case Type::Pointer:
return pointerTypesAreCompatible(LHS, RHS);
case Type::ConstantArray:
- return arrayTypesAreCompatible(LHS, RHS);
+ return areCompatArrayTypes(cast<ArrayType>(LHS), cast<ArrayType>(RHS),
+ *this);
case Type::FunctionNoProto:
return functionTypesAreCompatible(LHS, RHS);
case Type::Tagged: // handle structures, unions
OpenPOWER on IntegriCloud