[cfe-commits] r51902 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/objc-comptypes-7.m

Steve Naroff snaroff at apple.com
Tue Jun 3 07:04:55 PDT 2008


Author: snaroff
Date: Tue Jun  3 09:04:54 2008
New Revision: 51902

URL: http://llvm.org/viewvc/llvm-project?rev=51902&view=rev
Log:
Allow implicit pointer/int conversions on ObjCQualifiedIdTypes in Sema::CheckCompareOperands() and Sema::CheckAssignmentConstraints().

Fixes <rdar://problem/5980804> clang on xcode: error: incompatible type sending 'id<XDUMLType>', expected 'NSCellType'.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/objc-comptypes-7.m

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=51902&r1=51901&r2=51902&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jun  3 09:04:54 2008
@@ -1301,6 +1301,11 @@
   if (lhsType->isObjCQualifiedIdType() || rhsType->isObjCQualifiedIdType()) {
     if (ObjCQualifiedIdTypesAreCompatible(lhsType, rhsType, false))
       return Compatible;
+    // Relax integer conversions like we do for pointers below.
+    if (rhsType->isIntegerType())
+      return IntToPointer;
+    if (lhsType->isIntegerType())
+      return PointerToInt;
     return Incompatible;
   }
 
@@ -1647,12 +1652,14 @@
     ImpCastExprToType(rex, lType); // promote the pointer to pointer
     return Context.IntTy;
   }
-  if ((lType->isObjCQualifiedIdType() || rType->isObjCQualifiedIdType())
-      && ObjCQualifiedIdTypesAreCompatible(lType, rType, true)) {
-    ImpCastExprToType(rex, lType); 
-    return Context.IntTy;
+  if ((lType->isObjCQualifiedIdType() || rType->isObjCQualifiedIdType())) {
+    if (ObjCQualifiedIdTypesAreCompatible(lType, rType, true)) {
+      ImpCastExprToType(rex, lType);
+      return Context.IntTy;
+    }
   }
-  if (lType->isPointerType() && rType->isIntegerType()) {
+  if ((lType->isPointerType() || lType->isObjCQualifiedIdType()) && 
+       rType->isIntegerType()) {
     if (!RHSIsNull)
       Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer,
            lType.getAsString(), rType.getAsString(),
@@ -1660,7 +1667,8 @@
     ImpCastExprToType(rex, lType); // promote the integer to pointer
     return Context.IntTy;
   }
-  if (lType->isIntegerType() && rType->isPointerType()) {
+  if (lType->isIntegerType() && 
+      (rType->isPointerType() || rType->isObjCQualifiedIdType())) {
     if (!LHSIsNull)
       Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer,
            lType.getAsString(), rType.getAsString(),

Modified: cfe/trunk/test/Sema/objc-comptypes-7.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-comptypes-7.m?rev=51902&r1=51901&r2=51902&view=diff

==============================================================================
--- cfe/trunk/test/Sema/objc-comptypes-7.m (original)
+++ cfe/trunk/test/Sema/objc-comptypes-7.m Tue Jun  3 09:04:54 2008
@@ -27,7 +27,7 @@
   obj = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'id'}}
   obj = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'id'}}
 
-  obj_p = i; // expected-error {{incompatible type assigning 'int', expected 'id<MyProtocol>' }}
+  obj_p = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'id<MyProtocol>'}}
   obj_p = j; // expected-error {{incompatible type assigning 'int *', expected 'id<MyProtocol>'}}
   
   obj_c = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'MyClass *'}}
@@ -37,7 +37,7 @@
   obj_C = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'Class'}}
   
   i = obj;   // expected-warning {{incompatible pointer to integer conversion assigning 'id', expected 'int'}}
-  i = obj_p; // expected-error {{incompatible type assigning 'id<MyProtocol>', expected 'int'}}
+  i = obj_p; // expected-warning {{incompatible pointer to integer conversion assigning 'id<MyProtocol>', expected 'int'}}
   i = obj_c; // expected-warning {{incompatible pointer to integer conversion assigning 'MyClass *', expected 'int'}}
   i = obj_C; // expected-warning {{incompatible pointer to integer conversion assigning 'Class', expected 'int'}}
   
@@ -56,8 +56,8 @@
   if (obj_c == j) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'int *')}}
   if (j == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'MyClass *')}}
 
-  if (obj_p == i) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'int')}}
-  if (i == obj_p) foo() ; // expected-error {{invalid operands to binary expression ('int' and 'id<MyProtocol>')}}
+  if (obj_p == i) foo() ; // expected-warning {{comparison between pointer and integer ('id<MyProtocol>' and 'int')}}
+  if (i == obj_p) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'id<MyProtocol>')}}
   if (obj_p == j) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'int *')}}
   if (j == obj_p) foo() ; // expected-error {{invalid operands to binary expression ('int *' and 'id<MyProtocol>')}}
 





More information about the cfe-commits mailing list