objc-arc: Make -Wdirect-ivar-access accessible to all

memory models, except when arc is accessing a weak
ivar (which is an error). // rdar://6505197

llvm-svn: 161458
This commit is contained in:
Fariborz Jahanian 2012-08-07 23:48:10 +00:00
parent 42032fafe4
commit 285a7cc721
3 changed files with 22 additions and 11 deletions

View File

@ -1961,9 +1961,7 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S,
return ExprError();
MarkAnyDeclReferenced(Loc, IV);
if (IV->getType()->isObjCObjectPointerType() &&
getLangOpts().getGC() == LangOptions::NonGC &&
!getLangOpts().ObjCAutoRefCount) {
if (IV->getType()->isObjCObjectPointerType()) {
ObjCMethodFamily MF = CurMethod->getMethodFamily();
if (MF != OMF_init && MF != OMF_dealloc && MF != OMF_finalize)
Diag(Loc, diag::warn_direct_ivar_access) << IV->getDeclName();

View File

@ -1250,6 +1250,7 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
<< IV->getDeclName();
}
}
bool warn = true;
if (getLangOpts().ObjCAutoRefCount) {
Expr *BaseExp = BaseExpr.get()->IgnoreParenImpCasts();
if (UnaryOperator *UO = dyn_cast<UnaryOperator>(BaseExp))
@ -1257,13 +1258,12 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
BaseExp = UO->getSubExpr()->IgnoreParenCasts();
if (DeclRefExpr *DE = dyn_cast<DeclRefExpr>(BaseExp))
if (DE->getType().getObjCLifetime() == Qualifiers::OCL_Weak)
if (DE->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {
Diag(DE->getLocation(), diag::error_arc_weak_ivar_access);
warn = false;
}
if (IV->getType()->isObjCObjectPointerType() &&
getLangOpts().getGC() == LangOptions::NonGC &&
!getLangOpts().ObjCAutoRefCount) {
bool warn = true;
}
if (warn && IV->getType()->isObjCObjectPointerType()) {
if (ObjCMethodDecl *MD = getCurMethodDecl()) {
ObjCMethodFamily MF = MD->getMethodFamily();
warn = (MF != OMF_init && MF != OMF_dealloc &&

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -Wdirect-ivar-access -verify -Wno-objc-root-class %s
// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -Wdirect-ivar-access -verify -Wno-objc-root-class %s
// rdar://6505197
__attribute__((objc_root_class)) @interface MyObject {
@ -7,13 +7,13 @@ __attribute__((objc_root_class)) @interface MyObject {
id _isTickledPink;
}
@property(retain) id myMaster;
@property(assign) id isTickledPink;
@property(assign) id isTickledPink; // expected-note {{property declared here}}
@end
@implementation MyObject
@synthesize myMaster = _myMaster;
@synthesize isTickledPink = _isTickledPink;
@synthesize isTickledPink = _isTickledPink; // expected-error {{existing ivar '_isTickledPink' for property 'isTickledPink'}}
- (void) doSomething {
_myMaster = _isTickledPink; // expected-warning {{instance variable '_myMaster' is being directly accessed}} \
@ -36,3 +36,16 @@ MyObject * foo ()
return p->_isTickledPink; // expected-warning {{instance variable '_isTickledPink' is being directly accessed}}
}
@interface ITest32 {
@public
id ivar;
}
@end
id Test32(__weak ITest32 *x) {
__weak ITest32 *y;
x->ivar = 0; // expected-error {{dereferencing a __weak pointer is not allowed}}
return y ? y->ivar // expected-error {{dereferencing a __weak pointer is not allowed}}
: (*x).ivar; // expected-error {{dereferencing a __weak pointer is not allowed}}
}