aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-12-08 18:24:49 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-12-08 18:24:49 +0000
commit52efc3fdbabaf4848f47887eda130b0961508cd0 (patch)
treef811f5999e3c30a418de1a4346f69df201e57bb3
parent0ae7b3f1d5403265f693ed75384603ca8fbba74d (diff)
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
-rw-r--r--lib/Sema/Sema.h3
-rw-r--r--lib/Sema/SemaExpr.cpp41
2 files changed, 27 insertions, 17 deletions
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<ObjCObjectPointerType>()->getPointeeType();
+ QualType rhptee =
+ rhsType->getAs<ObjCObjectPointerType>()->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<ObjCObjectPointerType>()->getPointeeType();
- QualType rhptee =
- rhsType->getAs<ObjCObjectPointerType>()->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<PointerType>()) {
if (RHSPT->getPointeeType()->isVoidType())