[cfe-commits] r161362 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp lib/Sema/SemaExprMember.cpp test/SemaObjC/warn-direct-ivar-access.m
Jordan Rose
jordan_rose at apple.com
Mon Aug 6 17:09:29 PDT 2012
Why does this only warn under non-GC?
Jordan
On Aug 6, 2012, at 16:50 , Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Mon Aug 6 18:50:51 2012
> New Revision: 161362
>
> URL: http://llvm.org/viewvc/llvm-project?rev=161362&view=rev
> Log:
> objective-c: Implement gcc's -Wdirect-ivar-access option.
> // rdar://6505197
>
> Added:
> cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/lib/Sema/SemaExprMember.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=161362&r1=161361&r2=161362&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Aug 6 18:50:51 2012
> @@ -5759,6 +5759,8 @@
> def warn_missing_method_return_type : Warning<
> "method has no return type specified; defaults to 'id'">,
> InGroup<MissingMethodReturnType>, DefaultIgnore;
> +def warn_direct_ivar_access : Warning<"instance variable %0 is being "
> + "directly accessed">, InGroup<DiagGroup<"direct-ivar-access">>, DefaultIgnore;
>
> // Spell-checking diagnostics
> def err_unknown_type_or_class_name_suggest : Error<
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=161362&r1=161361&r2=161362&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Aug 6 18:50:51 2012
> @@ -1961,6 +1961,9 @@
> return ExprError();
>
> MarkAnyDeclReferenced(Loc, IV);
> + if (IV->getType()->isObjCObjectPointerType() &&
> + getLangOpts().getGC() == LangOptions::NonGC)
> + Diag(Loc, diag::warn_direct_ivar_access) << IV->getDeclName();
> return Owned(new (Context)
> ObjCIvarRefExpr(IV, IV->getType(), Loc,
> SelfExpr.take(), true, true));
>
> Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=161362&r1=161361&r2=161362&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprMember.cpp Mon Aug 6 18:50:51 2012
> @@ -1260,7 +1260,9 @@
> if (DE->getType().getObjCLifetime() == Qualifiers::OCL_Weak)
> 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();
> return Owned(new (Context) ObjCIvarRefExpr(IV, IV->getType(),
> MemberLoc, BaseExpr.take(),
> IsArrow));
>
> Added: 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=161362&view=auto
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m (added)
> +++ cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m Mon Aug 6 18:50:51 2012
> @@ -0,0 +1,33 @@
> +// RUN: %clang_cc1 -fsyntax-only -Wdirect-ivar-access -verify -Wno-objc-root-class %s
> +// rdar://6505197
> +
> +__attribute__((objc_root_class)) @interface MyObject {
> + at public
> + id _myMaster;
> + id _isTickledPink;
> +}
> + at property(retain) id myMaster;
> + at property(assign) id isTickledPink;
> + at end
> +
> + at implementation MyObject
> +
> + at synthesize myMaster = _myMaster;
> + at synthesize isTickledPink = _isTickledPink;
> +
> +- (void) doSomething {
> + _myMaster = _isTickledPink; // expected-warning {{instance variable '_myMaster' is being directly accessed}} \
> + // expected-warning {{instance variable '_isTickledPink' is being directly accessed}}
> +}
> +
> + at end
> +
> +MyObject * foo ()
> +{
> + MyObject* p=0;
> + p.isTickledPink = p.myMaster; // ok
> + p->_isTickledPink = (*p)._myMaster; // expected-warning {{instance variable '_isTickledPink' is being directly accessed}} \
> + // expected-warning {{instance variable '_myMaster' is being directly accessed}}
> + return p->_isTickledPink; // expected-warning {{instance variable '_isTickledPink' is being directly accessed}}
> +}
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list