From: Fariborz Jahanian Date: Tue, 8 Dec 2009 18:24:49 +0000 (+0000) Subject: Refactor objective-c pointer assignment compatibility logic. No X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=52efc3fdbabaf4848f47887eda130b0961508cd0;p=clang Refactor objective-c pointer assignment compatibility logic. No intended functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90865 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 46a87cff3f..a7eb0c6d88 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -3553,6 +3553,9 @@ public: AssignConvertType CheckPointerTypesForAssignment(QualType lhsType, QualType rhsType); + AssignConvertType CheckObjCPointerTypesForAssignment(QualType lhsType, + QualType rhsType); + // Helper function for CheckAssignmentConstraints involving two // block pointer types. AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType, diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 776ea71f29..4920206b25 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4310,6 +4310,29 @@ Sema::CheckBlockPointerTypesForAssignment(QualType lhsType, return ConvTy; } +/// CheckObjCPointerTypesForAssignment - Compares two objective-c pointer types +/// for assignment compatibility. +Sema::AssignConvertType +Sema::CheckObjCPointerTypesForAssignment(QualType lhsType, QualType rhsType) { + if (lhsType->isObjCBuiltinType() || rhsType->isObjCBuiltinType()) + return Compatible; + QualType lhptee = + lhsType->getAs()->getPointeeType(); + QualType rhptee = + rhsType->getAs()->getPointeeType(); + // make sure we operate on the canonical type + lhptee = Context.getCanonicalType(lhptee); + rhptee = Context.getCanonicalType(rhptee); + if (!lhptee.isAtLeastAsQualifiedAs(rhptee)) + return CompatiblePointerDiscardsQualifiers; + + if (Context.typesAreCompatible(lhsType, rhsType)) + return Compatible; + if (lhsType->isObjCQualifiedIdType() || rhsType->isObjCQualifiedIdType()) + return IncompatibleObjCQualifiedId; + return IncompatiblePointer; +} + /// CheckAssignmentConstraints (C99 6.5.16) - This routine currently /// has code to accommodate several GCC extensions when type checking /// pointers. Here are some objectionable examples that GCC considers warnings: @@ -4432,23 +4455,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { return IncompatiblePointer; } if (rhsType->isObjCObjectPointerType()) { - if (lhsType->isObjCBuiltinType() || rhsType->isObjCBuiltinType()) - return Compatible; - QualType lhptee = - lhsType->getAs()->getPointeeType(); - QualType rhptee = - rhsType->getAs()->getPointeeType(); - // make sure we operate on the canonical type - lhptee = Context.getCanonicalType(lhptee); - rhptee = Context.getCanonicalType(rhptee); - if (!lhptee.isAtLeastAsQualifiedAs(rhptee)) - return CompatiblePointerDiscardsQualifiers; - - if (Context.typesAreCompatible(lhsType, rhsType)) - return Compatible; - if (lhsType->isObjCQualifiedIdType() || rhsType->isObjCQualifiedIdType()) - return IncompatibleObjCQualifiedId; - return IncompatiblePointer; + return CheckObjCPointerTypesForAssignment(lhsType, rhsType); } if (const PointerType *RHSPT = rhsType->getAs()) { if (RHSPT->getPointeeType()->isVoidType())