]> granicus.if.org Git - clang/commitdiff
[arcmt] Revert r156999 "Remove the "it is not safe to remove an unused 'autorelease...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 21 May 2012 17:48:31 +0000 (17:48 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 21 May 2012 17:48:31 +0000 (17:48 +0000)
migration error".

Per feedback from John this is useful to have in general.

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

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

index 976c097356e2ddbbbc0c8606d9fd0129dd47be9c..11a6553341442c65af572917a053fb4b254f1456 100644 (file)
@@ -63,6 +63,17 @@ public:
         break;
       return true;
     case OMF_autorelease:
+      if (isRemovable(E)) {
+        // An unused autorelease is badness. If we remove it the receiver
+        // will likely die immediately while previously it was kept alive
+        // by the autorelease pool. This is bad practice in general, leave it
+        // and emit an error to force the user to restructure his code.
+        Pass.TA.reportError("it is not safe to remove an unused 'autorelease' "
+            "message; its receiver may be destroyed immediately",
+            E->getLocStart(), E->getSourceRange());
+        return true;
+      }
+      // Pass through.
     case OMF_retain:
     case OMF_release:
       if (E->getReceiverKind() == ObjCMessageExpr::Instance)
index 73eba9fc7bcf6610e37295aadd0544650da57f6c..cf7161187fb16cf92ed6064eee432d12f0c318c2 100644 (file)
@@ -89,7 +89,8 @@ void test1(A *a, BOOL b, struct UnsafeS *unsafeS) {
   [a retain];
   [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}}
   [a release];
-  [a autorelease];
+  [a autorelease]; // expected-error {{it is not safe to remove an unused 'autorelease' message; its receiver may be destroyed immediately}} \
+                   // expected-error {{ARC forbids explicit message send}}
 
   CFStringRef cfstr;
   NSString *str = (NSString *)cfstr; // expected-error {{cast of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast}} \