objective-c: Exclude -Wdirect-ivar-access for arc.

Allow direct ivar access in init and dealloc methods
in mrr. // rdar://650197

llvm-svn: 161426
This commit is contained in:
Fariborz Jahanian 2012-08-07 16:38:44 +00:00
parent 59fba12d28
commit a7c9f883e6
3 changed files with 22 additions and 4 deletions

View File

@ -1962,8 +1962,12 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S,
MarkAnyDeclReferenced(Loc, IV);
if (IV->getType()->isObjCObjectPointerType() &&
getLangOpts().getGC() == LangOptions::NonGC)
Diag(Loc, diag::warn_direct_ivar_access) << IV->getDeclName();
getLangOpts().getGC() == LangOptions::NonGC &&
!getLangOpts().ObjCAutoRefCount) {
ObjCMethodFamily MF = CurMethod->getMethodFamily();
if (MF != OMF_init && MF != OMF_dealloc && MF != OMF_finalize)
Diag(Loc, diag::warn_direct_ivar_access) << IV->getDeclName();
}
return Owned(new (Context)
ObjCIvarRefExpr(IV, IV->getType(), Loc,
SelfExpr.take(), true, true));

View File

@ -1261,8 +1261,17 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
Diag(DE->getLocation(), diag::error_arc_weak_ivar_access);
}
if (IV->getType()->isObjCObjectPointerType() &&
getLangOpts().getGC() == LangOptions::NonGC)
Diag(MemberLoc, diag::warn_direct_ivar_access) << IV->getDeclName();
getLangOpts().getGC() == LangOptions::NonGC &&
!getLangOpts().ObjCAutoRefCount) {
bool warn = true;
if (ObjCMethodDecl *MD = getCurMethodDecl()) {
ObjCMethodFamily MF = MD->getMethodFamily();
warn = (MF != OMF_init && MF != OMF_dealloc &&
MF != OMF_finalize);
}
if (warn)
Diag(MemberLoc, diag::warn_direct_ivar_access) << IV->getDeclName();
}
return Owned(new (Context) ObjCIvarRefExpr(IV, IV->getType(),
MemberLoc, BaseExpr.take(),
IsArrow));

View File

@ -20,6 +20,11 @@ __attribute__((objc_root_class)) @interface MyObject {
// expected-warning {{instance variable '_isTickledPink' is being directly accessed}}
}
- (id) init {
_myMaster=0;
return _myMaster;
}
- (void) dealloc { _myMaster = 0; }
@end
MyObject * foo ()