diff options
Diffstat (limited to 'test/ARCMT')
25 files changed, 987 insertions, 120 deletions
diff --git a/test/ARCMT/Common.h b/test/ARCMT/Common.h index 16856ed..ed48949 100644 --- a/test/ARCMT/Common.h +++ b/test/ARCMT/Common.h @@ -6,6 +6,7 @@ #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained)) #define CF_CONSUMED __attribute__((cf_consumed)) +#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained)) #define NS_INLINE static __inline__ __attribute__((always_inline)) #define nil ((void*) 0) @@ -21,7 +22,7 @@ typedef struct _NSZone NSZone; typedef const void * CFTypeRef; CFTypeRef CFRetain(CFTypeRef cf); -id CFBridgingRelease(CFTypeRef CF_CONSUMED X); +CFTypeRef CFMakeCollectable(CFTypeRef cf) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; NS_INLINE NS_RETURNS_RETAINED id NSMakeCollectable(CFTypeRef CF_CONSUMED cf) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; @@ -68,3 +69,36 @@ typedef const void* objc_objectptr_t; extern __attribute__((ns_returns_retained)) id objc_retainedObject(objc_objectptr_t __attribute__((cf_consumed)) pointer); extern __attribute__((ns_returns_not_retained)) id objc_unretainedObject(objc_objectptr_t pointer); extern objc_objectptr_t objc_unretainedPointer(id object); + +#define dispatch_retain(object) ({ dispatch_object_t _o = (object); _dispatch_object_validate(_o); (void)[_o retain]; }) +#define dispatch_release(object) ({ dispatch_object_t _o = (object); _dispatch_object_validate(_o); [_o release]; }) +#define xpc_retain(object) ({ xpc_object_t _o = (object); _xpc_object_validate(_o); [_o retain]; }) +#define xpc_release(object) ({ xpc_object_t _o = (object); _xpc_object_validate(_o); [_o release]; }) + +typedef id dispatch_object_t; +typedef id xpc_object_t; + +void _dispatch_object_validate(dispatch_object_t object); +void _xpc_object_validate(xpc_object_t object); + +#if __has_feature(objc_arc) + +NS_INLINE CF_RETURNS_RETAINED CFTypeRef CFBridgingRetain(id X) { + return (__bridge_retained CFTypeRef)X; +} + +NS_INLINE id CFBridgingRelease(CFTypeRef CF_CONSUMED X) { + return (__bridge_transfer id)X; +} + +#else + +NS_INLINE CF_RETURNS_RETAINED CFTypeRef CFBridgingRetain(id X) { + return X ? CFRetain((CFTypeRef)X) : NULL; +} + +NS_INLINE id CFBridgingRelease(CFTypeRef CF_CONSUMED X) { + return [(id)CFMakeCollectable(X) autorelease]; +} + +#endif diff --git a/test/ARCMT/autoreleases.m b/test/ARCMT/autoreleases.m index 3acddb7..a131bc5 100644 --- a/test/ARCMT/autoreleases.m +++ b/test/ARCMT/autoreleases.m @@ -3,29 +3,21 @@ // RUN: diff %t %s.result // DISABLE: mingw32 -typedef unsigned char BOOL; +#include "Common.h" -@interface NSObject { - id isa; -} -+new; -+alloc; --init; --autorelease; -@end - -@interface NSAutoreleasePool : NSObject -- drain; -@end - @interface A : NSObject { @package id object; } @end -@interface B : NSObject +@interface B : NSObject { + id _prop; + xpc_object_t _xpc_prop; +} - (BOOL)containsSelf:(A*)a; +@property (retain) id prop; +@property (retain) xpc_object_t xpc_prop; @end @implementation A @@ -35,6 +27,26 @@ typedef unsigned char BOOL; - (BOOL)containsSelf:(A*)a { return a->object == self; } + +-(id) prop { + return _prop; +} +-(void) setProp:(id) newVal { + [_prop autorelease]; + _prop = [newVal retain]; +} +-(void) setProp2:(CFTypeRef) newVal { + [_prop autorelease]; + _prop = (id)CFRetain(newVal); +} + +-(id) xpc_prop { + return _xpc_prop; +} +-(void) setXpc_prop:(xpc_object_t) newVal { + [_xpc_prop autorelease]; + _xpc_prop = xpc_retain(newVal); +} @end void NSLog(id, ...); @@ -47,3 +59,8 @@ int main (int argc, const char * argv[]) { [pool drain]; return 0; } + +void test(A *prevVal, A *newVal) { + [prevVal autorelease]; + prevVal = [newVal retain]; +} diff --git a/test/ARCMT/autoreleases.m.result b/test/ARCMT/autoreleases.m.result index 49bc321..6593fc9 100644 --- a/test/ARCMT/autoreleases.m.result +++ b/test/ARCMT/autoreleases.m.result @@ -3,29 +3,21 @@ // RUN: diff %t %s.result // DISABLE: mingw32 -typedef unsigned char BOOL; +#include "Common.h" -@interface NSObject { - id isa; -} -+new; -+alloc; --init; --autorelease; -@end - -@interface NSAutoreleasePool : NSObject -- drain; -@end - @interface A : NSObject { @package id object; } @end -@interface B : NSObject +@interface B : NSObject { + id _prop; + xpc_object_t _xpc_prop; +} - (BOOL)containsSelf:(A*)a; +@property (strong) id prop; +@property (strong) xpc_object_t xpc_prop; @end @implementation A @@ -35,6 +27,23 @@ typedef unsigned char BOOL; - (BOOL)containsSelf:(A*)a { return a->object == self; } + +-(id) prop { + return _prop; +} +-(void) setProp:(id) newVal { + _prop = newVal; +} +-(void) setProp2:(CFTypeRef) newVal { + _prop = (id)CFBridgingRelease(CFRetain(newVal)); +} + +-(id) xpc_prop { + return _xpc_prop; +} +-(void) setXpc_prop:(xpc_object_t) newVal { + _xpc_prop = newVal; +} @end void NSLog(id, ...); @@ -47,3 +56,7 @@ int main (int argc, const char * argv[]) { } return 0; } + +void test(A *prevVal, A *newVal) { + prevVal = newVal; +} diff --git a/test/ARCMT/checking.m b/test/ARCMT/checking.m index cf71611..3ad911e 100644 --- a/test/ARCMT/checking.m +++ b/test/ARCMT/checking.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 %s +// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fblocks -Werror %s // DISABLE: mingw32 #if __has_feature(objc_arc) @@ -45,9 +45,9 @@ struct UnsafeS { }; @interface A : NSObject -- (id)retain; -- (id)retainCount; -- (id)autorelease; +- (id)retain; // expected-note {{declaration has been explicitly marked unavailable here}} +- (id)retainCount; // expected-note {{declaration has been explicitly marked unavailable here}} +- (id)autorelease; // expected-note 2 {{declaration has been explicitly marked unavailable here}} - (id)init; - (oneway void)release; - (void)dealloc; @@ -79,7 +79,8 @@ void test1(A *a, BOOL b, struct UnsafeS *unsafeS) { [a.delegate release]; // expected-error {{it is not safe to remove 'retain' message on the result of a 'delegate' message; the object that was passed to 'setDelegate:' may not be properly retained}} \ // expected-error {{ARC forbids explicit message send}} [unsafeS->unsafeObj retain]; // expected-error {{it is not safe to remove 'retain' message on an __unsafe_unretained type}} \ - // expected-error {{ARC forbids explicit message send}} + // expected-error {{ARC forbids explicit message send}} \ + // expected-error {{'retain' is unavailable}} id foo = [unsafeS->unsafeObj retain]; // no warning. [global_foo retain]; // expected-error {{it is not safe to remove 'retain' message on a global variable}} \ // expected-error {{ARC forbids explicit message send}} @@ -87,10 +88,16 @@ void test1(A *a, BOOL b, struct UnsafeS *unsafeS) { // expected-error {{ARC forbids explicit message send}} [a dealloc]; [a retain]; - [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}} + [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}} \ + // expected-error {{'retainCount' is unavailable}} [a release]; [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}} + // expected-error {{ARC forbids explicit message send}} \ + // expected-error {{'autorelease' is unavailable}} + [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}} \ + // expected-error {{'autorelease' is unavailable}} + a = 0; 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}} \ @@ -135,7 +142,7 @@ void rdar8861761() { - (void) noninit { self = 0; // expected-error {{cannot assign to 'self' outside of a method in the init family}} - for (id x in collection) { // expected-error {{use of undeclared identifier 'collection'}} + for (__strong id x in collection) { // expected-error {{use of undeclared identifier 'collection'}} x = 0; } } @@ -325,3 +332,13 @@ void rdar9504750(id p) { self->x = [NSObject new]; // expected-error {{assigning retained object}} } @end + +@interface Test10 : NSObject +@property (retain) id prop; +-(void)foo; +@end + +void test(Test10 *x) { + x.prop = ^{ [x foo]; }; // expected-warning {{likely to lead to a retain cycle}} \ + // expected-note {{retained by the captured object}} +} diff --git a/test/ARCMT/cxx-rewrite.mm.result b/test/ARCMT/cxx-rewrite.mm.result index a2dc9a5..7c944d5 100644 --- a/test/ARCMT/cxx-rewrite.mm.result +++ b/test/ARCMT/cxx-rewrite.mm.result @@ -16,7 +16,7 @@ struct foo { [NSString string]; } } - ~foo(){ s; } + ~foo(){ } private: foo(foo const &); foo &operator=(foo const &); diff --git a/test/ARCMT/dispatch.m b/test/ARCMT/dispatch.m index 75c4a83..58c7769 100644 --- a/test/ARCMT/dispatch.m +++ b/test/ARCMT/dispatch.m @@ -4,17 +4,6 @@ #include "Common.h" -#define dispatch_retain(object) ({ dispatch_object_t _o = (object); _dispatch_object_validate(_o); (void)[_o retain]; }) -#define dispatch_release(object) ({ dispatch_object_t _o = (object); _dispatch_object_validate(_o); [_o release]; }) -#define xpc_retain(object) ({ xpc_object_t _o = (object); _xpc_object_validate(_o); [_o retain]; }) -#define xpc_release(object) ({ xpc_object_t _o = (object); _xpc_object_validate(_o); [_o release]; }) - -typedef id dispatch_object_t; -typedef id xpc_object_t; - -void _dispatch_object_validate(dispatch_object_t object); -void _xpc_object_validate(xpc_object_t object); - dispatch_object_t getme(void); void func(dispatch_object_t o) { diff --git a/test/ARCMT/dispatch.m.result b/test/ARCMT/dispatch.m.result index e897672..55b6558 100644 --- a/test/ARCMT/dispatch.m.result +++ b/test/ARCMT/dispatch.m.result @@ -4,17 +4,6 @@ #include "Common.h" -#define dispatch_retain(object) ({ dispatch_object_t _o = (object); _dispatch_object_validate(_o); (void)[_o retain]; }) -#define dispatch_release(object) ({ dispatch_object_t _o = (object); _dispatch_object_validate(_o); [_o release]; }) -#define xpc_retain(object) ({ xpc_object_t _o = (object); _xpc_object_validate(_o); [_o retain]; }) -#define xpc_release(object) ({ xpc_object_t _o = (object); _xpc_object_validate(_o); [_o release]; }) - -typedef id dispatch_object_t; -typedef id xpc_object_t; - -void _dispatch_object_validate(dispatch_object_t object); -void _xpc_object_validate(xpc_object_t object); - dispatch_object_t getme(void); void func(dispatch_object_t o) { diff --git a/test/ARCMT/nonobjc-to-objc-cast-2.m b/test/ARCMT/nonobjc-to-objc-cast-2.m index 1ec0089..80d694e 100644 --- a/test/ARCMT/nonobjc-to-objc-cast-2.m +++ b/test/ARCMT/nonobjc-to-objc-cast-2.m @@ -3,16 +3,37 @@ #include "Common.h" -@interface NSString : NSObject --(id)string; --(id)newString; -@end - typedef const struct __CFString * CFStringRef; typedef const void * CFTypeRef; CFTypeRef CFBridgingRetain(id X); id CFBridgingRelease(CFTypeRef); +struct StrS { + CFStringRef sref_member; +}; + +@interface NSString : NSObject { + CFStringRef sref; + struct StrS *strS; +} +-(id)string; +-(id)newString; +@end + +@implementation NSString +-(id)string { + if (0) + return sref; + else + return strS->sref_member; +} +-(id)newString { + return sref; // expected-error {{implicit conversion of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'id' requires a bridged cast}} \ + // expected-note{{use __bridge to convert directly (no change in ownership)}} \ + // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}} +} +@end + void f(BOOL b) { 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}} \ diff --git a/test/ARCMT/nonobjc-to-objc-cast.m b/test/ARCMT/nonobjc-to-objc-cast.m index fcdcd89..55b6655 100644 --- a/test/ARCMT/nonobjc-to-objc-cast.m +++ b/test/ARCMT/nonobjc-to-objc-cast.m @@ -5,11 +5,6 @@ #include "Common.h" -@interface NSString : NSObject --(id)string; --(id)newString; -@end - typedef const struct __CFString * CFStringRef; extern const CFStringRef kUTTypePlainText; extern const CFStringRef kUTTypeRTF; @@ -21,6 +16,18 @@ extern const CFAllocatorRef kCFAllocatorDefault; extern CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid); +struct StrS { + CFStringRef sref_member; +}; + +@interface NSString : NSObject { + CFStringRef sref; + struct StrS *strS; +} +-(id)string; +-(id)newString; +@end + void f(BOOL b, id p) { NSString *str = (NSString *)kUTTypePlainText; str = b ? kUTTypeRTF : kUTTypePlainText; @@ -41,6 +48,16 @@ void f(BOOL b, id p) { } @end +@implementation NSString +-(id)string { + if (0) + return sref; + else + return strS->sref_member; +} +-(id)newString { return 0; } +@end + extern void consumeParam(CFStringRef CF_CONSUMED p); void f2(NSString *s) { diff --git a/test/ARCMT/nonobjc-to-objc-cast.m.result b/test/ARCMT/nonobjc-to-objc-cast.m.result index b50a948..4f508f6 100644 --- a/test/ARCMT/nonobjc-to-objc-cast.m.result +++ b/test/ARCMT/nonobjc-to-objc-cast.m.result @@ -5,11 +5,6 @@ #include "Common.h" -@interface NSString : NSObject --(id)string; --(id)newString; -@end - typedef const struct __CFString * CFStringRef; extern const CFStringRef kUTTypePlainText; extern const CFStringRef kUTTypeRTF; @@ -21,6 +16,18 @@ extern const CFAllocatorRef kCFAllocatorDefault; extern CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid); +struct StrS { + CFStringRef sref_member; +}; + +@interface NSString : NSObject { + CFStringRef sref; + struct StrS *strS; +} +-(id)string; +-(id)newString; +@end + void f(BOOL b, id p) { NSString *str = (__bridge NSString *)kUTTypePlainText; str = (__bridge NSString *)(b ? kUTTypeRTF : kUTTypePlainText); @@ -28,9 +35,9 @@ void f(BOOL b, id p) { str = (NSString *)p; // no change. CFUUIDRef _uuid; - NSString *_uuidString = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid); - _uuidString = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid); - _uuidString = (__bridge_transfer NSString *)(CFRetain(_uuid)); + NSString *_uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, _uuid)); + _uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, _uuid)); + _uuidString = CFBridgingRelease(CFRetain(_uuid)); } @implementation NSString (StrExt) @@ -41,22 +48,32 @@ void f(BOOL b, id p) { } @end +@implementation NSString +-(id)string { + if (0) + return (__bridge id)(sref); + else + return (__bridge id)(strS->sref_member); +} +-(id)newString { return 0; } +@end + extern void consumeParam(CFStringRef CF_CONSUMED p); void f2(NSString *s) { CFStringRef ref = (__bridge CFStringRef)([s string]); ref = (__bridge CFStringRef)[s string]; ref = (__bridge CFStringRef)(s.string); - ref = (__bridge_retained CFStringRef)([NSString new]); - ref = (__bridge_retained CFStringRef)([s newString]); - ref = (__bridge_retained CFStringRef)[NSString new]; - ref = (__bridge_retained CFStringRef)([[NSString alloc] init]); - ref = (__bridge_retained CFStringRef)([s string]); - ref = (__bridge_retained CFStringRef)[s string]; - ref = (__bridge_retained CFTypeRef)([s string]); - ref = (__bridge_retained CFTypeRef)(s); - ref = (__bridge_retained CFStringRef)(s); - - consumeParam((__bridge_retained CFStringRef)s); - consumeParam((__bridge_retained CFStringRef)(s)); + ref = CFBridgingRetain([NSString new]); + ref = CFBridgingRetain([s newString]); + ref = (CFStringRef)CFBridgingRetain([NSString new]); + ref = CFBridgingRetain([[NSString alloc] init]); + ref = CFBridgingRetain([s string]); + ref = (CFStringRef)CFBridgingRetain([s string]); + ref = CFBridgingRetain([s string]); + ref = CFBridgingRetain(s); + ref = CFBridgingRetain(s); + + consumeParam((CFStringRef)CFBridgingRetain(s)); + consumeParam(CFBridgingRetain(s)); } diff --git a/test/ARCMT/objcmt-boxing.m b/test/ARCMT/objcmt-boxing.m new file mode 100644 index 0000000..2ad65a1 --- /dev/null +++ b/test/ARCMT/objcmt-boxing.m @@ -0,0 +1,102 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c++ -verify +// 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 + +#define YES __objc_yes +#define NO __objc_no + +typedef long NSInteger; +typedef unsigned long NSUInteger; +typedef signed char BOOL; +#define nil ((void*) 0) + +#define INT_MIN (-__INT_MAX__ -1) + +@interface NSObject ++ (id)alloc; +@end + +@interface NSNumber : NSObject +@end + +@interface NSNumber (NSNumberCreation) +- (id)initWithChar:(char)value; +- (id)initWithUnsignedChar:(unsigned char)value; +- (id)initWithShort:(short)value; +- (id)initWithUnsignedShort:(unsigned short)value; +- (id)initWithInt:(int)value; +- (id)initWithUnsignedInt:(unsigned int)value; +- (id)initWithLong:(long)value; +- (id)initWithUnsignedLong:(unsigned long)value; +- (id)initWithLongLong:(long long)value; +- (id)initWithUnsignedLongLong:(unsigned long long)value; +- (id)initWithFloat:(float)value; +- (id)initWithDouble:(double)value; +- (id)initWithBool:(BOOL)value; +- (id)initWithInteger:(NSInteger)value; +- (id)initWithUnsignedInteger:(NSUInteger)value; + ++ (NSNumber *)numberWithChar:(char)value; ++ (NSNumber *)numberWithUnsignedChar:(unsigned char)value; ++ (NSNumber *)numberWithShort:(short)value; ++ (NSNumber *)numberWithUnsignedShort:(unsigned short)value; ++ (NSNumber *)numberWithInt:(int)value; ++ (NSNumber *)numberWithUnsignedInt:(unsigned int)value; ++ (NSNumber *)numberWithLong:(long)value; ++ (NSNumber *)numberWithUnsignedLong:(unsigned long)value; ++ (NSNumber *)numberWithLongLong:(long long)value; ++ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value; ++ (NSNumber *)numberWithFloat:(float)value; ++ (NSNumber *)numberWithDouble:(double)value; ++ (NSNumber *)numberWithBool:(BOOL)value; ++ (NSNumber *)numberWithInteger:(NSInteger)value; ++ (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value; +@end + +enum { + NSASCIIStringEncoding = 1, + NSUTF8StringEncoding = 4, + NSUnicodeStringEncoding = 10 +}; +typedef NSUInteger NSStringEncoding; + +@interface NSString : NSObject +@end + +@interface NSString (NSStringExtensionMethods) ++ (id)stringWithUTF8String:(const char *)nullTerminatedCString; ++ (id)stringWithCString:(const char *)cString encoding:(NSStringEncoding)enc; ++ (id)stringWithCString:(const char *)bytes; +@end + +enum MyEnm { + ME_foo +}; + +void foo() { + [NSNumber numberWithInt:INT_MIN]; + bool cppb; + [NSNumber numberWithBool:cppb]; + MyEnm myenum; + [NSNumber numberWithInteger:myenum]; + [NSNumber numberWithInteger:ME_foo]; + [NSNumber numberWithDouble:cppb]; // expected-warning {{converting to boxing syntax requires casting 'bool' to 'double'}} +} + +void boxString() { + NSString *s = [NSString stringWithUTF8String:"box"]; + const char *cstr1; + char *cstr2; + s = [NSString stringWithUTF8String:cstr1]; + s = [NSString stringWithUTF8String:cstr2]; + s = [NSString stringWithCString:cstr1 encoding:NSASCIIStringEncoding]; + s = [NSString stringWithCString:cstr1 encoding:NSUTF8StringEncoding]; + s = [NSString stringWithCString:cstr1 encoding: NSUnicodeStringEncoding]; + NSStringEncoding encode; + s = [NSString stringWithCString:cstr1 encoding:encode]; + s = [NSString stringWithCString:cstr1]; + + static const char strarr[] = "coolbox"; + s = [NSString stringWithUTF8String:strarr]; +} diff --git a/test/ARCMT/objcmt-boxing.m.result b/test/ARCMT/objcmt-boxing.m.result new file mode 100644 index 0000000..f101989 --- /dev/null +++ b/test/ARCMT/objcmt-boxing.m.result @@ -0,0 +1,102 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c++ -verify +// 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 + +#define YES __objc_yes +#define NO __objc_no + +typedef long NSInteger; +typedef unsigned long NSUInteger; +typedef signed char BOOL; +#define nil ((void*) 0) + +#define INT_MIN (-__INT_MAX__ -1) + +@interface NSObject ++ (id)alloc; +@end + +@interface NSNumber : NSObject +@end + +@interface NSNumber (NSNumberCreation) +- (id)initWithChar:(char)value; +- (id)initWithUnsignedChar:(unsigned char)value; +- (id)initWithShort:(short)value; +- (id)initWithUnsignedShort:(unsigned short)value; +- (id)initWithInt:(int)value; +- (id)initWithUnsignedInt:(unsigned int)value; +- (id)initWithLong:(long)value; +- (id)initWithUnsignedLong:(unsigned long)value; +- (id)initWithLongLong:(long long)value; +- (id)initWithUnsignedLongLong:(unsigned long long)value; +- (id)initWithFloat:(float)value; +- (id)initWithDouble:(double)value; +- (id)initWithBool:(BOOL)value; +- (id)initWithInteger:(NSInteger)value; +- (id)initWithUnsignedInteger:(NSUInteger)value; + ++ (NSNumber *)numberWithChar:(char)value; ++ (NSNumber *)numberWithUnsignedChar:(unsigned char)value; ++ (NSNumber *)numberWithShort:(short)value; ++ (NSNumber *)numberWithUnsignedShort:(unsigned short)value; ++ (NSNumber *)numberWithInt:(int)value; ++ (NSNumber *)numberWithUnsignedInt:(unsigned int)value; ++ (NSNumber *)numberWithLong:(long)value; ++ (NSNumber *)numberWithUnsignedLong:(unsigned long)value; ++ (NSNumber *)numberWithLongLong:(long long)value; ++ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value; ++ (NSNumber *)numberWithFloat:(float)value; ++ (NSNumber *)numberWithDouble:(double)value; ++ (NSNumber *)numberWithBool:(BOOL)value; ++ (NSNumber *)numberWithInteger:(NSInteger)value; ++ (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value; +@end + +enum { + NSASCIIStringEncoding = 1, + NSUTF8StringEncoding = 4, + NSUnicodeStringEncoding = 10 +}; +typedef NSUInteger NSStringEncoding; + +@interface NSString : NSObject +@end + +@interface NSString (NSStringExtensionMethods) ++ (id)stringWithUTF8String:(const char *)nullTerminatedCString; ++ (id)stringWithCString:(const char *)cString encoding:(NSStringEncoding)enc; ++ (id)stringWithCString:(const char *)bytes; +@end + +enum MyEnm { + ME_foo +}; + +void foo() { + @INT_MIN; + bool cppb; + @(cppb); + MyEnm myenum; + @(myenum); + @(ME_foo); + [NSNumber numberWithDouble:cppb]; // expected-warning {{converting to boxing syntax requires casting 'bool' to 'double'}} +} + +void boxString() { + NSString *s = @"box"; + const char *cstr1; + char *cstr2; + s = @(cstr1); + s = @(cstr2); + s = @(cstr1); + s = @(cstr1); + s = [NSString stringWithCString:cstr1 encoding: NSUnicodeStringEncoding]; + NSStringEncoding encode; + s = [NSString stringWithCString:cstr1 encoding:encode]; + s = @(cstr1); + + static const char strarr[] = "coolbox"; + s = @(strarr); +} diff --git a/test/ARCMT/objcmt-numeric-literals.m b/test/ARCMT/objcmt-numeric-literals.m index b86af4d..7f33dc2 100644 --- a/test/ARCMT/objcmt-numeric-literals.m +++ b/test/ARCMT/objcmt-numeric-literals.m @@ -1,6 +1,7 @@ // RUN: rm -rf %t // RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c++ // 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 #define YES __objc_yes #define NO __objc_no diff --git a/test/ARCMT/objcmt-numeric-literals.m.result b/test/ARCMT/objcmt-numeric-literals.m.result index 1c4187a..bb7b515 100644 --- a/test/ARCMT/objcmt-numeric-literals.m.result +++ b/test/ARCMT/objcmt-numeric-literals.m.result @@ -1,6 +1,7 @@ // RUN: rm -rf %t // RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c++ // 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 #define YES __objc_yes #define NO __objc_no @@ -467,7 +468,7 @@ void foo() { [NSNumber numberWithInteger:NO]; [NSNumber numberWithInteger:true]; [NSNumber numberWithInteger:false]; - [NSNumber numberWithInteger:VAL_INT]; + @VAL_INT; [NSNumber numberWithInteger:VAL_UINT]; [NSNumber numberWithUnsignedInteger:'a']; @@ -497,5 +498,5 @@ void foo() { [NSNumber numberWithUnsignedInteger:true]; [NSNumber numberWithUnsignedInteger:false]; [NSNumber numberWithUnsignedInteger:VAL_INT]; - [NSNumber numberWithUnsignedInteger:VAL_UINT]; + @VAL_UINT; } diff --git a/test/ARCMT/objcmt-subscripting-literals-in-arc.m b/test/ARCMT/objcmt-subscripting-literals-in-arc.m new file mode 100644 index 0000000..4d94162 --- /dev/null +++ b/test/ARCMT/objcmt-subscripting-literals-in-arc.m @@ -0,0 +1,106 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fobjc-arc -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -triple x86_64-apple-darwin11 +// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result +// RUN: %clang_cc1 -fobjc-arc -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s.result + +typedef signed char BOOL; +#define nil ((void*) 0) + +typedef const struct __CFString * CFStringRef; + +@interface NSObject ++ (id)alloc; +@end + +@protocol NSCopying +@end + +@interface NSString : NSObject ++ (id)stringWithString:(NSString *)string; +- (id)initWithString:(NSString *)aString; +@end + +@interface NSArray : NSObject +- (id)objectAtIndex:(unsigned long)index; +@end + +@interface NSArray (NSExtendedArray) +- (id)objectAtIndexedSubscript:(unsigned)idx; +@end + +@interface NSArray (NSArrayCreation) ++ (id)array; ++ (id)arrayWithObject:(id)anObject; ++ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; ++ (id)arrayWithObjects:(id)firstObj, ...; ++ (id)arrayWithArray:(NSArray *)array; + +- (id)initWithObjects:(const id [])objects count:(unsigned long)cnt; +- (id)initWithObjects:(id)firstObj, ...; +- (id)initWithArray:(NSArray *)array; +@end + +@interface NSMutableArray : NSArray +- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; +@end + +@interface NSMutableArray (NSExtendedMutableArray) +- (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx; +@end + +@interface NSDictionary : NSObject +- (id)objectForKey:(id)aKey; +@end + +@interface NSDictionary (NSExtendedDictionary) +- (id)objectForKeyedSubscript:(id)key; +@end + +@interface NSDictionary (NSDictionaryCreation) ++ (id)dictionary; ++ (id)dictionaryWithObject:(id)object forKey:(id)key; ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; ++ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...; ++ (id)dictionaryWithDictionary:(NSDictionary *)dict; ++ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; + +- (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; +- (id)initWithObjectsAndKeys:(id)firstObject, ...; +- (id)initWithDictionary:(NSDictionary *)otherDictionary; +- (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; +@end + +@interface NSMutableDictionary : NSDictionary +- (void)setObject:(id)anObject forKey:(id)aKey; +@end + +@interface NSMutableDictionary (NSExtendedMutableDictionary) +- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; +@end + +@interface NSNumber : NSObject +@end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithInt:(int)value; +- (id)initWithInt:(int)value; +@end + +@interface I { + NSArray *ivarArr; +} +@end +@implementation I +-(void) foo { + NSString *str; + NSArray *arr; + NSDictionary *dict; + + arr = [NSArray arrayWithObjects:str, str, nil]; + arr = [[NSArray alloc] initWithObjects:str, str, nil]; + dict = [NSDictionary dictionaryWithObjectsAndKeys: @"value1", @"key1", @"value2", @"key2", nil]; + dict = [[NSDictionary alloc] initWithObjectsAndKeys: @"value1", @"key1", @"value2", @"key2", 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 new file mode 100644 index 0000000..6f7a723 --- /dev/null +++ b/test/ARCMT/objcmt-subscripting-literals-in-arc.m.result @@ -0,0 +1,106 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fobjc-arc -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -triple x86_64-apple-darwin11 +// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result +// RUN: %clang_cc1 -fobjc-arc -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s.result + +typedef signed char BOOL; +#define nil ((void*) 0) + +typedef const struct __CFString * CFStringRef; + +@interface NSObject ++ (id)alloc; +@end + +@protocol NSCopying +@end + +@interface NSString : NSObject ++ (id)stringWithString:(NSString *)string; +- (id)initWithString:(NSString *)aString; +@end + +@interface NSArray : NSObject +- (id)objectAtIndex:(unsigned long)index; +@end + +@interface NSArray (NSExtendedArray) +- (id)objectAtIndexedSubscript:(unsigned)idx; +@end + +@interface NSArray (NSArrayCreation) ++ (id)array; ++ (id)arrayWithObject:(id)anObject; ++ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; ++ (id)arrayWithObjects:(id)firstObj, ...; ++ (id)arrayWithArray:(NSArray *)array; + +- (id)initWithObjects:(const id [])objects count:(unsigned long)cnt; +- (id)initWithObjects:(id)firstObj, ...; +- (id)initWithArray:(NSArray *)array; +@end + +@interface NSMutableArray : NSArray +- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; +@end + +@interface NSMutableArray (NSExtendedMutableArray) +- (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx; +@end + +@interface NSDictionary : NSObject +- (id)objectForKey:(id)aKey; +@end + +@interface NSDictionary (NSExtendedDictionary) +- (id)objectForKeyedSubscript:(id)key; +@end + +@interface NSDictionary (NSDictionaryCreation) ++ (id)dictionary; ++ (id)dictionaryWithObject:(id)object forKey:(id)key; ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; ++ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...; ++ (id)dictionaryWithDictionary:(NSDictionary *)dict; ++ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; + +- (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; +- (id)initWithObjectsAndKeys:(id)firstObject, ...; +- (id)initWithDictionary:(NSDictionary *)otherDictionary; +- (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; +@end + +@interface NSMutableDictionary : NSDictionary +- (void)setObject:(id)anObject forKey:(id)aKey; +@end + +@interface NSMutableDictionary (NSExtendedMutableDictionary) +- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; +@end + +@interface NSNumber : NSObject +@end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithInt:(int)value; +- (id)initWithInt:(int)value; +@end + +@interface I { + NSArray *ivarArr; +} +@end +@implementation I +-(void) foo { + NSString *str; + NSArray *arr; + NSDictionary *dict; + + arr = @[str, str]; + arr = @[str, str]; + dict = @{@"key1": @"value1", @"key2": @"value2"}; + dict = @{@"key1": @"value1", @"key2": @"value2"}; + + NSNumber *n = @2; +} +@end diff --git a/test/ARCMT/objcmt-subscripting-literals.m b/test/ARCMT/objcmt-subscripting-literals.m index 3d26efe..0174fcf 100644 --- a/test/ARCMT/objcmt-subscripting-literals.m +++ b/test/ARCMT/objcmt-subscripting-literals.m @@ -1,14 +1,20 @@ // RUN: rm -rf %t // RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -triple x86_64-apple-darwin11 // 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 typedef signed char BOOL; #define nil ((void*) 0) +typedef const struct __CFString * CFStringRef; + @interface NSObject + (id)alloc; @end +@protocol NSCopying +@end + @interface NSString : NSObject + (id)stringWithString:(NSString *)string; - (id)initWithString:(NSString *)aString; @@ -16,7 +22,10 @@ typedef signed char BOOL; @interface NSArray : NSObject - (id)objectAtIndex:(unsigned long)index; -- (id)objectAtIndexedSubscript:(int)index; +@end + +@interface NSArray (NSExtendedArray) +- (id)objectAtIndexedSubscript:(unsigned)idx; @end @interface NSArray (NSArrayCreation) @@ -29,16 +38,21 @@ typedef signed char BOOL; - (id)initWithObjects:(const id [])objects count:(unsigned long)cnt; - (id)initWithObjects:(id)firstObj, ...; - (id)initWithArray:(NSArray *)array; - -- (id)objectAtIndex:(unsigned long)index; @end @interface NSMutableArray : NSArray - (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; -- (void)setObject:(id)object atIndexedSubscript:(int)index; +@end + +@interface NSMutableArray (NSExtendedMutableArray) +- (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx; @end @interface NSDictionary : NSObject +- (id)objectForKey:(id)aKey; +@end + +@interface NSDictionary (NSExtendedDictionary) - (id)objectForKeyedSubscript:(id)key; @end @@ -54,13 +68,14 @@ typedef signed char BOOL; - (id)initWithObjectsAndKeys:(id)firstObject, ...; - (id)initWithDictionary:(NSDictionary *)otherDictionary; - (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; - -- (id)objectForKey:(id)aKey; @end @interface NSMutableDictionary : NSDictionary - (void)setObject:(id)anObject forKey:(id)aKey; -- (void)setObject:(id)object forKeyedSubscript:(id)key; +@end + +@interface NSMutableDictionary (NSExtendedMutableDictionary) +- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; @end @interface NSNumber : NSObject @@ -74,7 +89,9 @@ typedef signed char BOOL; #define PAIR(x) @#x, [NSNumber numberWithInt:(x)] #define TWO(x) ((x), (x)) -@interface I +@interface I { + NSArray *ivarArr; +} @end @implementation I -(void) foo { @@ -133,5 +150,74 @@ typedef signed char BOOL; [mdict setObject:[dict objectForKey:@"key1"] forKey:[dict objectForKey:[NSArray arrayWithObject:@"arrkey"]]]; __strong NSArray **parr = 0; o = [*parr objectAtIndex:2]; + void *hd; + o = [(NSArray*)hd objectAtIndex:2]; + o = [ivarArr objectAtIndex:2]; +} +@end + +extern const CFStringRef globStr; + +void test1(NSString *str) { + NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: str, globStr, nil]; + dict = [NSDictionary dictionaryWithObjectsAndKeys: globStr, str, nil]; + dict = [NSDictionary dictionaryWithObject:str forKey:globStr]; + dict = [NSDictionary dictionaryWithObject:globStr forKey:str]; + + NSArray *arr = [NSArray arrayWithObjects: globStr, globStr, nil]; + arr = [NSArray arrayWithObjects: str, globStr, nil]; + arr = [NSArray arrayWithObjects: globStr, str, nil]; + arr = [NSArray arrayWithObject:globStr]; +} + +@interface Custom : NSObject +- (id)objectAtIndex:(unsigned long)index; +@end + +@interface Custom (Extended) +- (id)objectAtIndexedSubscript:(unsigned)idx; +@end + +@interface MutableCustom : Custom +- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; +@end + +@interface MutableCustom (Extended) +- (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx; +@end + +@interface CustomUnavail : NSObject +- (id)objectAtIndex:(unsigned long)index; +@end + +@interface CustomUnavail (Extended) +- (id)objectAtIndexedSubscript:(unsigned)idx __attribute__((unavailable)); +@end + +@interface MutableCustomUnavail : CustomUnavail +- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; +@end + +@interface MutableCustomUnavail (Extended) +- (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx __attribute__((unavailable)); +@end + +void test2() { + MutableCustom *mutc; + id o = [mutc objectAtIndex:4]; + [mutc replaceObjectAtIndex:2 withObject:@"val"]; + + MutableCustomUnavail *mutcunaval; + o = [mutcunaval objectAtIndex:4]; + [mutcunaval replaceObjectAtIndex:2 withObject:@"val"]; } + +@interface NSLocale : NSObject ++ (id)systemLocale; ++ (id)currentLocale; +- (id)objectForKey:(id)key; @end + +void test3(id key) { + id o = [[NSLocale currentLocale] objectForKey:key]; +} diff --git a/test/ARCMT/objcmt-subscripting-literals.m.result b/test/ARCMT/objcmt-subscripting-literals.m.result index 8ac6dcc..9975996 100644 --- a/test/ARCMT/objcmt-subscripting-literals.m.result +++ b/test/ARCMT/objcmt-subscripting-literals.m.result @@ -1,14 +1,20 @@ // RUN: rm -rf %t // RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -triple x86_64-apple-darwin11 // 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 typedef signed char BOOL; #define nil ((void*) 0) +typedef const struct __CFString * CFStringRef; + @interface NSObject + (id)alloc; @end +@protocol NSCopying +@end + @interface NSString : NSObject + (id)stringWithString:(NSString *)string; - (id)initWithString:(NSString *)aString; @@ -16,7 +22,10 @@ typedef signed char BOOL; @interface NSArray : NSObject - (id)objectAtIndex:(unsigned long)index; -- (id)objectAtIndexedSubscript:(int)index; +@end + +@interface NSArray (NSExtendedArray) +- (id)objectAtIndexedSubscript:(unsigned)idx; @end @interface NSArray (NSArrayCreation) @@ -29,16 +38,21 @@ typedef signed char BOOL; - (id)initWithObjects:(const id [])objects count:(unsigned long)cnt; - (id)initWithObjects:(id)firstObj, ...; - (id)initWithArray:(NSArray *)array; - -- (id)objectAtIndex:(unsigned long)index; @end @interface NSMutableArray : NSArray - (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; -- (void)setObject:(id)object atIndexedSubscript:(int)index; +@end + +@interface NSMutableArray (NSExtendedMutableArray) +- (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx; @end @interface NSDictionary : NSObject +- (id)objectForKey:(id)aKey; +@end + +@interface NSDictionary (NSExtendedDictionary) - (id)objectForKeyedSubscript:(id)key; @end @@ -54,13 +68,14 @@ typedef signed char BOOL; - (id)initWithObjectsAndKeys:(id)firstObject, ...; - (id)initWithDictionary:(NSDictionary *)otherDictionary; - (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; - -- (id)objectForKey:(id)aKey; @end @interface NSMutableDictionary : NSDictionary - (void)setObject:(id)anObject forKey:(id)aKey; -- (void)setObject:(id)object forKeyedSubscript:(id)key; +@end + +@interface NSMutableDictionary (NSExtendedMutableDictionary) +- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; @end @interface NSNumber : NSObject @@ -74,7 +89,9 @@ typedef signed char BOOL; #define PAIR(x) @#x, [NSNumber numberWithInt:(x)] #define TWO(x) ((x), (x)) -@interface I +@interface I { + NSArray *ivarArr; +} @end @implementation I -(void) foo { @@ -133,5 +150,74 @@ typedef signed char BOOL; mdict[dict[@[@"arrkey"]]] = dict[@"key1"]; __strong NSArray **parr = 0; o = (*parr)[2]; + void *hd; + o = ((NSArray*)hd)[2]; + o = ivarArr[2]; +} +@end + +extern const CFStringRef globStr; + +void test1(NSString *str) { + NSDictionary *dict = @{(id)globStr: str}; + dict = @{str: (id)globStr}; + dict = @{(id)globStr: str}; + dict = @{str: (id)globStr}; + + NSArray *arr = @[(id)globStr, (id)globStr]; + arr = @[str, (id)globStr]; + arr = @[(id)globStr, str]; + arr = @[(id)globStr]; +} + +@interface Custom : NSObject +- (id)objectAtIndex:(unsigned long)index; +@end + +@interface Custom (Extended) +- (id)objectAtIndexedSubscript:(unsigned)idx; +@end + +@interface MutableCustom : Custom +- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; +@end + +@interface MutableCustom (Extended) +- (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx; +@end + +@interface CustomUnavail : NSObject +- (id)objectAtIndex:(unsigned long)index; +@end + +@interface CustomUnavail (Extended) +- (id)objectAtIndexedSubscript:(unsigned)idx __attribute__((unavailable)); +@end + +@interface MutableCustomUnavail : CustomUnavail +- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; +@end + +@interface MutableCustomUnavail (Extended) +- (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx __attribute__((unavailable)); +@end + +void test2() { + MutableCustom *mutc; + id o = mutc[4]; + mutc[2] = @"val"; + + MutableCustomUnavail *mutcunaval; + o = [mutcunaval objectAtIndex:4]; + [mutcunaval replaceObjectAtIndex:2 withObject:@"val"]; } + +@interface NSLocale : NSObject ++ (id)systemLocale; ++ (id)currentLocale; +- (id)objectForKey:(id)key; @end + +void test3(id key) { + id o = [[NSLocale currentLocale] objectForKey:key]; +} diff --git a/test/ARCMT/objcmt-subscripting-unavailable.m b/test/ARCMT/objcmt-subscripting-unavailable.m new file mode 100644 index 0000000..d72c362 --- /dev/null +++ b/test/ARCMT/objcmt-subscripting-unavailable.m @@ -0,0 +1,79 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -triple x86_64-apple-darwin11 +// 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 + +typedef signed char BOOL; +#define nil ((void*) 0) + +@interface NSObject ++ (id)alloc; +@end + +@interface NSArray : NSObject +- (id)objectAtIndex:(unsigned long)index; +@end + +@interface NSArray (NSArrayCreation) ++ (id)array; ++ (id)arrayWithObject:(id)anObject; ++ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; ++ (id)arrayWithObjects:(id)firstObj, ...; ++ (id)arrayWithArray:(NSArray *)array; + +- (id)initWithObjects:(const id [])objects count:(unsigned long)cnt; +- (id)initWithObjects:(id)firstObj, ...; +- (id)initWithArray:(NSArray *)array; +@end + +@interface NSMutableArray : NSArray +- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; +@end + +@interface NSDictionary : NSObject +@end + +@interface NSDictionary (NSDictionaryCreation) ++ (id)dictionary; ++ (id)dictionaryWithObject:(id)object forKey:(id)key; ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; ++ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...; ++ (id)dictionaryWithDictionary:(NSDictionary *)dict; ++ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; + +- (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; +- (id)initWithObjectsAndKeys:(id)firstObject, ...; +- (id)initWithDictionary:(NSDictionary *)otherDictionary; +- (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; + +- (id)objectForKey:(id)aKey; +@end + +@interface NSMutableDictionary : NSDictionary +- (void)setObject:(id)anObject forKey:(id)aKey; +@end + +@interface I +@end +@implementation I +-(void) foo { + id str; + NSArray *arr; + NSDictionary *dict; + + arr = [NSArray array]; + arr = [NSArray arrayWithObject:str]; + arr = [NSArray arrayWithObjects:str, str, nil]; + dict = [NSDictionary dictionary]; + dict = [NSDictionary dictionaryWithObject:arr forKey:str]; + + id o = [arr objectAtIndex:2]; + o = [dict objectForKey:@"key"]; + NSMutableArray *marr = 0; + NSMutableDictionary *mdict = 0; + [marr replaceObjectAtIndex:2 withObject:@"val"]; + [mdict setObject:@"value" forKey:@"key"]; + [marr replaceObjectAtIndex:2 withObject:[arr objectAtIndex:4]]; + [mdict setObject:[dict objectForKey:@"key2"] forKey:@"key"]; +} +@end diff --git a/test/ARCMT/objcmt-subscripting-unavailable.m.result b/test/ARCMT/objcmt-subscripting-unavailable.m.result new file mode 100644 index 0000000..bd74d55 --- /dev/null +++ b/test/ARCMT/objcmt-subscripting-unavailable.m.result @@ -0,0 +1,79 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -triple x86_64-apple-darwin11 +// 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 + +typedef signed char BOOL; +#define nil ((void*) 0) + +@interface NSObject ++ (id)alloc; +@end + +@interface NSArray : NSObject +- (id)objectAtIndex:(unsigned long)index; +@end + +@interface NSArray (NSArrayCreation) ++ (id)array; ++ (id)arrayWithObject:(id)anObject; ++ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; ++ (id)arrayWithObjects:(id)firstObj, ...; ++ (id)arrayWithArray:(NSArray *)array; + +- (id)initWithObjects:(const id [])objects count:(unsigned long)cnt; +- (id)initWithObjects:(id)firstObj, ...; +- (id)initWithArray:(NSArray *)array; +@end + +@interface NSMutableArray : NSArray +- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; +@end + +@interface NSDictionary : NSObject +@end + +@interface NSDictionary (NSDictionaryCreation) ++ (id)dictionary; ++ (id)dictionaryWithObject:(id)object forKey:(id)key; ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; ++ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...; ++ (id)dictionaryWithDictionary:(NSDictionary *)dict; ++ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; + +- (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; +- (id)initWithObjectsAndKeys:(id)firstObject, ...; +- (id)initWithDictionary:(NSDictionary *)otherDictionary; +- (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; + +- (id)objectForKey:(id)aKey; +@end + +@interface NSMutableDictionary : NSDictionary +- (void)setObject:(id)anObject forKey:(id)aKey; +@end + +@interface I +@end +@implementation I +-(void) foo { + id str; + NSArray *arr; + NSDictionary *dict; + + arr = @[]; + arr = @[str]; + arr = @[str, str]; + dict = @{}; + dict = @{str: arr}; + + id o = [arr objectAtIndex:2]; + o = [dict objectForKey:@"key"]; + NSMutableArray *marr = 0; + NSMutableDictionary *mdict = 0; + [marr replaceObjectAtIndex:2 withObject:@"val"]; + [mdict setObject:@"value" forKey:@"key"]; + [marr replaceObjectAtIndex:2 withObject:[arr objectAtIndex:4]]; + [mdict setObject:[dict objectForKey:@"key2"] forKey:@"key"]; +} +@end diff --git a/test/ARCMT/releases-driver.m b/test/ARCMT/releases-driver.m index b75432a..7b1d2fb 100644 --- a/test/ARCMT/releases-driver.m +++ b/test/ARCMT/releases-driver.m @@ -53,9 +53,8 @@ void func(Foo *p) { @end @implementation Baz -- dealloc { +- (void) dealloc { [_foo release]; - return 0; } @end diff --git a/test/ARCMT/releases-driver.m.result b/test/ARCMT/releases-driver.m.result index 70c0aec..4c864bd 100644 --- a/test/ARCMT/releases-driver.m.result +++ b/test/ARCMT/releases-driver.m.result @@ -49,9 +49,6 @@ void func(Foo *p) { @end @implementation Baz -- dealloc { - return 0; -} @end #define RELEASE_MACRO(x) [x release] diff --git a/test/ARCMT/releases.m b/test/ARCMT/releases.m index 867fab9..5500895 100644 --- a/test/ARCMT/releases.m +++ b/test/ARCMT/releases.m @@ -58,9 +58,8 @@ void func(Foo *p) { @end @implementation Baz -- dealloc { +- (void) dealloc { [_foo release]; - return 0; } @end diff --git a/test/ARCMT/releases.m.result b/test/ARCMT/releases.m.result index 556610a..473750e 100644 --- a/test/ARCMT/releases.m.result +++ b/test/ARCMT/releases.m.result @@ -54,9 +54,6 @@ void func(Foo *p) { @end @implementation Baz -- dealloc { - return 0; -} @end void block_test(Foo *p) { diff --git a/test/ARCMT/verify.m b/test/ARCMT/verify.m new file mode 100644 index 0000000..9110fe6 --- /dev/null +++ b/test/ARCMT/verify.m @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -arcmt-check -verify %s +// RUN: %clang_cc1 -arcmt-check -verify %t.invalid 2>&1 | FileCheck %s + +#if 0 +// expected-error {{should be ignored}} +#endif + +#error should not be ignored +// expected-error@-1 {{should not be ignored}} + +// CHECK: error: 'error' diagnostics seen but not expected: +// CHECK-NEXT: (frontend): error reading '{{.*}}verify.m.tmp.invalid' +// CHECK-NEXT: 1 error generated. |