[cfe-commits] r148404 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprMember.cpp test/Analysis/misc-ps-region-store.m test/SemaObjC/id-isa-ref.m test/SemaObjCXX/instantiate-expr.mm

Fariborz Jahanian fjahanian at apple.com
Wed Jan 18 11:08:57 PST 2012


Author: fjahanian
Date: Wed Jan 18 13:08:56 2012
New Revision: 148404

URL: http://llvm.org/viewvc/llvm-project?rev=148404&view=rev
Log:
objc: deprecate direct usage of 'isa' of objc objects
in favor of usage of api's intended for.
// rdar://8290002

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExprMember.cpp
    cfe/trunk/test/Analysis/misc-ps-region-store.m
    cfe/trunk/test/SemaObjC/id-isa-ref.m
    cfe/trunk/test/SemaObjCXX/instantiate-expr.mm

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=148404&r1=148403&r2=148404&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jan 18 13:08:56 2012
@@ -511,6 +511,10 @@
 def warn_objc_property_no_assignment_attribute : Warning<
   "no 'assign', 'retain', or 'copy' attribute is specified - "
   "'assign' is assumed">;
+def warn_objc_isa_use : Warning<
+  "direct access to objective-c's isa is deprecated "
+  "in favor of object_setClass() and object_getClass()">,
+  InGroup<DiagGroup<"deprecated-objective-c-isa-usage">>;
 def warn_objc_property_default_assign_on_object : Warning<
   "default property attribute 'assign' not appropriate for non-gc object">;
 def warn_property_attr_mismatch : Warning<

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=148404&r1=148403&r2=148404&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Wed Jan 18 13:08:56 2012
@@ -1114,10 +1114,12 @@
         goto fail;
       // There's an implicit 'isa' ivar on all objects.
       // But we only actually find it this way on objects of type 'id',
-      // apparently.
-      if (OTy->isObjCId() && Member->isStr("isa"))
+      // apparently.ghjg
+      if (OTy->isObjCId() && Member->isStr("isa")) {
+        Diag(MemberLoc, diag::warn_objc_isa_use);
         return Owned(new (Context) ObjCIsaExpr(BaseExpr.take(), IsArrow, MemberLoc,
                                                Context.getObjCClassType()));
+      }
 
       if (ShouldTryAgainWithRedefinitionType(*this, BaseExpr))
         return LookupMemberExpr(R, BaseExpr, IsArrow, OpLoc, SS,

Modified: cfe/trunk/test/Analysis/misc-ps-region-store.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps-region-store.m?rev=148404&r1=148403&r2=148404&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps-region-store.m (original)
+++ cfe/trunk/test/Analysis/misc-ps-region-store.m Wed Jan 18 13:08:56 2012
@@ -918,7 +918,7 @@
 
 void pr6302(id x, Class y) {
   // This previously crashed the analyzer (reported in PR 6302)
-  x->isa  = y;
+  x->isa  = y; // expected-warning {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}}
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/test/SemaObjC/id-isa-ref.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/id-isa-ref.m?rev=148404&r1=148403&r2=148404&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/id-isa-ref.m (original)
+++ cfe/trunk/test/SemaObjC/id-isa-ref.m Wed Jan 18 13:08:56 2012
@@ -16,8 +16,9 @@
  
   id x;
 
-  [(*x).isa self];
-  [x->isa self];
+  // rdar://8290002
+  [(*x).isa self]; // expected-warning {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}}
+  [x->isa self]; // expected-warning {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}}
   
   Whatever *y;
 

Modified: cfe/trunk/test/SemaObjCXX/instantiate-expr.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/instantiate-expr.mm?rev=148404&r1=148403&r2=148404&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/instantiate-expr.mm (original)
+++ cfe/trunk/test/SemaObjCXX/instantiate-expr.mm Wed Jan 18 13:08:56 2012
@@ -20,10 +20,11 @@
 void f(U value, V value2) {
   get_an_A(N)->ivar = value; // expected-error{{assigning to 'int' from incompatible type 'int *'}}
   get_an_A(N).prop = value2; // expected-error{{assigning to 'int' from incompatible type 'double *'}}
-  T c = get_an_id(N)->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}}
+  T c = get_an_id(N)->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} \
+                           // expected-warning 5 {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}}
 }
 
-template void f<6, Class>(int, int);
+template void f<6, Class>(int, int); // expected-note{{in instantiation of}}
 template void f<7, Class>(int*, int); // expected-note{{in instantiation of}}
 template void f<8, Class>(int, double*); // expected-note{{in instantiation of}}
 template void f<9, int>(int, int); // expected-note{{in instantiation of}}
@@ -44,10 +45,11 @@
 // an isa.
 template<typename T, typename U>
 void f3(U ptr) {
-  T c = ptr->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}}
+  T c = ptr->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} \
+                  // expected-warning 2 {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}}
 }
 
-template void f3<Class>(id);
+template void f3<Class>(id); // expected-note{{in instantiation of}}
 template void f3<int>(id); // expected-note{{instantiation of}}
 
 // Implicit setter/getter





More information about the cfe-commits mailing list