[cfe-commits] r165133 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/FixIt/fixit-missing-self-in-block.m test/SemaObjC/warn-implicit-self-in-block.m test/SemaObjC/warn-retain-cycle.m
Jordan Rose
jordan_rose at apple.com
Wed Oct 3 13:47:24 PDT 2012
On Oct 3, 2012, at 10:55 , Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Wed Oct 3 12:55:29 2012
> New Revision: 165133
>
> URL: http://llvm.org/viewvc/llvm-project?rev=165133&view=rev
> Log:
> objective-C arc: Warn under arc about a use of an ivar inside a block
> that doesn't have a 'self' as this implicitly captures 'self' and could
> create retain cycles. Provide fixit. // rdar://11194874
>
> Added:
> cfe/trunk/test/FixIt/fixit-missing-self-in-block.m
> cfe/trunk/test/SemaObjC/warn-implicit-self-in-block.m
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/test/SemaObjC/warn-retain-cycle.m
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=165133&r1=165132&r2=165133&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Oct 3 12:55:29 2012
> @@ -717,6 +717,10 @@
> "but may be unpredictably set to nil; assign to a strong variable to keep "
> "the object alive">,
> InGroup<ARCRepeatedUseOfWeak>, DefaultIgnore;
> +def warn_implicitly_retains_self : Warning <
> + "block implicitily retains 'self' - explicitly mention 'self' to indicate "
> + "this is intended behavior">,
> + InGroup<DiagGroup<"implicit-retain-self">>;
Typo: "implicitily". Also, I think we usually use a semicolon for the suggestion. (I can see why the fixit is on the warning in this case -- it doesn't change the behavior.)
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=165133&r1=165132&r2=165133&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Oct 3 12:55:29 2012
> @@ -2008,6 +2008,9 @@
> if (Level != DiagnosticsEngine::Ignored)
> getCurFunction()->recordUseOfWeak(Result);
> }
> + if (CurContext->isClosure())
> + Diag(Loc, diag::warn_implicitly_retains_self)
> + << FixItHint::CreateInsertion(Loc, "self->");
> }
>
> return Owned(Result);
>
> Added: cfe/trunk/test/FixIt/fixit-missing-self-in-block.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-missing-self-in-block.m?rev=165133&view=auto
> ==============================================================================
> --- cfe/trunk/test/FixIt/fixit-missing-self-in-block.m (added)
> +++ cfe/trunk/test/FixIt/fixit-missing-self-in-block.m Wed Oct 3 12:55:29 2012
> @@ -0,0 +1,20 @@
> +// RUN: cp %s %t
> +// RUN: %clang_cc1 -x objective-c -fobjc-arc -fblocks -fixit %t
> +// RUN: %clang_cc1 -x objective-c -fobjc-arc -fblocks -Werror %t
> +// rdar://11194874
> +
> + at interface Root @end
> +
> + at interface I : Root
> +{
> + int _bar;
> +}
> + at end
> +
> + at implementation I
> + - (void)foo{
> + ^{
> + _bar = 3;
> + }();
> + }
> + at end
>
> Added: cfe/trunk/test/SemaObjC/warn-implicit-self-in-block.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-implicit-self-in-block.m?rev=165133&view=auto
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/warn-implicit-self-in-block.m (added)
> +++ cfe/trunk/test/SemaObjC/warn-implicit-self-in-block.m Wed Oct 3 12:55:29 2012
> @@ -0,0 +1,18 @@
> +// RUN: %clang_cc1 -x objective-c -fobjc-arc -fblocks -verify %s
> +// rdar://11194874
> +
> + at interface Root @end
> +
> + at interface I : Root
> +{
> + int _bar;
> +}
> + at end
> +
> + at implementation I
> + - (void)foo{
> + ^{
> + _bar = 3; // expected-warning {{block implicitily retains 'self' - explicitly mention 'self' to indicate this is intended behavior}}
> + }();
> + }
> + at end
>
> Modified: cfe/trunk/test/SemaObjC/warn-retain-cycle.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-retain-cycle.m?rev=165133&r1=165132&r2=165133&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/warn-retain-cycle.m (original)
> +++ cfe/trunk/test/SemaObjC/warn-retain-cycle.m Wed Oct 3 12:55:29 2012
> @@ -1,4 +1,4 @@
> -// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -verify -Wno-objc-root-class %s
> +// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -verify -Wno-objc-root-class -Wno-implicit-retain-self %s
>
> void *_Block_copy(const void *block);
>
>
>
> _______________________________________________
> 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