[cfe-commits] r161458 - in /cfe/trunk: lib/Sema/SemaExpr.cpp lib/Sema/SemaExprMember.cpp test/SemaObjC/warn-direct-ivar-access.m
Fariborz Jahanian
fjahanian at apple.com
Tue Aug 7 16:48:11 PDT 2012
Author: fjahanian
Date: Tue Aug 7 18:48:10 2012
New Revision: 161458
URL: http://llvm.org/viewvc/llvm-project?rev=161458&view=rev
Log:
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
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=161458&r1=161457&r2=161458&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Aug 7 18:48:10 2012
@@ -1961,9 +1961,7 @@
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();
Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=161458&r1=161457&r2=161458&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Tue Aug 7 18:48:10 2012
@@ -1250,6 +1250,7 @@
<< IV->getDeclName();
}
}
+ bool warn = true;
if (getLangOpts().ObjCAutoRefCount) {
Expr *BaseExp = BaseExpr.get()->IgnoreParenImpCasts();
if (UnaryOperator *UO = dyn_cast<UnaryOperator>(BaseExp))
@@ -1257,13 +1258,12 @@
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 &&
Modified: cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m?rev=161458&r1=161457&r2=161458&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m (original)
+++ cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m Tue Aug 7 18:48:10 2012
@@ -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 @@
id _isTickledPink;
}
@property(retain) id myMaster;
- at property(assign) id isTickledPink;
+ at property(assign) id isTickledPink; // expected-note {{property declared here}}
@end
@implementation MyObject
@synthesize myMaster = _myMaster;
- at synthesize isTickledPink = _isTickledPink;
+ at 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 @@
return p->_isTickledPink; // expected-warning {{instance variable '_isTickledPink' is being directly accessed}}
}
+ at interface ITest32 {
+ at public
+ id ivar;
+}
+ at 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}}
+}
+
More information about the cfe-commits
mailing list