[cfe-commits] r108758 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp test/SemaObjC/compare-qualified-class.m
Fariborz Jahanian
fjahanian at apple.com
Mon Jul 19 15:02:22 PDT 2010
Author: fjahanian
Date: Mon Jul 19 17:02:22 2010
New Revision: 108758
URL: http://llvm.org/viewvc/llvm-project?rev=108758&view=rev
Log:
Patch to type match comparing Objective-C Classes which implement
protocols (Radar 8191774).
Added:
cfe/trunk/test/SemaObjC/compare-qualified-class.m
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=108758&r1=108757&r2=108758&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Jul 19 17:02:22 2010
@@ -1235,6 +1235,8 @@
bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
bool ForCompare);
+ bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS);
+
// Check the safety of assignment from LHS to RHS
bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
const ObjCObjectPointerType *RHSOPT);
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=108758&r1=108757&r2=108758&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Jul 19 17:02:22 2010
@@ -4226,6 +4226,32 @@
return false;
}
+/// ObjCQualifiedClassTypesAreCompatible - compare Class<p,...> and
+/// Class<p1, ...>.
+bool ASTContext::ObjCQualifiedClassTypesAreCompatible(QualType lhs,
+ QualType rhs) {
+ const ObjCObjectPointerType *lhsQID = lhs->getAs<ObjCObjectPointerType>();
+ const ObjCObjectPointerType *rhsOPT = rhs->getAs<ObjCObjectPointerType>();
+ assert ((lhsQID && rhsOPT) && "ObjCQualifiedClassTypesAreCompatible");
+
+ for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(),
+ E = lhsQID->qual_end(); I != E; ++I) {
+ bool match = false;
+ ObjCProtocolDecl *lhsProto = *I;
+ for (ObjCObjectPointerType::qual_iterator J = rhsOPT->qual_begin(),
+ E = rhsOPT->qual_end(); J != E; ++J) {
+ ObjCProtocolDecl *rhsProto = *J;
+ if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto)) {
+ match = true;
+ break;
+ }
+ }
+ if (!match)
+ return false;
+ }
+ return true;
+}
+
/// ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an
/// ObjCQualifiedIDType.
bool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs,
@@ -4365,7 +4391,11 @@
return ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0),
QualType(RHSOPT,0),
false);
-
+
+ if (LHS->isObjCQualifiedClass() && RHS->isObjCQualifiedClass())
+ return ObjCQualifiedClassTypesAreCompatible(QualType(LHSOPT,0),
+ QualType(RHSOPT,0));
+
// If we have 2 user-defined types, fall into that path.
if (LHS->getInterface() && RHS->getInterface())
return canAssignObjCInterfaces(LHS, RHS);
Added: cfe/trunk/test/SemaObjC/compare-qualified-class.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/compare-qualified-class.m?rev=108758&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/compare-qualified-class.m (added)
+++ cfe/trunk/test/SemaObjC/compare-qualified-class.m Mon Jul 19 17:02:22 2010
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar:// 8191774
+
+ at protocol SomeProtocol
+ at end
+
+ at protocol SomeProtocol1
+ at end
+
+ at interface SomeObject <SomeProtocol>
+ at end
+
+int main () {
+ Class <SomeProtocol> classA;
+ Class <SomeProtocol> classB;
+ Class <SomeProtocol, SomeProtocol1> classC;
+ Class <SomeProtocol1> classD;
+ void * pv = 0;
+ Class c = (Class)0;;
+ if (pv)
+ return classA == pv;
+
+ if (c)
+ return classA == c;
+
+ return classA == classB || classA == classC ||
+ classC == classA ||
+ classA == classD; // expected-warning {{comparison of distinct pointer types ('Class<SomeProtocol> *' and 'Class<SomeProtocol1> *')}}
+}
+
More information about the cfe-commits
mailing list