class AutoreleasePoolRewriter
: public RecursiveASTVisitor<AutoreleasePoolRewriter> {
public:
- AutoreleasePoolRewriter(Decl *D, MigrationPass &pass)
- : Dcl(D), Body(0), Pass(pass) {
+ AutoreleasePoolRewriter(MigrationPass &pass)
+ : Body(0), Pass(pass) {
PoolII = &pass.Ctx.Idents.get("NSAutoreleasePool");
DrainSel = pass.Ctx.Selectors.getNullarySelector(
&pass.Ctx.Idents.get("drain"));
return S;
}
- Decl *Dcl;
Stmt *Body;
MigrationPass &Pass;
class RetainReleaseDeallocRemover :
public RecursiveASTVisitor<RetainReleaseDeallocRemover> {
- Decl *Dcl;
Stmt *Body;
MigrationPass &Pass;
llvm::OwningPtr<ParentMap> StmtMap;
public:
- RetainReleaseDeallocRemover(Decl *D, MigrationPass &pass)
- : Dcl(D), Body(0), Pass(pass) { }
+ RetainReleaseDeallocRemover(MigrationPass &pass)
+ : Body(0), Pass(pass) { }
void transformBody(Stmt *body) {
Body = body;
namespace {
class UnusedInitRewriter : public RecursiveASTVisitor<UnusedInitRewriter> {
- Decl *Dcl;
Stmt *Body;
MigrationPass &Pass;
ExprSet Removables;
public:
- UnusedInitRewriter(Decl *D, MigrationPass &pass)
- : Dcl(D), Body(0), Pass(pass) { }
+ UnusedInitRewriter(MigrationPass &pass)
+ : Body(0), Pass(pass) { }
void transformBody(Stmt *body) {
Body = body;
public:
BodyTransform(MigrationPass &pass) : Pass(pass) { }
- void handleBody(Decl *D) {
- Stmt *body = D->getBody();
- if (body) {
- BODY_TRANS(D, Pass).transformBody(body);
- }
- }
-
- bool TraverseBlockDecl(BlockDecl *D) {
- handleBody(D);
- return true;
- }
- bool TraverseObjCMethodDecl(ObjCMethodDecl *D) {
- if (D->isThisDeclarationADefinition())
- handleBody(D);
- return true;
- }
- bool TraverseFunctionDecl(FunctionDecl *D) {
- if (D->isThisDeclarationADefinition())
- handleBody(D);
+ bool TraverseStmt(Stmt *rootS) {
+ BODY_TRANS(Pass).transformBody(rootS);
return true;
}
};
--- /dev/null
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c++ %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c++ %s > %t
+// RUN: diff %t %s.result
+
+#include "Common.h"
+
+@interface NSString : NSObject
++(id)string;
+@end
+
+struct foo {
+ NSString *s;
+ foo(NSString *s): s([s retain]){
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ [[NSString string] autorelease];
+ [pool drain];
+ }
+ ~foo(){ [s release]; }
+private:
+ foo(foo const &);
+ foo &operator=(foo const &);
+};
+
+int main(){
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+
+ foo f([[NSString string] autorelease]);
+
+ [pool drain];
+ return 0;
+}
--- /dev/null
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c++ %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c++ %s > %t
+// RUN: diff %t %s.result
+
+#include "Common.h"
+
+@interface NSString : NSObject
++(id)string;
+@end
+
+struct foo {
+ NSString *s;
+ foo(NSString *s): s(s){
+ @autoreleasepool {
+ [NSString string];
+ }
+ }
+ ~foo(){ s; }
+private:
+ foo(foo const &);
+ foo &operator=(foo const &);
+};
+
+int main(){
+ @autoreleasepool {
+
+ foo f([NSString string]);
+
+ }
+ return 0;
+}