]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/6315646> clang on xcode: error: invalid operands to binary expres...
authorSteve Naroff <snaroff@apple.com>
Mon, 27 Oct 2008 10:33:19 +0000 (10:33 +0000)
committerSteve Naroff <snaroff@apple.com>
Mon, 27 Oct 2008 10:33:19 +0000 (10:33 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58241 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaObjC/comptypes-1.m

index 5304fd9f7a55107e56ec0cae94b44722c1349032..d1be2a4a272e1d1da6b2b97e9226b3f4ec63d4fa 100644 (file)
@@ -2147,11 +2147,14 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation loc,
   }
 
   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;
     }
index f6cd3a266b9a09b39e043da925c2f3f8008ac6ce..ab5262e3392ac6e9c7076ad43df2d87a30949f6b 100644 (file)
@@ -68,7 +68,7 @@ int main()
      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 *')}}