[cfe-commits] r135301 - in /cfe/trunk: lib/ARCMigrate/TransRetainReleaseDealloc.cpp test/ARCMT/releases.m test/ARCMT/releases.m.result
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Jul 15 14:11:24 PDT 2011
Author: akirtzidis
Date: Fri Jul 15 16:11:23 2011
New Revision: 135301
URL: http://llvm.org/viewvc/llvm-project?rev=135301&view=rev
Log:
[arcmt] For:
id x = ...
@try {
...
} @finally {
[x release];
}
Migrator will drop the release. It's better to change it to "x = 0" in a @finally to avoid leak when exception is thrown.
rdar://9398256
Modified:
cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
cfe/trunk/test/ARCMT/releases.m
cfe/trunk/test/ARCMT/releases.m.result
Modified: cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp?rev=135301&r1=135300&r2=135301&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp Fri Jul 15 16:11:23 2011
@@ -97,10 +97,7 @@
return true;
case ObjCMessageExpr::SuperInstance: {
Transaction Trans(Pass.TA);
- Pass.TA.clearDiagnostic(diag::err_arc_illegal_explicit_message,
- diag::err_unavailable,
- diag::err_unavailable_message,
- E->getSuperLoc());
+ clearDiagnostics(E->getSuperLoc());
if (tryRemoving(E))
return true;
Pass.TA.replace(E->getSourceRange(), "self");
@@ -114,10 +111,17 @@
if (!rec) return true;
Transaction Trans(Pass.TA);
- Pass.TA.clearDiagnostic(diag::err_arc_illegal_explicit_message,
- diag::err_unavailable,
- diag::err_unavailable_message,
- rec->getExprLoc());
+ clearDiagnostics(rec->getExprLoc());
+
+ if (E->getMethodFamily() == OMF_release &&
+ isRemovable(E) && isInAtFinally(E)) {
+ // Change the -release to "receiver = 0" in a finally to avoid a leak
+ // when an exception is thrown.
+ Pass.TA.replace(E->getSourceRange(), rec->getSourceRange());
+ Pass.TA.insertAfterToken(rec->getLocEnd(), " = 0");
+ return true;
+ }
+
if (!hasSideEffects(E, Pass.Ctx)) {
if (tryRemoving(E))
return true;
@@ -128,6 +132,25 @@
}
private:
+ void clearDiagnostics(SourceLocation loc) const {
+ Pass.TA.clearDiagnostic(diag::err_arc_illegal_explicit_message,
+ diag::err_unavailable,
+ diag::err_unavailable_message,
+ loc);
+ }
+
+ bool isInAtFinally(Expr *E) const {
+ assert(E);
+ Stmt *S = E;
+ while (S) {
+ if (isa<ObjCAtFinallyStmt>(S))
+ return true;
+ S = StmtMap->getParent(S);
+ }
+
+ return false;
+ }
+
bool isRemovable(Expr *E) const {
return Removables.count(E);
}
Modified: cfe/trunk/test/ARCMT/releases.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/releases.m?rev=135301&r1=135300&r2=135301&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/releases.m (original)
+++ cfe/trunk/test/ARCMT/releases.m Fri Jul 15 16:11:23 2011
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fobjc-nonfragile-abi -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
-// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fblocks -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-exceptions -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-exceptions -fblocks -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t
// RUN: diff %t %s.result
typedef int BOOL;
@@ -36,6 +36,11 @@
[IhaveSideEffect() release];
[x release], x = 0;
+
+ @try {
+ } @finally {
+ [x release];
+ }
}
@end
Modified: cfe/trunk/test/ARCMT/releases.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/releases.m.result?rev=135301&r1=135300&r2=135301&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/releases.m.result (original)
+++ cfe/trunk/test/ARCMT/releases.m.result Fri Jul 15 16:11:23 2011
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fobjc-nonfragile-abi -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
-// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fblocks -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-exceptions -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-exceptions -fblocks -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t
// RUN: diff %t %s.result
typedef int BOOL;
@@ -34,6 +34,11 @@
IhaveSideEffect();
x = 0;
+
+ @try {
+ } @finally {
+ x = 0;
+ }
}
@end
More information about the cfe-commits
mailing list