diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-05-21 17:48:31 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-05-21 17:48:31 +0000 |
commit | 5a42a0292ad4d11ccf0ae9d06f6c15c3c811adfd (patch) | |
tree | a5bd317482fb3f301a889a09c4992cb9f40682f6 | |
parent | 5bf0e3522fac400cf7bf49a775554f0fc942b336 (diff) |
[arcmt] Revert r156999 "Remove the "it is not safe to remove an unused 'autorelease' message" ARC
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
-rw-r--r-- | lib/ARCMigrate/TransRetainReleaseDealloc.cpp | 11 | ||||
-rw-r--r-- | test/ARCMT/checking.m | 3 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/ARCMigrate/TransRetainReleaseDealloc.cpp b/lib/ARCMigrate/TransRetainReleaseDealloc.cpp index 976c097356..11a6553341 100644 --- a/lib/ARCMigrate/TransRetainReleaseDealloc.cpp +++ b/lib/ARCMigrate/TransRetainReleaseDealloc.cpp @@ -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) diff --git a/test/ARCMT/checking.m b/test/ARCMT/checking.m index 73eba9fc7b..cf7161187f 100644 --- a/test/ARCMT/checking.m +++ b/test/ARCMT/checking.m @@ -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}} \ |