diff options
Diffstat (limited to 'test/ARCMT')
-rw-r--r-- | test/ARCMT/Common.h | 6 | ||||
-rw-r--r-- | test/ARCMT/autoreleases.m | 10 | ||||
-rw-r--r-- | test/ARCMT/autoreleases.m.result | 8 | ||||
-rw-r--r-- | test/ARCMT/block_copy_release.m | 17 | ||||
-rw-r--r-- | test/ARCMT/block_copy_release.m.result | 15 | ||||
-rw-r--r-- | test/ARCMT/check-with-pch.m | 16 | ||||
-rw-r--r-- | test/ARCMT/checking.m | 8 | ||||
-rw-r--r-- | test/ARCMT/migrate-with-pch.m | 7 | ||||
-rw-r--r-- | test/ARCMT/nonobjc-to-objc-cast-2.m | 9 | ||||
-rw-r--r-- | test/ARCMT/objcmt-subscripting-literals-in-arc.m | 2 | ||||
-rw-r--r-- | test/ARCMT/objcmt-subscripting-literals-in-arc.m.result | 2 | ||||
-rw-r--r-- | test/ARCMT/objcmt-subscripting-literals.m | 4 | ||||
-rw-r--r-- | test/ARCMT/objcmt-subscripting-literals.m.result | 4 | ||||
-rw-r--r-- | test/ARCMT/objcmt-with-pch.m | 16 | ||||
-rw-r--r-- | test/ARCMT/objcmt-with-pch.m.result | 16 | ||||
-rw-r--r-- | test/ARCMT/protected-scope.m | 37 | ||||
-rw-r--r-- | test/ARCMT/protected-scope.m.result | 39 |
17 files changed, 212 insertions, 4 deletions
diff --git a/test/ARCMT/Common.h b/test/ARCMT/Common.h index ed48949..b388eca 100644 --- a/test/ARCMT/Common.h +++ b/test/ARCMT/Common.h @@ -10,6 +10,7 @@ #define NS_INLINE static __inline__ __attribute__((always_inline)) #define nil ((void*) 0) +#define NULL ((void*)0) typedef int BOOL; typedef unsigned NSUInteger; @@ -102,3 +103,8 @@ NS_INLINE id CFBridgingRelease(CFTypeRef CF_CONSUMED X) { } #endif + +void *_Block_copy(const void *aBlock); +void _Block_release(const void *aBlock); +#define Block_copy(...) ((__typeof(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__))) +#define Block_release(...) _Block_release((const void *)(__VA_ARGS__)) diff --git a/test/ARCMT/autoreleases.m b/test/ARCMT/autoreleases.m index a131bc5..543bcf6 100644 --- a/test/ARCMT/autoreleases.m +++ b/test/ARCMT/autoreleases.m @@ -64,3 +64,13 @@ void test(A *prevVal, A *newVal) { [prevVal autorelease]; prevVal = [newVal retain]; } + +id test2(A* val) { + [[val retain] autorelease]; + return val; +} + +id test3() { + id a = [[A alloc] init]; + [a autorelease]; +} diff --git a/test/ARCMT/autoreleases.m.result b/test/ARCMT/autoreleases.m.result index 6593fc9..9b71ff8 100644 --- a/test/ARCMT/autoreleases.m.result +++ b/test/ARCMT/autoreleases.m.result @@ -60,3 +60,11 @@ int main (int argc, const char * argv[]) { void test(A *prevVal, A *newVal) { prevVal = newVal; } + +id test2(A* val) { + return val; +} + +id test3() { + id a = [[A alloc] init]; +} diff --git a/test/ARCMT/block_copy_release.m b/test/ARCMT/block_copy_release.m new file mode 100644 index 0000000..ae3b826 --- /dev/null +++ b/test/ARCMT/block_copy_release.m @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fblocks -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +typedef void (^blk)(int); + +void func(blk b) { + blk c = Block_copy(b); + Block_release(c); +} + +void func2(id b) { + id c = Block_copy(b); + Block_release(c); +} diff --git a/test/ARCMT/block_copy_release.m.result b/test/ARCMT/block_copy_release.m.result new file mode 100644 index 0000000..b292b64 --- /dev/null +++ b/test/ARCMT/block_copy_release.m.result @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fblocks -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +typedef void (^blk)(int); + +void func(blk b) { + blk c = [b copy]; +} + +void func2(id b) { + id c = [b copy]; +} diff --git a/test/ARCMT/check-with-pch.m b/test/ARCMT/check-with-pch.m new file mode 100644 index 0000000..7867002 --- /dev/null +++ b/test/ARCMT/check-with-pch.m @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -x objective-c -triple x86_64-apple-darwin10 %S/Common.h -emit-pch -o %t.pch +// RUN: %clang_cc1 -include-pch %t.pch -arcmt-check -verify -triple x86_64-apple-darwin10 -fblocks -Werror %s +// DISABLE: mingw32 + +// rdar://9601437 +@interface I9601437 { + __unsafe_unretained id x; +} +-(void)Meth; +@end + +@implementation I9601437 +-(void)Meth { + self->x = [NSObject new]; // expected-error {{assigning retained object}} +} +@end diff --git a/test/ARCMT/checking.m b/test/ARCMT/checking.m index 3ad911e..b06f4a7 100644 --- a/test/ARCMT/checking.m +++ b/test/ARCMT/checking.m @@ -117,7 +117,7 @@ void test1(A *a, BOOL b, struct UnsafeS *unsafeS) { } struct S { - A* a; // expected-error {{ARC forbids Objective-C objects in structs or unions}} + A* a; // expected-error {{ARC forbids Objective-C objects in struct}} }; @interface B @@ -178,13 +178,13 @@ void test12(id collection) { } void test6(unsigned cond) { - // FIXME: Fix this automatically ? switch (cond) { case 0: ; id x; // expected-note {{jump bypasses initialization of retaining variable}} case 1: // expected-error {{switch case is in protected scope}} + x = 0; break; } } @@ -293,10 +293,10 @@ id test9(Test9 *v) { void rdar9491791(int p) { switch (p) { case 3:; - NSObject *o = [[NSObject alloc] init]; // expected-note {{jump bypasses initialization of retaining variable}} + NSObject *o = [[NSObject alloc] init]; [o release]; break; - default: // expected-error {{switch case is in protected scope}} + default: break; } } diff --git a/test/ARCMT/migrate-with-pch.m b/test/ARCMT/migrate-with-pch.m new file mode 100644 index 0000000..7dca8be --- /dev/null +++ b/test/ARCMT/migrate-with-pch.m @@ -0,0 +1,7 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -x objective-c %S/Common.h -emit-pch -o %t.pch +// RUN: %clang_cc1 -arcmt-migrate -mt-migrate-directory %t %S/Inputs/test1.m.in -x objective-c -include-pch %t.pch +// RUN: %clang_cc1 -arcmt-migrate -mt-migrate-directory %t %S/Inputs/test2.m.in -x objective-c -include-pch %t.pch +// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %S/Inputs/test1.m.in.result %S/Inputs/test2.m.in.result %S/Inputs/test.h.result +// RUN: rm -rf %t +// DISABLE: mingw32 diff --git a/test/ARCMT/nonobjc-to-objc-cast-2.m b/test/ARCMT/nonobjc-to-objc-cast-2.m index 80d694e..e554c7d 100644 --- a/test/ARCMT/nonobjc-to-objc-cast-2.m +++ b/test/ARCMT/nonobjc-to-objc-cast-2.m @@ -54,3 +54,12 @@ CFStringRef f3() { return (CFStringRef)[[[NSString alloc] init] autorelease]; // expected-error {{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}} \ // expected-note {{remove the cast and change return type of function to 'NSString *' to have the object automatically autoreleased}} } + +extern void NSLog(NSString *format, ...); + +// rdar://13192395 +void f4(NSString *s) { + NSLog(@"%@", (CFStringRef)s); // expected-error {{cast of Objective-C pointer type 'NSString *' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast}} \ + // expected-note{{use __bridge to convert directly (no change in ownership)}} \ + // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFStringRef' (aka 'const struct __CFString *')}} +} diff --git a/test/ARCMT/objcmt-subscripting-literals-in-arc.m b/test/ARCMT/objcmt-subscripting-literals-in-arc.m index 4d94162..1f56f4a 100644 --- a/test/ARCMT/objcmt-subscripting-literals-in-arc.m +++ b/test/ARCMT/objcmt-subscripting-literals-in-arc.m @@ -101,6 +101,8 @@ typedef const struct __CFString * CFStringRef; dict = [NSDictionary dictionaryWithObjectsAndKeys: @"value1", @"key1", @"value2", @"key2", nil]; dict = [[NSDictionary alloc] initWithObjectsAndKeys: @"value1", @"key1", @"value2", @"key2", nil]; + dict = [[NSDictionary alloc] initWithObjects:[[NSArray alloc] initWithObjects:@"1", @"2", nil] forKeys:[NSArray arrayWithObjects:@"A", @"B", nil]]; + NSNumber *n = [[NSNumber alloc] initWithInt:2]; } @end diff --git a/test/ARCMT/objcmt-subscripting-literals-in-arc.m.result b/test/ARCMT/objcmt-subscripting-literals-in-arc.m.result index 6f7a723..d974a25 100644 --- a/test/ARCMT/objcmt-subscripting-literals-in-arc.m.result +++ b/test/ARCMT/objcmt-subscripting-literals-in-arc.m.result @@ -101,6 +101,8 @@ typedef const struct __CFString * CFStringRef; dict = @{@"key1": @"value1", @"key2": @"value2"}; dict = @{@"key1": @"value1", @"key2": @"value2"}; + dict = @{@"A": @"1", @"B": @"2"}; + NSNumber *n = @2; } @end diff --git a/test/ARCMT/objcmt-subscripting-literals.m b/test/ARCMT/objcmt-subscripting-literals.m index 0174fcf..8cef091 100644 --- a/test/ARCMT/objcmt-subscripting-literals.m +++ b/test/ARCMT/objcmt-subscripting-literals.m @@ -153,6 +153,10 @@ typedef const struct __CFString * CFStringRef; void *hd; o = [(NSArray*)hd objectAtIndex:2]; o = [ivarArr objectAtIndex:2]; + + dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"1", [NSArray array], nil] forKeys:[NSArray arrayWithObjects:@"A", [arr objectAtIndex:2], nil]]; + dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"1", @"2", nil] forKeys:arr]; + dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"1", @"2", nil] forKeys:@[@"A", @"B"]]; } @end diff --git a/test/ARCMT/objcmt-subscripting-literals.m.result b/test/ARCMT/objcmt-subscripting-literals.m.result index 9975996..0ca6dca 100644 --- a/test/ARCMT/objcmt-subscripting-literals.m.result +++ b/test/ARCMT/objcmt-subscripting-literals.m.result @@ -153,6 +153,10 @@ typedef const struct __CFString * CFStringRef; void *hd; o = ((NSArray*)hd)[2]; o = ivarArr[2]; + + dict = @{@"A": @"1", arr[2]: @[]}; + dict = [NSDictionary dictionaryWithObjects:@[@"1", @"2"] forKeys:arr]; + dict = @{@"A": @"1", @"B": @"2"}; } @end diff --git a/test/ARCMT/objcmt-with-pch.m b/test/ARCMT/objcmt-with-pch.m new file mode 100644 index 0000000..fac42c8 --- /dev/null +++ b/test/ARCMT/objcmt-with-pch.m @@ -0,0 +1,16 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c %S/Common.h -emit-pch -o %t.pch +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -include-pch %t.pch +// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s.result -include-pch %t.pch + +@interface NSNumber : NSObject +@end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithInt:(int)value; +@end + +void foo() { + NSNumber *n = [NSNumber numberWithInt:1]; +} diff --git a/test/ARCMT/objcmt-with-pch.m.result b/test/ARCMT/objcmt-with-pch.m.result new file mode 100644 index 0000000..04eadc9 --- /dev/null +++ b/test/ARCMT/objcmt-with-pch.m.result @@ -0,0 +1,16 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c %S/Common.h -emit-pch -o %t.pch +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -include-pch %t.pch +// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s.result -include-pch %t.pch + +@interface NSNumber : NSObject +@end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithInt:(int)value; +@end + +void foo() { + NSNumber *n = @1; +} diff --git a/test/ARCMT/protected-scope.m b/test/ARCMT/protected-scope.m new file mode 100644 index 0000000..8aece44 --- /dev/null +++ b/test/ARCMT/protected-scope.m @@ -0,0 +1,37 @@ +// 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 +// DISABLE: mingw32 + +#include "Common.h" + +void test(id p, int x) { + int v; + switch(x) { + case 0: + v++; + id w1 = p; + id w2 = p; + break; + case 1: + v++; + id w3 = p; + break; + case 2: + case 3: + break; + default: + break; + } +} + +void test2(int p) { + switch (p) { + case 3:; + NSObject *o = [[NSObject alloc] init]; + [o release]; + break; + default: + break; + } +} diff --git a/test/ARCMT/protected-scope.m.result b/test/ARCMT/protected-scope.m.result new file mode 100644 index 0000000..f385d88 --- /dev/null +++ b/test/ARCMT/protected-scope.m.result @@ -0,0 +1,39 @@ +// 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 +// DISABLE: mingw32 + +#include "Common.h" + +void test(id p, int x) { + int v; + switch(x) { + case 0: { + v++; + id w1 = p; + id w2 = p; + break; + } + case 1: { + v++; + id w3 = p; + break; + } + case 2: + case 3: + break; + default: + break; + } +} + +void test2(int p) { + switch (p) { + case 3: {; + NSObject *o = [[NSObject alloc] init]; + break; + } + default: + break; + } +} |