[cfe-commits] r45269 - in /cfe/trunk: AST/ASTContext.cpp test/Sema/objc-comptypes-1.m test/Sema/objc-string.m

Fariborz Jahanian fjahanian at apple.com
Thu Dec 20 14:37:58 PST 2007


Author: fjahanian
Date: Thu Dec 20 16:37:58 2007
New Revision: 45269

URL: http://llvm.org/viewvc/llvm-project?rev=45269&view=rev
Log:
More objective-c type checking. This time comparing objective-c known objects.

Modified:
    cfe/trunk/AST/ASTContext.cpp
    cfe/trunk/test/Sema/objc-comptypes-1.m
    cfe/trunk/test/Sema/objc-string.m

Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=45269&r1=45268&r2=45269&view=diff

==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Thu Dec 20 16:37:58 2007
@@ -1235,7 +1235,19 @@
 }
 
 bool ASTContext::interfaceTypesAreCompatible(QualType lhs, QualType rhs) {
-  return true; // FIXME: IMPLEMENT.
+  if (lhs == rhs)
+    return true;
+  ObjcInterfaceType *lhsIT = cast<ObjcInterfaceType>(lhs.getTypePtr());
+  ObjcInterfaceType *rhsIT = cast<ObjcInterfaceType>(rhs.getTypePtr());
+  ObjcInterfaceDecl *rhsIDecl = rhsIT->getDecl();
+  ObjcInterfaceDecl *lhsIDecl = lhsIT->getDecl();
+  // rhs is derived from lhs it is OK; else it is not OK.
+  while (rhsIDecl != NULL) {
+    if (rhsIDecl == lhsIDecl)
+      return true;
+    rhsIDecl = rhsIDecl->getSuperClass();
+  }
+  return false;
 }
 
 bool ASTContext::QualifiedInterfaceTypesAreCompatible(QualType lhs, 

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

==============================================================================
--- cfe/trunk/test/Sema/objc-comptypes-1.m (original)
+++ cfe/trunk/test/Sema/objc-comptypes-1.m Thu Dec 20 16:37:58 2007
@@ -33,6 +33,7 @@
   /* Assigning to a 'MyClass *' variable should always generate a
      warning, unless done from an 'id'.  */
   obj_c = obj;    /* Ok */
+  obj_c = obj_cp; // // expected-warning {{incompatible pointer types assigning 'MyOtherClass *' to 'MyClass *'}}
   obj_c = obj_C;  // expected-warning {{incompatible pointer types assigning 'Class' to 'MyClass *'}}
 
   /* Assigning to an 'id<MyProtocol>' variable should generate a
@@ -48,6 +49,7 @@
      a warning, unless done from an 'id' or an 'id<MyProtocol>' (since
      MyOtherClass implements MyProtocol).  */
   obj_cp = obj;    /* Ok */
+  obj_cp = obj_c;  // expected-warning {{incompatible pointer types assigning 'MyClass *' to 'MyOtherClass *'}}
   obj_cp = obj_p;  /* Ok */
   obj_cp = obj_C;  // expected-warning {{incompatible pointer types assigning 'Class' to 'MyOtherClass *'}}
 
@@ -64,6 +66,10 @@
   /* Any comparison between 'MyClass *' and anything which is not an 'id'
      must generate a warning.  */
   if (obj_p == obj_c) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'MyClass *')}}
+
+  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 *')}}
+
   if (obj_c == obj_C) foo() ;  // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'Class')}}
   if (obj_C == obj_c) foo() ;  // expected-warning {{comparison of distinct pointer types ('Class' and 'MyClass *')}} 
 

Modified: cfe/trunk/test/Sema/objc-string.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-string.m?rev=45269&r1=45268&r2=45269&view=diff

==============================================================================
--- cfe/trunk/test/Sema/objc-string.m (original)
+++ cfe/trunk/test/Sema/objc-string.m Thu Dec 20 16:37:58 2007
@@ -1,12 +1,11 @@
 // RUN: clang %s -verify -fsyntax-only
 
- at class NSString;
 @interface NSConstantString;
 @end
 
 
 
-NSString *s = @"123"; // simple
-NSString *t = @"123" @"456"; // concat
-NSString *u = @"123" @ blah; // expected-error: {{unexpected token}}
+NSConstantString *s = @"123"; // simple
+NSConstantString *t = @"123" @"456"; // concat
+NSConstantString *u = @"123" @ blah; // expected-error: {{unexpected token}}
 





More information about the cfe-commits mailing list