[cfe-commits] r58241 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/comptypes-1.m

Steve Naroff snaroff at apple.com
Mon Oct 27 03:33:19 PDT 2008


Author: snaroff
Date: Mon Oct 27 05:33:19 2008
New Revision: 58241

URL: http://llvm.org/viewvc/llvm-project?rev=58241&view=rev
Log:
Fix <rdar://problem/6315646> clang on xcode: error: invalid operands to binary expression ('id<NSTableViewDelegate>' and 'XCExtendedArrayController *').

There is still a bug here (as the FIXME in the test case indicates). Prior to this patch, the bug would generate an error. Now, we simply do nothing (which is less harmful until we can get it right). The complete bug fix will require changing ASTContext::mergeTypes(), which I'd like to defer for now.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaObjC/comptypes-1.m

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Oct 27 05:33:19 2008
@@ -2147,11 +2147,14 @@
   }
 
   if ((lType->isObjCQualifiedIdType() || rType->isObjCQualifiedIdType())) {
-    if ((lType->isPointerType() || rType->isPointerType()) &&
-        !Context.typesAreCompatible(lType, rType)) {
-      Diag(loc, diag::ext_typecheck_comparison_of_distinct_pointers,
-           lType.getAsString(), rType.getAsString(),
-           lex->getSourceRange(), rex->getSourceRange());
+    if (lType->isPointerType() || rType->isPointerType()) {
+      if (!Context.typesAreCompatible(lType, rType)) {
+        Diag(loc, diag::ext_typecheck_comparison_of_distinct_pointers,
+             lType.getAsString(), rType.getAsString(),
+             lex->getSourceRange(), rex->getSourceRange());
+        ImpCastExprToType(rex, lType);
+        return Context.IntTy;
+      }
       ImpCastExprToType(rex, lType);
       return Context.IntTy;
     }

Modified: cfe/trunk/test/SemaObjC/comptypes-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/comptypes-1.m?rev=58241&r1=58240&r2=58241&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/comptypes-1.m (original)
+++ cfe/trunk/test/SemaObjC/comptypes-1.m Mon Oct 27 05:33:19 2008
@@ -68,7 +68,7 @@
      must generate a warning.  */
   /* FIXME: GCC considers this a warning ("comparison of distinct pointer types"). */
   /* There is a corresponding FIXME in ASTContext::mergeTypes() */
-  if (obj_p == obj_c) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'MyClass *')}}
+  if (obj_p == obj_c) foo() ;
 
   if (obj_c == obj_cp) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'MyOtherClass *')}} 
   if (obj_cp == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'MyClass *')}}





More information about the cfe-commits mailing list