[cfe-commits] r135209 - in /cfe/trunk: lib/ARCMigrate/TransRetainReleaseDealloc.cpp test/ARCMT/checking.m

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Jul 14 15:46:12 PDT 2011


Author: akirtzidis
Date: Thu Jul 14 17:46:12 2011
New Revision: 135209

URL: http://llvm.org/viewvc/llvm-project?rev=135209&view=rev
Log:
[arcmt] Allow -retain of an __unsafe_unretained receiver if the result gets used.
Keep the error if the result is unused. rdar://9552694.

Modified:
    cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
    cfe/trunk/test/ARCMT/checking.m

Modified: cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp?rev=135209&r1=135208&r2=135209&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp Thu Jul 14 17:46:12 2011
@@ -70,7 +70,8 @@
       if (E->getReceiverKind() == ObjCMessageExpr::Instance)
         if (Expr *rec = E->getInstanceReceiver()) {
           rec = rec->IgnoreParenImpCasts();
-          if (rec->getType().getObjCLifetime() == Qualifiers::OCL_ExplicitNone){
+          if (rec->getType().getObjCLifetime() == Qualifiers::OCL_ExplicitNone &&
+              (E->getMethodFamily() != OMF_retain || isRemovable(E))) {
             std::string err = "it is not safe to remove '";
             err += E->getSelector().getAsString() + "' message on "
                 "an __unsafe_unretained type";

Modified: cfe/trunk/test/ARCMT/checking.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/checking.m?rev=135209&r1=135208&r2=135209&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/checking.m (original)
+++ cfe/trunk/test/ARCMT/checking.m Thu Jul 14 17:46:12 2011
@@ -39,6 +39,7 @@
 void test1(A *a, BOOL b, struct UnsafeS *unsafeS) {
   [unsafeS->unsafeObj retain]; // expected-error {{it is not safe to remove 'retain' message on an __unsafe_unretained type}} \
                                // expected-error {{ARC forbids explicit message send}}
+  id foo = [unsafeS->unsafeObj retain]; // no warning.
   [a dealloc];
   [a retain];
   [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}}





More information about the cfe-commits mailing list