[cfe-commits] r158938 - in /cfe/trunk: lib/Sema/SemaExprMember.cpp test/SemaObjC/id-isa-ref.m test/SemaObjC/warn-isa-ref.m
Fariborz Jahanian
fjahanian at apple.com
Thu Jun 21 14:35:15 PDT 2012
Author: fjahanian
Date: Thu Jun 21 16:35:15 2012
New Revision: 158938
URL: http://llvm.org/viewvc/llvm-project?rev=158938&view=rev
Log:
objective-c: If an ivar is (1) the first ivar in a root class and (2) named `isa`,
then it should get the same warnings that id->isa gets. // rdar://11702488
Added:
cfe/trunk/test/SemaObjC/warn-isa-ref.m
- copied, changed from r158919, cfe/trunk/test/SemaObjC/id-isa-ref.m
Removed:
cfe/trunk/test/SemaObjC/id-isa-ref.m
Modified:
cfe/trunk/lib/Sema/SemaExprMember.cpp
Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=158938&r1=158937&r2=158938&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Thu Jun 21 16:35:15 2012
@@ -1149,7 +1149,20 @@
ObjCImpDecl, HasTemplateArgs);
goto fail;
}
-
+ else if (Member && Member->isStr("isa")) {
+ // If an ivar is (1) the first ivar in a root class and (2) named `isa`,
+ // then issue the same deprecated warning that id->isa gets.
+ ObjCInterfaceDecl *ClassDeclared = 0;
+ if (ObjCIvarDecl *IV =
+ IDecl->lookupInstanceVariable(Member, ClassDeclared)) {
+ if (!ClassDeclared->getSuperClass()
+ && (*ClassDeclared->ivar_begin()) == IV) {
+ Diag(MemberLoc, diag::warn_objc_isa_use);
+ Diag(IV->getLocation(), diag::note_ivar_decl);
+ }
+ }
+ }
+
if (RequireCompleteType(OpLoc, BaseType, diag::err_typecheck_incomplete_tag,
BaseExpr.get()))
return ExprError();
Removed: cfe/trunk/test/SemaObjC/id-isa-ref.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/id-isa-ref.m?rev=158937&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/id-isa-ref.m (original)
+++ cfe/trunk/test/SemaObjC/id-isa-ref.m (removed)
@@ -1,35 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-typedef struct objc_object {
- struct objc_class *isa;
-} *id;
-
- at interface NSObject {
- struct objc_class *isa;
-}
- at end
- at interface Whatever : NSObject
-+self;
- at end
-
-static void func() {
-
- id x;
-
- // 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;
-
- // GCC allows this, with the following warning:
- // instance variable 'isa' is @protected; this will be a hard error in the future
- //
- // FIXME: see if we can avoid the 2 warnings that follow the error.
- [(*y).isa self]; // expected-error {{instance variable 'isa' is protected}} \
- expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} \
- expected-warning{{method '-self' not found (return type defaults to 'id')}}
- [y->isa self]; // expected-error {{instance variable 'isa' is protected}} \
- expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} \
- expected-warning{{method '-self' not found (return type defaults to 'id')}}
-}
Copied: cfe/trunk/test/SemaObjC/warn-isa-ref.m (from r158919, cfe/trunk/test/SemaObjC/id-isa-ref.m)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-isa-ref.m?p2=cfe/trunk/test/SemaObjC/warn-isa-ref.m&p1=cfe/trunk/test/SemaObjC/id-isa-ref.m&r1=158919&r2=158938&rev=158938&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/id-isa-ref.m (original)
+++ cfe/trunk/test/SemaObjC/warn-isa-ref.m Thu Jun 21 16:35:15 2012
@@ -5,6 +5,7 @@
} *id;
@interface NSObject {
+ id firstobj;
struct objc_class *isa;
}
@end
@@ -33,3 +34,50 @@
expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} \
expected-warning{{method '-self' not found (return type defaults to 'id')}}
}
+
+// rdar://11702488
+// If an ivar is (1) the first ivar in a root class and (2) named `isa`,
+// then it should get the same warnings that id->isa gets.
+
+ at interface BaseClass {
+ at public
+ Class isa; // expected-note 3 {{ivar is declared here}}
+}
+ at end
+
+ at interface OtherClass {
+ at public
+ id firstIvar;
+ Class isa; // note, not first ivar;
+}
+ at end
+
+ at interface Subclass : BaseClass @end
+
+ at interface SiblingClass : BaseClass @end
+
+ at interface Root @end
+
+ at interface hasIsa : Root {
+ at public
+ Class isa; // note, isa is not in root class
+}
+ at end
+
+ at implementation Subclass
+-(void)method {
+ hasIsa *u;
+ id v;
+ BaseClass *w;
+ Subclass *x;
+ SiblingClass *y;
+ OtherClass *z;
+ (void)v->isa; // expected-warning {{direct access to objective-c's isa is deprecated}}
+ (void)w->isa; // expected-warning {{direct access to objective-c's isa is deprecated}}
+ (void)x->isa; // expected-warning {{direct access to objective-c's isa is deprecated}}
+ (void)y->isa; // expected-warning {{direct access to objective-c's isa is deprecated}}
+ (void)z->isa;
+ (void)u->isa;
+}
+ at end
+
More information about the cfe-commits
mailing list