]> granicus.if.org Git - clang/commitdiff
[arcmt] Allow -retain of an __unsafe_unretained receiver if the result gets used.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 14 Jul 2011 22:46:12 +0000 (22:46 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 14 Jul 2011 22:46:12 +0000 (22:46 +0000)
Keep the error if the result is unused. rdar://9552694.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135209 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ARCMigrate/TransRetainReleaseDealloc.cpp
test/ARCMT/checking.m

index d64250faf0206773cea4afef884f58e384a2797e..4eeb47437e3478bc951cdf3eb975df0339b4cc77 100644 (file)
@@ -70,7 +70,8 @@ public:
       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";
index 4dea3b71dff8a70542200aa2dde11798fa892c3b..7ab54ceb05d5457cbec2aa29c7d5cce5e443e76f 100644 (file)
@@ -39,6 +39,7 @@ struct UnsafeS {
 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'}}