diff options
author | Chris Lattner <sabre@nondot.org> | 2008-04-07 06:56:55 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-04-07 06:56:55 +0000 |
commit | acc9972da24df89ea283d6f979ffbd0e4fa0e1a5 (patch) | |
tree | a0b52f4a29df77cf32d2195dcf4aa15199dcdfec /lib/AST/ASTContext.cpp | |
parent | 8f8fc7bdb6f42ce31d46596d4c0660625773cbef (diff) |
simplify array compatibility testing.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49326 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ASTContext.cpp')
-rw-r--r-- | lib/AST/ASTContext.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index e781040172..4de367551f 100644 --- a/lib/AST/ASTContext.cpp +++ b/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 |