hanchenye-llvm-project/clang/test/ARCMT/atautorelease.m

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.3 KiB
Mathematica
Raw Normal View History

// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -fobjc-arc -x objective-c %s.result
// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s > %t
// RUN: diff %t %s.result
#include "Common.h"
void NSLog(id, ...);
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
if (argc) {
NSAutoreleasePool * pool = [NSAutoreleasePool new];
NSLog(@"%s", "YES");
[pool drain];
}
[pool drain];
NSAutoreleasePool * pool1 = [[NSAutoreleasePool alloc] init];
NSLog(@"%s", "YES");
[pool1 release];
return 0;
}
void f(void) {
NSAutoreleasePool *pool1;
pool1 = [NSAutoreleasePool new];
int x = 4;
NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init];
++x;
[pool2 drain];
[pool1 release];
}
int UIApplicationMain(int argc, char *argv[]);
int main2(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int result = UIApplicationMain(argc, argv);
[pool release];
return result;
}
[arcmt] More automatic transformations and safety improvements; rdar://9615812 : - Replace calling -zone with 'nil'. -zone is obsolete in ARC. - Allow removing retain/release on a static global var. - Fix assertion hit when scanning for name references outside a NSAutoreleasePool scope. - Automatically add bridged casts for results of objc method calls and when calling CFRetain, for example: NSString *s; CFStringRef ref = [s string]; -> CFStringRef ref = (__bridge CFStringRef)([s string]); ref = s.string; -> ref = (__bridge CFStringRef)(s.string); ref = [NSString new]; -> ref = (__bridge_retained CFStringRef)([NSString new]); ref = [s newString]; -> ref = (__bridge_retained CFStringRef)([s newString]); ref = [[NSString alloc] init]; -> ref = (__bridge_retained CFStringRef)([[NSString alloc] init]); ref = [[s string] retain]; -> ref = (__bridge_retained CFStringRef)([s string]); ref = CFRetain(s); -> ref = (__bridge_retained CFTypeRef)(s); ref = [s retain]; -> ref = (__bridge_retained CFStringRef)(s); - Emit migrator error when trying to cast to CF type the result of autorelease/release: for CFStringRef f3() { return (CFStringRef)[[[NSString alloc] init] autorelease]; } emits: t.m:12:10: error: [rewriter] it is not safe to cast to 'CFStringRef' the result of 'autorelease' message; a __bridge cast may result in a pointer to a destroyed object and a __bridge_retained may leak the object return (CFStringRef)[[[NSString alloc] init] autorelease]; ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ t.m:12:3: note: [rewriter] remove the cast and change return type of function to 'NSString *' to have the object automatically autoreleased return (CFStringRef)[[[NSString alloc] init] autorelease]; ^ - Before changing attributes to weak/unsafe_unretained, check if the backing ivar is set to a +1 object, in which case use 'strong' instead. llvm-svn: 136208
2011-07-27 13:28:18 +08:00
@interface Foo : NSObject
@property (assign) id myProp;
@end
@implementation Foo
@synthesize myProp;
-(void)test:(id)p {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[pool drain];
self.myProp = p;
}
@end