[cfe-commits] r161458 - in /cfe/trunk: lib/Sema/SemaExpr.cpp lib/Sema/SemaExprMember.cpp test/SemaObjC/warn-direct-ivar-access.m
Douglas Gregor
dgregor at apple.com
Wed Aug 8 09:16:23 PDT 2012
On Aug 7, 2012, at 4:48 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> 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
Thanks! One last question…
> 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 &&
In both cases, why do we restrict this warning to ivars of Objective-C pointer type? Direct ivar access to an 'int' ivar is still direct access to an ivar, when one should presumably go through a property or method.
- Doug
More information about the cfe-commits
mailing list