[cfe-commits] r64393 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/conditional-expr-2.m

Steve Naroff snaroff at apple.com
Thu Feb 12 11:05:07 PST 2009


Author: snaroff
Date: Thu Feb 12 13:05:07 2009
New Revision: 64393

URL: http://llvm.org/viewvc/llvm-project?rev=64393&view=rev
Log:
Fix <rdar://problem/6499801> clang does not detect objc type mismatch in conditional expr

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaObjC/conditional-expr-2.m

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Feb 12 13:05:07 2009
@@ -2245,9 +2245,8 @@
         // incompatible then make sure to use 'id' as the composite
         // type so the result is acceptable for sending messages to.
 
-        // FIXME: This code should not be localized to here. Also this
-        // should use a compatible check instead of abusing the
-        // canAssignObjCInterfaces code.
+        // FIXME: Consider unifying with 'areComparableObjCPointerTypes'.
+        // It could return the composite type.      
         const ObjCInterfaceType* LHSIface = lhptee->getAsObjCInterfaceType();
         const ObjCInterfaceType* RHSIface = rhptee->getAsObjCInterfaceType();
         if (LHSIface && RHSIface &&
@@ -2258,11 +2257,11 @@
           compositeType = rexT;
         } else if (Context.isObjCIdStructType(lhptee) || 
                    Context.isObjCIdStructType(rhptee)) { 
-          // FIXME: This code looks wrong, because isObjCIdStructType checks
-          // the struct but getObjCIdType returns the pointer to
-          // struct. This is horrible and should be fixed.
           compositeType = Context.getObjCIdType();
         } else {
+          Diag(questionLoc, diag::ext_typecheck_comparison_of_distinct_pointers)
+               << lexT << rexT 
+               << lex->getSourceRange() << rex->getSourceRange();
           QualType incompatTy = Context.getObjCIdType();
           ImpCastExprToType(lex, incompatTy);
           ImpCastExprToType(rex, incompatTy);

Modified: cfe/trunk/test/SemaObjC/conditional-expr-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/conditional-expr-2.m?rev=64393&r1=64392&r2=64393&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/conditional-expr-2.m (original)
+++ cfe/trunk/test/SemaObjC/conditional-expr-2.m Thu Feb 12 13:05:07 2009
@@ -8,5 +8,22 @@
 void f0(int cond, A *a, B *b) {
   // Ensure that we can still send a message to result of incompatible
   // conditional expression.
-  [ (cond ? a : b) test ]; // expected-warning {{method '-test' not found}}
+  [ (cond ? a : b) test ]; // expected-warning{{comparison of distinct pointer types ('A *' and 'B *')}} expected-warning {{method '-test' not found}}
+}
+
+ at interface NSKey @end
+ at interface KeySub : NSKey @end
+
+ at interface UpdatesList @end
+
+void foo (int i, NSKey *NSKeyValueCoding_NullValue, UpdatesList *nukedUpdatesList)
+{
+  id obj;
+  NSKey *key;
+  KeySub *keysub;
+
+  obj = i ? NSKeyValueCoding_NullValue : nukedUpdatesList; // expected-warning{{comparison of distinct pointer types ('NSKey *' and 'UpdatesList *')}}
+  key = i ? NSKeyValueCoding_NullValue : nukedUpdatesList; // expected-warning{{comparison of distinct pointer types ('NSKey *' and 'UpdatesList *')}}
+  key = i ? NSKeyValueCoding_NullValue : keysub;
+  keysub = i ? NSKeyValueCoding_NullValue : keysub; // expected-warning{{incompatible pointer types assigning 'NSKey *', expected 'KeySub *'}}
 }





More information about the cfe-commits mailing list