[cfe-commits] r49326 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp

Chris Lattner sabre at nondot.org
Sun Apr 6 23:56:55 PDT 2008


Author: lattner
Date: Mon Apr  7 01:56:55 2008
New Revision: 49326

URL: http://llvm.org/viewvc/llvm-project?rev=49326&view=rev
Log:
simplify array compatibility testing.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=49326&r1=49325&r2=49326&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Apr  7 01:56:55 2008
@@ -330,7 +330,6 @@
   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

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=49326&r1=49325&r2=49326&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Apr  7 01:56:55 2008
@@ -1513,20 +1513,19 @@
   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 @@
   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





More information about the cfe-commits mailing list