[cfe-commits] r139706 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaObjCProperty.cpp test/SemaObjC/arc-retain-block-property.m test/SemaObjC/warn-retain-cycle.m

Fariborz Jahanian fjahanian at apple.com
Wed Sep 14 11:03:46 PDT 2011


Author: fjahanian
Date: Wed Sep 14 13:03:46 2011
New Revision: 139706

URL: http://llvm.org/viewvc/llvm-project?rev=139706&view=rev
Log:
objc-arc: warn when a 'retain' block property is
declared which does not force a 'copy' of the block literal
object. // rdar://9829425

Added:
    cfe/trunk/test/SemaObjC/arc-retain-block-property.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaObjCProperty.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=139706&r1=139705&r2=139706&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 14 13:03:46 2011
@@ -494,6 +494,9 @@
 def warn_objc_property_copy_missing_on_block : Warning<
     "'copy' attribute must be specified for the block property "
     "when -fobjc-gc-only is specified">;
+def warn_objc_property_retain_of_block : Warning<
+    "retain'ed block property does not copy the block "
+    "- use copy attribute instead">;
 def warn_atomic_property_rule : Warning<
   "writable atomic property %0 cannot pair a synthesized setter/getter "
   "with a user defined setter/getter">;

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=139706&r1=139705&r2=139706&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Wed Sep 14 13:03:46 2011
@@ -1701,7 +1701,7 @@
            (Attributes & ObjCDeclSpec::DQ_PR_weak)) {
       Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
         << "retain" << "weak";
-      Attributes &= ~ObjCDeclSpec::DQ_PR_weak;
+      Attributes &= ~ObjCDeclSpec::DQ_PR_retain;
   }
   else if ((Attributes & ObjCDeclSpec::DQ_PR_strong) &&
            (Attributes & ObjCDeclSpec::DQ_PR_weak)) {
@@ -1743,4 +1743,10 @@
       && getLangOptions().getGC() == LangOptions::GCOnly
       && PropertyTy->isBlockPointerType())
     Diag(Loc, diag::warn_objc_property_copy_missing_on_block);
+  else if (getLangOptions().ObjCAutoRefCount &&
+           (Attributes & ObjCDeclSpec::DQ_PR_retain) &&
+           !(Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
+           !(Attributes & ObjCDeclSpec::DQ_PR_strong) &&
+           PropertyTy->isBlockPointerType())
+      Diag(Loc, diag::warn_objc_property_retain_of_block);
 }

Added: cfe/trunk/test/SemaObjC/arc-retain-block-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-retain-block-property.m?rev=139706&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/arc-retain-block-property.m (added)
+++ cfe/trunk/test/SemaObjC/arc-retain-block-property.m Wed Sep 14 13:03:46 2011
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -fobjc-nonfragile-abi -verify %s
+// rdar://9829425
+
+extern void doSomething();
+
+ at interface Test
+{
+ at public
+  void (^aBlock)(void);
+}
+ at property (retain) void (^aBlock)(void); // expected-warning {{retain'ed block property does not copy the block - use copy attribute instead}}
+ at property (weak, retain) void (^aBlockW)(void); // expected-error {{property attributes 'retain' and 'weak' are mutually exclusive}} 
+ at property (strong, retain) void (^aBlockS)(void); // OK
+ at property (readonly, retain) void (^aBlockR)(void); // OK
+ at property (copy, retain) void (^aBlockC)(void); // expected-error {{property attributes 'copy' and 'retain' are mutually exclusive}}
+ at property (assign, retain) void (^aBlockA)(void); // expected-error {{property attributes 'assign' and 'retain' are mutually exclusive}}
+ at end
+
+ at implementation Test
+ at synthesize aBlock;
+ at dynamic aBlockW, aBlockS, aBlockR, aBlockC, aBlockA;
+ at end
+
+int main() {
+  Test *t;
+  t.aBlock = ^{ doSomething(); };
+  t.aBlockW = ^{ doSomething(); };
+  t.aBlockS = ^{ doSomething(); };
+}
+

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=139706&r1=139705&r2=139706&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-retain-cycle.m (original)
+++ cfe/trunk/test/SemaObjC/warn-retain-cycle.m Wed Sep 14 13:03:46 2011
@@ -27,7 +27,7 @@
 }
 
 @interface BlockOwner
- at property (retain) void (^strong)(void);
+ at property (retain) void (^strong)(void); // expected-warning {{retain'ed block property does not copy the block - use copy attribute instead}}
 @end
 
 @interface Test1 {





More information about the cfe-commits mailing list