diff options
author | Zancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au> | 2012-09-24 09:58:17 +1000 |
---|---|---|
committer | Zancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au> | 2012-09-24 09:58:17 +1000 |
commit | 222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch) | |
tree | 7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/ARCMT | |
parent | 3d206f03985b50beacae843d880bccdc91a9f424 (diff) |
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/ARCMT')
83 files changed, 4612 insertions, 0 deletions
diff --git a/clang/test/ARCMT/Common.h b/clang/test/ARCMT/Common.h new file mode 100644 index 0000000..16856ed --- /dev/null +++ b/clang/test/ARCMT/Common.h @@ -0,0 +1,70 @@ +#if __has_feature(objc_arr) +#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode"))) +#else +#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE +#endif + +#define NS_RETURNS_RETAINED __attribute__((ns_returns_retained)) +#define CF_CONSUMED __attribute__((cf_consumed)) + +#define NS_INLINE static __inline__ __attribute__((always_inline)) +#define nil ((void*) 0) + +typedef int BOOL; +typedef unsigned NSUInteger; +typedef int int32_t; +typedef unsigned char uint8_t; +typedef int32_t UChar32; +typedef unsigned char UChar; + +typedef struct _NSZone NSZone; + +typedef const void * CFTypeRef; +CFTypeRef CFRetain(CFTypeRef cf); +id CFBridgingRelease(CFTypeRef CF_CONSUMED X); + +NS_INLINE NS_RETURNS_RETAINED id NSMakeCollectable(CFTypeRef CF_CONSUMED cf) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (NSUInteger)retainCount NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (id)autorelease NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +@end + +@interface NSObject <NSObject> {} +- (id)init; + ++ (id)new; ++ (id)alloc; +- (void)dealloc; + +- (void)finalize; + +- (id)copy; +- (id)mutableCopy; +@end + +NS_AUTOMATED_REFCOUNT_UNAVAILABLE +@interface NSAutoreleasePool : NSObject { +@private + void *_token; + void *_reserved3; + void *_reserved2; + void *_reserved; +} + ++ (void)addObject:(id)anObject; + +- (void)addObject:(id)anObject; + +- (void)drain; + +@end + +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); diff --git a/clang/test/ARCMT/GC-check-warn-nsalloc.m b/clang/test/ARCMT/GC-check-warn-nsalloc.m new file mode 100644 index 0000000..5ce36c4 --- /dev/null +++ b/clang/test/ARCMT/GC-check-warn-nsalloc.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -arcmt-check -verify -no-ns-alloc-error -triple x86_64-apple-darwin10 -fobjc-gc-only %s +// RUN: %clang_cc1 -arcmt-check -verify -no-ns-alloc-error -triple x86_64-apple-darwin10 -fobjc-gc-only -x objective-c++ %s +// DISABLE: mingw32 +// rdar://10532541 +// XFAIL: * + +typedef unsigned NSUInteger; +void *__strong NSAllocateCollectable(NSUInteger size, NSUInteger options); + +void test1() { + NSAllocateCollectable(100, 0); // expected-warning {{call returns pointer to GC managed memory; it will become unmanaged in ARC}} +} diff --git a/clang/test/ARCMT/GC-check.m b/clang/test/ARCMT/GC-check.m new file mode 100644 index 0000000..3a1b67c --- /dev/null +++ b/clang/test/ARCMT/GC-check.m @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-gc-only %s +// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-gc-only -x objective-c++ %s +// DISABLE: mingw32 + +#define CF_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode"))) +typedef unsigned NSUInteger; +typedef const void * CFTypeRef; +CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE; // expected-note {{unavailable}} +void *__strong NSAllocateCollectable(NSUInteger size, NSUInteger options); + +void test1(CFTypeRef *cft) { + CFTypeRef c = CFMakeCollectable(cft); // expected-error {{CFMakeCollectable will leak the object that it receives in ARC}} \ + // expected-error {{unavailable}} + NSAllocateCollectable(100, 0); // expected-error {{call returns pointer to GC managed memory; it will become unmanaged in ARC}} +} + +@interface I1 { + __strong void *gcVar; // expected-error {{GC managed memory will become unmanaged in ARC}} +} +@end; diff --git a/clang/test/ARCMT/GC-no-arc-runtime.m b/clang/test/ARCMT/GC-no-arc-runtime.m new file mode 100644 index 0000000..f069992 --- /dev/null +++ b/clang/test/ARCMT/GC-no-arc-runtime.m @@ -0,0 +1,78 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-gc-only -x objective-c %s > %t +// RUN: diff %t %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-gc-only -x objective-c++ %s > %t +// RUN: diff %t %s.result +// DISABLE: mingw32 + +#include "Common.h" +#include "GC.h" + +void test1(CFTypeRef *cft) { + id x = NSMakeCollectable(cft); +} + +@interface I1 +@end + +@implementation I1 +-(void)dealloc { + // dealloc + test1(0); +} + +-(void)finalize { + // finalize + test1(0); +} +@end + +@interface I2 +@property (retain) id prop; +@end + +@implementation I2 +@synthesize prop; + +-(void)finalize { + self.prop = 0; + // finalize + test1(0); +} +@end + +__attribute__((objc_arc_weak_reference_unavailable)) +@interface QQ { + __weak id s; + __weak QQ *q; +} +@end + +@interface I3 +@property (assign) I3 *__weak pw1, *__weak pw2; +@property (assign) I3 *__strong ps; +@property (assign) I3 * pds; +@end + +@interface I4Impl { + I4Impl *pds2; +} +@property (assign) I4Impl *__weak pw1, *__weak pw2; +@property (assign) I4Impl *__strong ps; +@property (assign) I4Impl * pds; +@property (assign) I4Impl * pds2; +@end + +@implementation I4Impl +@synthesize pw1, pw2, ps, pds, pds2; + +-(void)test1:(CFTypeRef *)cft { + id x = NSMakeCollectable(cft); +} +@end + +@interface I5 { + __weak id prop; +} +@property (readonly) __weak id prop; +@end diff --git a/clang/test/ARCMT/GC-no-arc-runtime.m.result b/clang/test/ARCMT/GC-no-arc-runtime.m.result new file mode 100644 index 0000000..f55ca38 --- /dev/null +++ b/clang/test/ARCMT/GC-no-arc-runtime.m.result @@ -0,0 +1,73 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-gc-only -x objective-c %s > %t +// RUN: diff %t %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-gc-only -x objective-c++ %s > %t +// RUN: diff %t %s.result +// DISABLE: mingw32 + +#include "Common.h" +#include "GC.h" + +void test1(CFTypeRef *cft) { + id x = CFBridgingRelease(cft); +} + +@interface I1 +@end + +@implementation I1 +-(void)dealloc { + // dealloc + test1(0); +} + +@end + +@interface I2 +@property (strong) id prop; +@end + +@implementation I2 +@synthesize prop; + +-(void)dealloc { + // finalize + test1(0); +} +@end + +__attribute__((objc_arc_weak_reference_unavailable)) +@interface QQ { + __unsafe_unretained id s; + __unsafe_unretained QQ *q; +} +@end + +@interface I3 +@property (unsafe_unretained) I3 * pw1, * pw2; +@property (strong) I3 * ps; +@property (assign) I3 * pds; +@end + +@interface I4Impl { + I4Impl *__strong pds2; +} +@property (unsafe_unretained) I4Impl * pw1, * pw2; +@property (strong) I4Impl * ps; +@property (strong) I4Impl * pds; +@property (strong) I4Impl * pds2; +@end + +@implementation I4Impl +@synthesize pw1, pw2, ps, pds, pds2; + +-(void)test1:(CFTypeRef *)cft { + id x = CFBridgingRelease(cft); +} +@end + +@interface I5 { + __unsafe_unretained id prop; +} +@property (unsafe_unretained, readonly) id prop; +@end diff --git a/clang/test/ARCMT/GC-no-finalize-removal.m b/clang/test/ARCMT/GC-no-finalize-removal.m new file mode 100644 index 0000000..14e8602 --- /dev/null +++ b/clang/test/ARCMT/GC-no-finalize-removal.m @@ -0,0 +1,90 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-gc-only -no-finalize-removal -x objective-c %s > %t +// RUN: diff %t %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-gc-only -no-finalize-removal -x objective-c++ %s > %t +// RUN: diff %t %s.result +// DISABLE: mingw32 + +#include "Common.h" +#include "GC.h" + +void test1(CFTypeRef *cft) { + id x = NSMakeCollectable(cft); +} + +@interface I1 +@end + +@implementation I1 +-(void)dealloc { + // dealloc + test1(0); +} + +-(void)finalize { + // finalize + test1(0); +} +@end + +@interface I2 +@property (retain) id prop; +@end + +@implementation I2 +@synthesize prop; + +-(void)finalize { + self.prop = 0; + // finalize + test1(0); +} +@end + +__attribute__((objc_arc_weak_reference_unavailable)) +@interface QQ { + __weak id s; + __weak QQ *q; +} +@end + +@interface I3 +@property (assign) I3 *__weak pw1, *__weak pw2; +@property (assign) I3 *__strong ps; +@property (assign) I3 * pds; +@end + +@interface I4Impl { + I4Impl *pds2; + I4Impl *pds3; + __weak I4Impl *pw3; + __weak I4Impl *pw4; +} +@property (assign) I4Impl *__weak pw1, *__weak pw2; +@property (assign) I4Impl *__strong ps; +@property (assign) I4Impl * pds; +@property (assign) I4Impl * pds2; +@property (readwrite) I4Impl * pds3; +@property (readonly) I4Impl * pds4; +@property (readonly) __weak I4Impl *pw3; +@property (assign) __weak I4Impl *pw4; +@end + +@implementation I4Impl +@synthesize pw1, pw2, pw3, pw4, ps, pds, pds2, pds3, pds4; + +-(void)test1:(CFTypeRef *)cft { + id x = NSMakeCollectable(cft); +} +@end + +// rdar://10532449 +@interface rdar10532449 +@property (assign) id assign_prop; +@property (assign, readonly) id __strong strong_readonly_prop; +@property (assign) id __weak weak_prop; +@end + +@implementation rdar10532449 +@synthesize assign_prop, strong_readonly_prop, weak_prop; +@end diff --git a/clang/test/ARCMT/GC-no-finalize-removal.m.result b/clang/test/ARCMT/GC-no-finalize-removal.m.result new file mode 100644 index 0000000..ea14873 --- /dev/null +++ b/clang/test/ARCMT/GC-no-finalize-removal.m.result @@ -0,0 +1,98 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-gc-only -no-finalize-removal -x objective-c %s > %t +// RUN: diff %t %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-gc-only -no-finalize-removal -x objective-c++ %s > %t +// RUN: diff %t %s.result +// DISABLE: mingw32 + +#include "Common.h" +#include "GC.h" + +void test1(CFTypeRef *cft) { + id x = CFBridgingRelease(cft); +} + +@interface I1 +@end + +@implementation I1 +-(void)dealloc { + // dealloc + test1(0); +} + +#if !__has_feature(objc_arc) +-(void)finalize { + // finalize + test1(0); +} +#endif +@end + +@interface I2 +@property (strong) id prop; +@end + +@implementation I2 +@synthesize prop; + +#if !__has_feature(objc_arc) +-(void)finalize { + self.prop = 0; + // finalize + test1(0); +} +#endif +-(void)dealloc { + // finalize + test1(0); +} +@end + +__attribute__((objc_arc_weak_reference_unavailable)) +@interface QQ { + __weak id s; + __unsafe_unretained QQ *q; +} +@end + +@interface I3 +@property (weak) I3 * pw1, * pw2; +@property (strong) I3 * ps; +@property (assign) I3 * pds; +@end + +@interface I4Impl { + I4Impl *__strong pds2; + I4Impl *pds3; + __weak I4Impl *pw3; + __weak I4Impl *pw4; +} +@property (weak) I4Impl * pw1, * pw2; +@property (strong) I4Impl * ps; +@property (strong) I4Impl * pds; +@property (strong) I4Impl * pds2; +@property (readwrite) I4Impl * pds3; +@property (readonly) I4Impl * pds4; +@property (weak, readonly) I4Impl *pw3; +@property (weak) I4Impl *pw4; +@end + +@implementation I4Impl +@synthesize pw1, pw2, pw3, pw4, ps, pds, pds2, pds3, pds4; + +-(void)test1:(CFTypeRef *)cft { + id x = CFBridgingRelease(cft); +} +@end + +// rdar://10532449 +@interface rdar10532449 +@property (strong) id assign_prop; +@property (strong, readonly) id strong_readonly_prop; +@property (weak) id weak_prop; +@end + +@implementation rdar10532449 +@synthesize assign_prop, strong_readonly_prop, weak_prop; +@end diff --git a/clang/test/ARCMT/GC.h b/clang/test/ARCMT/GC.h new file mode 100644 index 0000000..4301baf --- /dev/null +++ b/clang/test/ARCMT/GC.h @@ -0,0 +1,6 @@ + +@interface ExtInterface { + __strong ExtInterface *myivar; + __strong void *gcVar; +} +@end diff --git a/clang/test/ARCMT/GC.m b/clang/test/ARCMT/GC.m new file mode 100644 index 0000000..eebbaf6 --- /dev/null +++ b/clang/test/ARCMT/GC.m @@ -0,0 +1,95 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-gc-only -x objective-c %s > %t +// RUN: diff %t %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-gc-only -x objective-c++ %s > %t +// RUN: diff %t %s.result +// DISABLE: mingw32 + +#include "Common.h" +#include "GC.h" + +void test1(CFTypeRef *cft) { + id x = NSMakeCollectable(cft); +} + +@interface I1 +@end + +@implementation I1 +-(void)dealloc { + // dealloc + test1(0); +} + +-(void)finalize { + // finalize + test1(0); +} +@end + +@interface I2 +@property (retain) id prop; +@end + +@implementation I2 +@synthesize prop; + +-(void)finalize { + self.prop = 0; + // finalize + test1(0); +} +@end + +__attribute__((objc_arc_weak_reference_unavailable)) +@interface QQ { + __weak id s; + __weak QQ *q; +} +@end + +@interface I3 +@property (assign) I3 *__weak pw1, *__weak pw2; +@property (assign) I3 *__strong ps; +@property (assign) I3 * pds; +@end + +@interface I4Impl { + I4Impl *pds2; + I4Impl *pds3; + __weak I4Impl *pw3; + __weak I4Impl *pw4; +} +@property (assign) I4Impl *__weak pw1, *__weak pw2; +@property (assign) I4Impl *__strong ps; +@property (assign) I4Impl * pds; +@property (assign) I4Impl * pds2; +@property (readwrite) I4Impl * pds3; +@property (readonly) I4Impl * pds4; +@property (readonly) __weak I4Impl *pw3; +@property (assign) __weak I4Impl *pw4; +@end + +@implementation I4Impl +@synthesize pw1, pw2, pw3, pw4, ps, pds, pds2, pds3, pds4; + +-(void)test1:(CFTypeRef *)cft { + id x = NSMakeCollectable(cft); +} +@end + +// rdar://10532449 +@interface rdar10532449 +@property (assign) id assign_prop; +@property (assign, readonly) id __strong strong_readonly_prop; +@property (assign) id __weak weak_prop; +@end + +@implementation rdar10532449 +@synthesize assign_prop, strong_readonly_prop, weak_prop; +@end + +void test2(id p, __strong I1 *ap[]) { + for (__strong I1 *specRule in p) { + } +} diff --git a/clang/test/ARCMT/GC.m.result b/clang/test/ARCMT/GC.m.result new file mode 100644 index 0000000..c2c523f --- /dev/null +++ b/clang/test/ARCMT/GC.m.result @@ -0,0 +1,90 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-gc-only -x objective-c %s > %t +// RUN: diff %t %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-gc-only -x objective-c++ %s > %t +// RUN: diff %t %s.result +// DISABLE: mingw32 + +#include "Common.h" +#include "GC.h" + +void test1(CFTypeRef *cft) { + id x = CFBridgingRelease(cft); +} + +@interface I1 +@end + +@implementation I1 +-(void)dealloc { + // dealloc + test1(0); +} + +@end + +@interface I2 +@property (strong) id prop; +@end + +@implementation I2 +@synthesize prop; + +-(void)dealloc { + // finalize + test1(0); +} +@end + +__attribute__((objc_arc_weak_reference_unavailable)) +@interface QQ { + __weak id s; + __unsafe_unretained QQ *q; +} +@end + +@interface I3 +@property (weak) I3 * pw1, * pw2; +@property (strong) I3 * ps; +@property (assign) I3 * pds; +@end + +@interface I4Impl { + I4Impl *__strong pds2; + I4Impl *pds3; + __weak I4Impl *pw3; + __weak I4Impl *pw4; +} +@property (weak) I4Impl * pw1, * pw2; +@property (strong) I4Impl * ps; +@property (strong) I4Impl * pds; +@property (strong) I4Impl * pds2; +@property (readwrite) I4Impl * pds3; +@property (readonly) I4Impl * pds4; +@property (weak, readonly) I4Impl *pw3; +@property (weak) I4Impl *pw4; +@end + +@implementation I4Impl +@synthesize pw1, pw2, pw3, pw4, ps, pds, pds2, pds3, pds4; + +-(void)test1:(CFTypeRef *)cft { + id x = CFBridgingRelease(cft); +} +@end + +// rdar://10532449 +@interface rdar10532449 +@property (strong) id assign_prop; +@property (strong, readonly) id strong_readonly_prop; +@property (weak) id weak_prop; +@end + +@implementation rdar10532449 +@synthesize assign_prop, strong_readonly_prop, weak_prop; +@end + +void test2(id p, __strong I1 *ap[]) { + for (__strong I1 *specRule in p) { + } +} diff --git a/clang/test/ARCMT/Inputs/test.h b/clang/test/ARCMT/Inputs/test.h new file mode 100644 index 0000000..756295f --- /dev/null +++ b/clang/test/ARCMT/Inputs/test.h @@ -0,0 +1,15 @@ +@protocol NSObject +- (oneway void)release; +@end + +#ifdef PART1 +static inline void part1(id p) { + [p release]; +} +#endif + +#ifdef PART2 +static inline void part2(id p) { + [p release]; +} +#endif diff --git a/clang/test/ARCMT/Inputs/test.h.result b/clang/test/ARCMT/Inputs/test.h.result new file mode 100644 index 0000000..0638a33 --- /dev/null +++ b/clang/test/ARCMT/Inputs/test.h.result @@ -0,0 +1,13 @@ +@protocol NSObject +- (oneway void)release; +@end + +#ifdef PART1 +static inline void part1(id p) { +} +#endif + +#ifdef PART2 +static inline void part2(id p) { +} +#endif diff --git a/clang/test/ARCMT/Inputs/test1.m.in b/clang/test/ARCMT/Inputs/test1.m.in new file mode 100644 index 0000000..8416a88 --- /dev/null +++ b/clang/test/ARCMT/Inputs/test1.m.in @@ -0,0 +1,6 @@ +#define PART1 +#include "test.h" + +void test1(id p) { + [p release]; +} diff --git a/clang/test/ARCMT/Inputs/test1.m.in.result b/clang/test/ARCMT/Inputs/test1.m.in.result new file mode 100644 index 0000000..f351fe6 --- /dev/null +++ b/clang/test/ARCMT/Inputs/test1.m.in.result @@ -0,0 +1,5 @@ +#define PART1 +#include "test.h" + +void test1(id p) { +} diff --git a/clang/test/ARCMT/Inputs/test2.m.in b/clang/test/ARCMT/Inputs/test2.m.in new file mode 100644 index 0000000..99f87b0 --- /dev/null +++ b/clang/test/ARCMT/Inputs/test2.m.in @@ -0,0 +1,6 @@ +#define PART2 +#include "test.h" + +void test2(id p) { + [p release]; +} diff --git a/clang/test/ARCMT/Inputs/test2.m.in.result b/clang/test/ARCMT/Inputs/test2.m.in.result new file mode 100644 index 0000000..f8e918c --- /dev/null +++ b/clang/test/ARCMT/Inputs/test2.m.in.result @@ -0,0 +1,5 @@ +#define PART2 +#include "test.h" + +void test2(id p) { +} diff --git a/clang/test/ARCMT/api.m b/clang/test/ARCMT/api.m new file mode 100644 index 0000000..ba122c4 --- /dev/null +++ b/clang/test/ARCMT/api.m @@ -0,0 +1,10 @@ +// 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(NSObject *o) { + NSZone *z = [o zone]; +} diff --git a/clang/test/ARCMT/api.m.result b/clang/test/ARCMT/api.m.result new file mode 100644 index 0000000..7e04e7d --- /dev/null +++ b/clang/test/ARCMT/api.m.result @@ -0,0 +1,10 @@ +// 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(NSObject *o) { + NSZone *z = nil; +} diff --git a/clang/test/ARCMT/assign-prop-no-arc-runtime.m b/clang/test/ARCMT/assign-prop-no-arc-runtime.m new file mode 100644 index 0000000..de1c456 --- /dev/null +++ b/clang/test/ARCMT/assign-prop-no-arc-runtime.m @@ -0,0 +1,15 @@ +// 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-macosx10.6 -fsyntax-only %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface Foo : NSObject { + NSObject *x; +} +@property (readonly,assign) id x; +@end + +@implementation Foo +@synthesize x; +@end diff --git a/clang/test/ARCMT/assign-prop-no-arc-runtime.m.result b/clang/test/ARCMT/assign-prop-no-arc-runtime.m.result new file mode 100644 index 0000000..23848d3 --- /dev/null +++ b/clang/test/ARCMT/assign-prop-no-arc-runtime.m.result @@ -0,0 +1,15 @@ +// 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-macosx10.6 -fsyntax-only %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface Foo : NSObject { + NSObject *__unsafe_unretained x; +} +@property (readonly,unsafe_unretained) id x; +@end + +@implementation Foo +@synthesize x; +@end diff --git a/clang/test/ARCMT/assign-prop-with-arc-runtime.m b/clang/test/ARCMT/assign-prop-with-arc-runtime.m new file mode 100644 index 0000000..c357eeb --- /dev/null +++ b/clang/test/ARCMT/assign-prop-with-arc-runtime.m @@ -0,0 +1,73 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only %s > %t +// RUN: diff %t %s.result +// DISABLE: mingw32 + +#include "Common.h" + +__attribute__((objc_arc_weak_reference_unavailable)) +@interface WeakOptOut +@end + +@class _NSCachedAttributedString; +typedef _NSCachedAttributedString *BadClassForWeak; + +@class Forw; + +@interface Foo : NSObject { + Foo *x, *w, *q1, *q2; + WeakOptOut *oo; + BadClassForWeak bcw; + id not_safe1; + NSObject *not_safe2; + Forw *not_safe3; + Foo *assign_plus1; +} +@property (readonly) Foo *x; +@property (assign) Foo *w; +@property Foo *q1, *q2; +@property (assign) WeakOptOut *oo; +@property (assign) BadClassForWeak bcw; +@property (assign) id not_safe1; +@property () NSObject *not_safe2; +@property Forw *not_safe3; +@property (readonly) Foo *assign_plus1; +@property (readonly) Foo *assign_plus2; +@property (readonly) Foo *assign_plus3; + +@property (assign) Foo *no_user_ivar1; +@property (readonly) Foo *no_user_ivar2; + +@property (retain) id def1; +@property (atomic,retain) id def2; +@property (retain,atomic) id def3; + +@end + +@implementation Foo +@synthesize x,w,q1,q2,oo,bcw,not_safe1,not_safe2,not_safe3; +@synthesize no_user_ivar1, no_user_ivar2; +@synthesize assign_plus1, assign_plus2, assign_plus3; +@synthesize def1, def2, def3; + +-(void)test:(Foo *)parm { + assign_plus1 = [[Foo alloc] init]; + assign_plus2 = [Foo new]; + assign_plus3 = [parm retain]; +} +@end + +@interface TestExt +@property (retain,readonly) TestExt *x1; +@property (readonly) TestExt *x2; +@end + +@interface TestExt() +@property (retain,readwrite) TestExt *x1; +@property (readwrite) TestExt *x2; +@property (retain) TestExt *x3; +@end + +@implementation TestExt +@synthesize x1, x2, x3; +@end diff --git a/clang/test/ARCMT/assign-prop-with-arc-runtime.m.result b/clang/test/ARCMT/assign-prop-with-arc-runtime.m.result new file mode 100644 index 0000000..a255a36 --- /dev/null +++ b/clang/test/ARCMT/assign-prop-with-arc-runtime.m.result @@ -0,0 +1,73 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only %s > %t +// RUN: diff %t %s.result +// DISABLE: mingw32 + +#include "Common.h" + +__attribute__((objc_arc_weak_reference_unavailable)) +@interface WeakOptOut +@end + +@class _NSCachedAttributedString; +typedef _NSCachedAttributedString *BadClassForWeak; + +@class Forw; + +@interface Foo : NSObject { + Foo *__weak x, *__weak w, *__weak q1, *__weak q2; + WeakOptOut *__unsafe_unretained oo; + BadClassForWeak __unsafe_unretained bcw; + id __unsafe_unretained not_safe1; + NSObject *__unsafe_unretained not_safe2; + Forw *__unsafe_unretained not_safe3; + Foo *assign_plus1; +} +@property (weak, readonly) Foo *x; +@property (weak) Foo *w; +@property (weak) Foo *q1, *q2; +@property (unsafe_unretained) WeakOptOut *oo; +@property (unsafe_unretained) BadClassForWeak bcw; +@property (unsafe_unretained) id not_safe1; +@property (unsafe_unretained) NSObject *not_safe2; +@property (unsafe_unretained) Forw *not_safe3; +@property (readonly) Foo *assign_plus1; +@property (readonly) Foo *assign_plus2; +@property (readonly) Foo *assign_plus3; + +@property (weak) Foo *no_user_ivar1; +@property (weak, readonly) Foo *no_user_ivar2; + +@property (strong) id def1; +@property (atomic,strong) id def2; +@property (strong,atomic) id def3; + +@end + +@implementation Foo +@synthesize x,w,q1,q2,oo,bcw,not_safe1,not_safe2,not_safe3; +@synthesize no_user_ivar1, no_user_ivar2; +@synthesize assign_plus1, assign_plus2, assign_plus3; +@synthesize def1, def2, def3; + +-(void)test:(Foo *)parm { + assign_plus1 = [[Foo alloc] init]; + assign_plus2 = [Foo new]; + assign_plus3 = parm; +} +@end + +@interface TestExt +@property (strong,readonly) TestExt *x1; +@property (weak, readonly) TestExt *x2; +@end + +@interface TestExt() +@property (strong,readwrite) TestExt *x1; +@property (weak, readwrite) TestExt *x2; +@property (strong) TestExt *x3; +@end + +@implementation TestExt +@synthesize x1, x2, x3; +@end diff --git a/clang/test/ARCMT/atautorelease-2.m b/clang/test/ARCMT/atautorelease-2.m new file mode 100644 index 0000000..5c2cd6b --- /dev/null +++ b/clang/test/ARCMT/atautorelease-2.m @@ -0,0 +1,30 @@ +// 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 + +@interface NSAutoreleasePool +- drain; ++new; ++alloc; +-init; +-autorelease; +-release; +@end + +void NSLog(id, ...); + +int main (int argc, const char * argv[]) { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *chunkPool = [[NSAutoreleasePool alloc] init]; + + while (argc) { + [chunkPool release]; + return 0; + } + + [chunkPool drain]; + [pool drain]; + + return 0; +} diff --git a/clang/test/ARCMT/atautorelease-2.m.result b/clang/test/ARCMT/atautorelease-2.m.result new file mode 100644 index 0000000..06bf0d5 --- /dev/null +++ b/clang/test/ARCMT/atautorelease-2.m.result @@ -0,0 +1,29 @@ +// 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 + +@interface NSAutoreleasePool +- drain; ++new; ++alloc; +-init; +-autorelease; +-release; +@end + +void NSLog(id, ...); + +int main (int argc, const char * argv[]) { + @autoreleasepool { + @autoreleasepool { + + while (argc) { + return 0; + } + + } + } + + return 0; +} diff --git a/clang/test/ARCMT/atautorelease-3.m b/clang/test/ARCMT/atautorelease-3.m new file mode 100644 index 0000000..0b6abdf --- /dev/null +++ b/clang/test/ARCMT/atautorelease-3.m @@ -0,0 +1,41 @@ +// 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 + +@interface NSAutoreleasePool +- drain; ++new; ++alloc; +-init; +-autorelease; +- release; +@end + +void NSLog(id, ...); + +void test1(int x) { + // All this stuff get removed since nothing is happening inside. + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *chunkPool = [[NSAutoreleasePool alloc] init]; + while (x) { + chunkPool = [[NSAutoreleasePool alloc] init]; + [chunkPool release]; + } + + [chunkPool drain]; + [pool drain]; +} + +void test2(int x) { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *chunkPool = [[NSAutoreleasePool alloc] init]; + while (x) { + chunkPool = [[NSAutoreleasePool alloc] init]; + ++x; + [chunkPool release]; + } + + [chunkPool drain]; + [pool drain]; +} diff --git a/clang/test/ARCMT/atautorelease-3.m.result b/clang/test/ARCMT/atautorelease-3.m.result new file mode 100644 index 0000000..9103de4 --- /dev/null +++ b/clang/test/ARCMT/atautorelease-3.m.result @@ -0,0 +1,32 @@ +// 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 + +@interface NSAutoreleasePool +- drain; ++new; ++alloc; +-init; +-autorelease; +- release; +@end + +void NSLog(id, ...); + +void test1(int x) { + // All this stuff get removed since nothing is happening inside. +} + +void test2(int x) { + @autoreleasepool { + @autoreleasepool { + while (x) { + @autoreleasepool { + ++x; + } + } + + } + } +} diff --git a/clang/test/ARCMT/atautorelease-check.m b/clang/test/ARCMT/atautorelease-check.m new file mode 100644 index 0000000..8daf9d6 --- /dev/null +++ b/clang/test/ARCMT/atautorelease-check.m @@ -0,0 +1,145 @@ +// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 %s +// DISABLE: mingw32 + +#if __has_feature(objc_arr) +#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode"))) +#else +#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE +#endif + +typedef struct _NSZone NSZone; +typedef int BOOL; +typedef unsigned NSUInteger; + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (NSUInteger)retainCount NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (id)autorelease NS_AUTOMATED_REFCOUNT_UNAVAILABLE; + +- (NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +@end + +@protocol NSCopying +- (id)copyWithZone:(NSZone *)zone; +@end + +@protocol NSMutableCopying +- (id)mutableCopyWithZone:(NSZone *)zone; +@end + +@interface NSObject <NSObject> {} +- (id)init; + ++ (id)new; ++ (id)allocWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; ++ (id)alloc; +- (void)dealloc; + +- (void)finalize; + +- (id)copy; +- (id)mutableCopy; + ++ (id)copyWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; ++ (id)mutableCopyWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +@end + +extern void NSRecycleZone(NSZone *zone); + +NS_AUTOMATED_REFCOUNT_UNAVAILABLE +@interface NSAutoreleasePool : NSObject { // expected-note 13 {{marked unavailable here}} +@private + void *_token; + void *_reserved3; + void *_reserved2; + void *_reserved; +} + ++ (void)addObject:(id)anObject; + +- (void)addObject:(id)anObject; + +- (void)drain; + +@end + + +void NSLog(id, ...); + +int main (int argc, const char * argv[]) { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *chunkPool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} + + while (argc) { + [chunkPool release]; + // the following pool was not released in this scope, don't touch it. + chunkPool = [[NSAutoreleasePool alloc] init]; // expected-error {{'NSAutoreleasePool' is unavailable}} + } + + [chunkPool drain]; + [pool drain]; + + return 0; +} + +void f(void) { + NSAutoreleasePool * pool; // expected-error {{'NSAutoreleasePool' is unavailable}} + + for (int i=0; i != 10; ++i) { + id x = pool; // We won't touch a NSAutoreleasePool if we can't safely + // remove all the references to it. + } + + pool = [[NSAutoreleasePool alloc] init]; // expected-error {{'NSAutoreleasePool' is unavailable}} + NSLog(@"%s", "YES"); + [pool release]; +} + +void f2(void) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} \ + // expected-note {{scope begins here}} + + // 'x' is declared inside the "pool scope" but used outside it, if we create + // a @autorelease scope it will be undefined outside it so don't touch the pool. + int x = 0; // expected-note {{declared here}} + + [pool release]; // expected-note {{scope ends here}} + + ++x; // expected-error {{a name is referenced outside the NSAutoreleasePool scope that it was declared in}} +} + +void f3(void) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} \ + // expected-note {{scope begins here}} + + struct S { int x; }; // expected-note {{declared here}} + + [pool release]; // expected-note {{scope ends here}} + + struct S *var; // expected-error {{a name is referenced outside the NSAutoreleasePool scope that it was declared in}} + var->x = 0; +} + +void f4(void) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} \ + // expected-note {{scope begins here}} + + enum { Bar }; // expected-note {{declared here}} + + [pool release]; // expected-note {{scope ends here}} + + int x = Bar; // expected-error {{a name is referenced outside the NSAutoreleasePool scope that it was declared in}} +} + +void f5(void) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} \ + // expected-note {{scope begins here}} + + typedef int Bar; // expected-note {{declared here}} + + [pool release]; // expected-note {{scope ends here}} + + Bar x; // expected-error {{a name is referenced outside the NSAutoreleasePool scope that it was declared in}} +} diff --git a/clang/test/ARCMT/atautorelease.m b/clang/test/ARCMT/atautorelease.m new file mode 100644 index 0000000..132553b --- /dev/null +++ b/clang/test/ARCMT/atautorelease.m @@ -0,0 +1,62 @@ +// 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 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; +} + +@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 diff --git a/clang/test/ARCMT/atautorelease.m.result b/clang/test/ARCMT/atautorelease.m.result new file mode 100644 index 0000000..5191f47 --- /dev/null +++ b/clang/test/ARCMT/atautorelease.m.result @@ -0,0 +1,61 @@ +// 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 NSLog(id, ...); + +int main (int argc, const char * argv[]) { + + @autoreleasepool { + + if (argc) { + @autoreleasepool { + NSLog(@"%s", "YES"); + } + } + } + + @autoreleasepool { + NSLog(@"%s", "YES"); + } + + return 0; +} + +void f(void) { + + @autoreleasepool { + int x = 4; + + @autoreleasepool { + ++x; + } + + } +} + +int UIApplicationMain(int argc, char *argv[]); + +int main2(int argc, char *argv[]) { + @autoreleasepool { + int result = UIApplicationMain(argc, argv); + return result; + } +} + +@interface Foo : NSObject +@property (unsafe_unretained) id myProp; +@end + +@implementation Foo +@synthesize myProp; + +-(void)test:(id)p { + @autoreleasepool { + } + self.myProp = p; +} +@end diff --git a/clang/test/ARCMT/autoreleases.m b/clang/test/ARCMT/autoreleases.m new file mode 100644 index 0000000..3acddb7 --- /dev/null +++ b/clang/test/ARCMT/autoreleases.m @@ -0,0 +1,49 @@ +// 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 + +typedef unsigned char BOOL; + +@interface NSObject { + id isa; +} ++new; ++alloc; +-init; +-autorelease; +@end + +@interface NSAutoreleasePool : NSObject +- drain; +@end + +@interface A : NSObject { +@package + id object; +} +@end + +@interface B : NSObject +- (BOOL)containsSelf:(A*)a; +@end + +@implementation A +@end + +@implementation B +- (BOOL)containsSelf:(A*)a { + return a->object == self; +} +@end + +void NSLog(id, ...); + +int main (int argc, const char * argv[]) { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + A *a = [[A new] autorelease]; + B *b = [[B new] autorelease]; + NSLog(@"%s", [b containsSelf:a] ? "YES" : "NO"); + [pool drain]; + return 0; +} diff --git a/clang/test/ARCMT/autoreleases.m.result b/clang/test/ARCMT/autoreleases.m.result new file mode 100644 index 0000000..49bc321 --- /dev/null +++ b/clang/test/ARCMT/autoreleases.m.result @@ -0,0 +1,49 @@ +// 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 + +typedef unsigned char BOOL; + +@interface NSObject { + id isa; +} ++new; ++alloc; +-init; +-autorelease; +@end + +@interface NSAutoreleasePool : NSObject +- drain; +@end + +@interface A : NSObject { +@package + id object; +} +@end + +@interface B : NSObject +- (BOOL)containsSelf:(A*)a; +@end + +@implementation A +@end + +@implementation B +- (BOOL)containsSelf:(A*)a { + return a->object == self; +} +@end + +void NSLog(id, ...); + +int main (int argc, const char * argv[]) { + @autoreleasepool { + A *a = [A new]; + B *b = [B new]; + NSLog(@"%s", [b containsSelf:a] ? "YES" : "NO"); + } + return 0; +} diff --git a/clang/test/ARCMT/check-api.m b/clang/test/ARCMT/check-api.m new file mode 100644 index 0000000..11f4313 --- /dev/null +++ b/clang/test/ARCMT/check-api.m @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-macosx10.7 %s + +#include "Common.h" + +@interface NSInvocation : NSObject +- (void)getReturnValue:(void *)retLoc; +- (void)setReturnValue:(void *)retLoc; + +- (void)getArgument:(void *)argumentLocation atIndex:(int)idx; +- (void)setArgument:(void *)argumentLocation atIndex:(int)idx; +@end + +@interface Test +@end + +@implementation Test { + id strong_id; + __weak id weak_id; + __unsafe_unretained id unsafe_id; + int arg; +} +- (void) test:(NSInvocation *)invok { + [invok getReturnValue:&strong_id]; // expected-error {{NSInvocation's getReturnValue is not safe to be used with an object with ownership other than __unsafe_unretained}} + [invok getReturnValue:&weak_id]; // expected-error {{NSInvocation's getReturnValue is not safe to be used with an object with ownership other than __unsafe_unretained}} + [invok getReturnValue:&unsafe_id]; + [invok getReturnValue:&arg]; + + [invok setReturnValue:&strong_id]; // expected-error {{NSInvocation's setReturnValue is not safe to be used with an object with ownership other than __unsafe_unretained}} + [invok setReturnValue:&weak_id]; // expected-error {{NSInvocation's setReturnValue is not safe to be used with an object with ownership other than __unsafe_unretained}} + [invok setReturnValue:&unsafe_id]; + [invok setReturnValue:&arg]; + + [invok getArgument:&strong_id atIndex:0]; // expected-error {{NSInvocation's getArgument is not safe to be used with an object with ownership other than __unsafe_unretained}} + [invok getArgument:&weak_id atIndex:0]; // expected-error {{NSInvocation's getArgument is not safe to be used with an object with ownership other than __unsafe_unretained}} + [invok getArgument:&unsafe_id atIndex:0]; + [invok getArgument:&arg atIndex:0]; + + [invok setArgument:&strong_id atIndex:0]; // expected-error {{NSInvocation's setArgument is not safe to be used with an object with ownership other than __unsafe_unretained}} + [invok setArgument:&weak_id atIndex:0]; // expected-error {{NSInvocation's setArgument is not safe to be used with an object with ownership other than __unsafe_unretained}} + [invok setArgument:&unsafe_id atIndex:0]; + [invok setArgument:&arg atIndex:0]; +} +@end diff --git a/clang/test/ARCMT/check-with-serialized-diag.m b/clang/test/ARCMT/check-with-serialized-diag.m new file mode 100644 index 0000000..d8073d0 --- /dev/null +++ b/clang/test/ARCMT/check-with-serialized-diag.m @@ -0,0 +1,55 @@ + +@protocol NSObject +- (id)retain; +- (unsigned)retainCount; +- (oneway void)release; +- (id)autorelease; +@end + +@interface NSObject <NSObject> {} +- (id)init; + ++ (id)new; ++ (id)alloc; +- (void)dealloc; + +- (void)finalize; + +- (id)copy; +- (id)mutableCopy; +@end + +@interface A : NSObject +@end + +struct UnsafeS { + A *__unsafe_unretained unsafeObj; +}; + +id global_foo; + +void test1(A *a, struct UnsafeS *unsafeS) { + [unsafeS->unsafeObj retain]; + id foo = [unsafeS->unsafeObj retain]; // no warning. + [global_foo retain]; + [a retainCount]; +} + +// RUN: not %clang_cc1 -arcmt-check -triple x86_64-apple-darwin10 %s -serialize-diagnostic-file %t.diag +// RUN: c-index-test -read-diagnostics %t.diag > %t 2>&1 +// RUN: FileCheck --input-file=%t %s + +// CHECK: {{.*}}check-with-serialized-diag.m:32:4: error: [rewriter] it is not safe to remove 'retain' message on an __unsafe_unretained type +// CHECK-NEXT: Number FIXITs = 0 +// CHECK-NEXT: {{.*}}check-with-serialized-diag.m:34:4: error: [rewriter] it is not safe to remove 'retain' message on a global variable +// CHECK-NEXT: Number FIXITs = 0 +// CHECK-NEXT: {{.*}}check-with-serialized-diag.m:32:4: error: ARC forbids explicit message send of 'retain' +// CHECK-NEXT: Range: {{.*}}check-with-serialized-diag.m:32:23 {{.*}}check-with-serialized-diag.m:32:29 +// CHECK-NEXT: Number FIXITs = 0 +// CHECK-NEXT: {{.*}}check-with-serialized-diag.m:34:4: error: ARC forbids explicit message send of 'retain' +// CHECK-NEXT: Range: {{.*}}check-with-serialized-diag.m:34:15 {{.*}}check-with-serialized-diag.m:34:21 +// CHECK-NEXT: Number FIXITs = 0 +// CHECK-NEXT: {{.*}}check-with-serialized-diag.m:35:4: error: ARC forbids explicit message send of 'retainCount' +// CHECK-NEXT: Range: {{.*}}check-with-serialized-diag.m:35:6 {{.*}}check-with-serialized-diag.m:35:17 +// CHECK-NEXT: Number FIXITs = 0 + diff --git a/clang/test/ARCMT/checking.m b/clang/test/ARCMT/checking.m new file mode 100644 index 0000000..cf71611 --- /dev/null +++ b/clang/test/ARCMT/checking.m @@ -0,0 +1,327 @@ +// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 %s +// DISABLE: mingw32 + +#if __has_feature(objc_arc) +#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode"))) +#else +#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE +#endif + +typedef const void * CFTypeRef; +CFTypeRef CFBridgingRetain(id X); +id CFBridgingRelease(CFTypeRef); + +typedef int BOOL; +typedef unsigned NSUInteger; + +@protocol NSObject +- (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (NSUInteger)retainCount NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +- (id)autorelease NS_AUTOMATED_REFCOUNT_UNAVAILABLE; +@end + +@interface NSObject <NSObject> {} +- (id)init; + ++ (id)new; ++ (id)alloc; +- (void)dealloc; + +- (void)finalize; + +- (id)copy; +- (id)mutableCopy; +@end + +typedef const struct __CFString * CFStringRef; +extern const CFStringRef kUTTypePlainText; +extern const CFStringRef kUTTypeRTF; +@class NSString; +@class A; + +struct UnsafeS { + A *__unsafe_unretained unsafeObj; +}; + +@interface A : NSObject +- (id)retain; +- (id)retainCount; +- (id)autorelease; +- (id)init; +- (oneway void)release; +- (void)dealloc; +-(void)test; +-(id)delegate; +@end + +@implementation A +-(void)test { + [super dealloc]; +} +-(void)dealloc { + [super dealloc]; +} + +- (id)retain { return self; } // expected-error {{ARC forbids implementation}} +- (id)retainCount { return self; } // expected-error {{ARC forbids implementation}} +- (id)autorelease { return self; } // expected-error {{ARC forbids implementation}} +- (oneway void)release { } // expected-error {{ARC forbids implementation}} + +-(id)delegate { return self; } +@end + +id global_foo; + +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}} + [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}} + 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}} + [global_foo release]; // expected-error {{it is not safe to remove 'release' message on a global variable}} \ + // expected-error {{ARC forbids explicit message send}} + [a dealloc]; + [a retain]; + [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}} + [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}} + + 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}} \ + // 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}} \ + str = (NSString *)kUTTypePlainText; + str = b ? kUTTypeRTF : kUTTypePlainText; + str = (NSString *)(b ? kUTTypeRTF : kUTTypePlainText); + str = (NSString *)a; // no change. + + SEL s = @selector(retain); // expected-error {{ARC forbids use of 'retain' in a @selector}} + s = @selector(release); // expected-error {{ARC forbids use of 'release' in a @selector}} + s = @selector(autorelease); // expected-error {{ARC forbids use of 'autorelease' in a @selector}} + s = @selector(dealloc); // expected-error {{ARC forbids use of 'dealloc' in a @selector}} + + static id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}} +} + +struct S { + A* a; // expected-error {{ARC forbids Objective-C objects in structs or unions}} +}; + +@interface B +-(id)alloc; +- (id)initWithInt: (int) i; +@end + +void rdar8861761() { + B *o1 = [[B alloc] initWithInt:0]; + B *o2 = [B alloc]; + [o2 initWithInt:0]; +} + +@interface Test13 +- (id) init0; +- (void) noninit; +@end +@implementation Test13 +- (id) init0 { + self = 0; +} +- (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'}} + x = 0; + } +} +@end + +void * cvt(id arg) +{ + void* voidp_val; + (void)(int*)arg; // expected-error {{disallowed}} + (void)(id)arg; + (void)(__autoreleasing id*)arg; // expected-error {{disallowed}} + (void)(id*)arg; // expected-error {{disallowed}} + + (void)(__autoreleasing id**)voidp_val; + (void)(void*)voidp_val; + (void)(void**)arg; // expected-error {{disallowed}} + cvt((void*)arg); // expected-error 2 {{requires a bridged cast}} \ + // expected-note 2 {{use __bridge to}} expected-note {{use CFBridgingRelease call}} expected-note {{use CFBridgingRetain call}} + cvt(0); + (void)(__strong id**)(0); + return arg; // expected-error {{requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgingRetain call}} +} + + +void test12(id collection) { + for (id x in collection) { + x = 0; + } + + for (__strong id x in collection) { + x = 0; + } +} + +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}} + break; + } +} + +@class Test8_incomplete; +@interface Test8_complete @end; +@interface Test8_super @end; +@interface Test8 : Test8_super +- (id) init00; +- (id) init01; // expected-note {{declaration in interface}} +- (id) init02; +- (id) init03; // covariance +- (id) init04; // covariance +- (id) init05; + +- (void) init10; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}} +- (void) init11; +- (void) init12; +- (void) init13; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}} +- (void) init14; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}} +- (void) init15; + +// These should be invalid to actually call. +- (Test8_incomplete*) init20; +- (Test8_incomplete*) init21; // expected-note {{declaration in interface}} +- (Test8_incomplete*) init22; +- (Test8_incomplete*) init23; +- (Test8_incomplete*) init24; +- (Test8_incomplete*) init25; + +- (Test8_super*) init30; // id exception to covariance +- (Test8_super*) init31; // expected-note {{declaration in interface}} +- (Test8_super*) init32; +- (Test8_super*) init33; +- (Test8_super*) init34; // covariance +- (Test8_super*) init35; + +- (Test8*) init40; // id exception to covariance +- (Test8*) init41; // expected-note {{declaration in interface}} +- (Test8*) init42; +- (Test8*) init43; // this should be a warning, but that's a general language thing, not an ARC thing +- (Test8*) init44; +- (Test8*) init45; + +- (Test8_complete*) init50; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init51; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init52; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init53; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init54; // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init55; // expected-error {{init methods must return a type related to the receiver type}} +@end +@implementation Test8 +- (id) init00 { return 0; } +- (id) init10 { return 0; } // expected-error {{method implementation does not match its declaration}} +- (id) init20 { return 0; } +- (id) init30 { return 0; } +- (id) init40 { return 0; } +- (id) init50 { return 0; } + +- (void) init01 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} +- (void) init11 {} +- (void) init21 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} +- (void) init31 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} +- (void) init41 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} +- (void) init51 {} + +- (Test8_incomplete*) init02 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_incomplete*) init12 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_incomplete*) init22 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_incomplete*) init32 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_incomplete*) init42 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_incomplete*) init52 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} + +- (Test8_super*) init03 { return 0; } +- (Test8_super*) init13 { return 0; } // expected-error {{method implementation does not match its declaration}} +- (Test8_super*) init23 { return 0; } +- (Test8_super*) init33 { return 0; } +- (Test8_super*) init43 { return 0; } +- (Test8_super*) init53 { return 0; } + +- (Test8*) init04 { return 0; } +- (Test8*) init14 { return 0; } // expected-error {{method implementation does not match its declaration}} +- (Test8*) init24 { return 0; } +- (Test8*) init34 { return 0; } +- (Test8*) init44 { return 0; } +- (Test8*) init54 { return 0; } + +- (Test8_complete*) init05 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init15 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init25 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init35 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init45 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +- (Test8_complete*) init55 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} +@end + +@class Test9_incomplete; +@interface Test9 +- (Test9_incomplete*) init1; // expected-error {{init methods must return a type related to the receiver type}} +- (Test9_incomplete*) init2; +@end +id test9(Test9 *v) { + return [v init1]; +} + +// rdar://9491791 +void rdar9491791(int p) { + switch (p) { + case 3:; + NSObject *o = [[NSObject alloc] init]; // expected-note {{jump bypasses initialization of retaining variable}} + [o release]; + break; + default: // expected-error {{switch case is in protected scope}} + break; + } +} + +#define RELEASE_MACRO(x) do { [x release]; } while(1) + +// rdar://9504750 +void rdar9504750(id p) { + RELEASE_MACRO(p); // expected-error {{ARC forbids explicit message send of 'release'}} +} + +// rdar://8939557 +@interface TestReadonlyProperty : NSObject +@property(assign,readonly) NSObject *value; +@end + +@implementation TestReadonlyProperty +@synthesize value; +- (void)viewDidLoad { + value = [NSObject new]; // expected-error {{assigning retained object}} +} +@end + +// 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/clang/test/ARCMT/cxx-checking.mm b/clang/test/ARCMT/cxx-checking.mm new file mode 100644 index 0000000..9f9e3d8 --- /dev/null +++ b/clang/test/ARCMT/cxx-checking.mm @@ -0,0 +1,106 @@ +// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fsyntax-only -fblocks -Warc-abi %s +// DISABLE: mingw32 + +// Classes that have an Objective-C object pointer. +struct HasObjectMember0 { // expected-warning{{'HasObjectMember0' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + id x; +}; + +struct HasObjectMember1 { // expected-warning{{'HasObjectMember1' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + id x[3]; +}; + +struct HasObjectMember2 { // expected-warning{{'HasObjectMember2' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + id x[3][2]; +}; + +// Don't complain if the type has non-external linkage +namespace { + struct HasObjectMember3 { + id x[3][2]; + }; +} + +// Don't complain if the Objective-C pointer type was explicitly given +// no lifetime. +struct HasObjectMember3 { + __unsafe_unretained id x[3][2]; +}; + +struct HasBlockPointerMember0 { // expected-warning{{'HasBlockPointerMember0' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + int (^bp)(int); +}; + +struct HasBlockPointerMember1 { // expected-warning{{'HasBlockPointerMember1' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} + int (^bp[2][3])(int); +}; + +struct NonPOD { + NonPOD(const NonPOD&); +}; + +struct HasObjectMemberAndNonPOD0 { // expected-warning{{'HasObjectMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ + // expected-warning{{'HasObjectMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + id x; + NonPOD np; +}; + +struct HasObjectMemberAndNonPOD1 { // expected-warning{{'HasObjectMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ + // expected-warning{{'HasObjectMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + NonPOD np; + id x[3]; +}; + +struct HasObjectMemberAndNonPOD2 { // expected-warning{{'HasObjectMemberAndNonPOD2' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ + // expected-warning{{'HasObjectMemberAndNonPOD2' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + NonPOD np; + id x[3][2]; +}; + +struct HasObjectMemberAndNonPOD3 { + HasObjectMemberAndNonPOD3 &operator=(const HasObjectMemberAndNonPOD3&); + ~HasObjectMemberAndNonPOD3(); + NonPOD np; + id x[3][2]; +}; + +struct HasBlockPointerMemberAndNonPOD0 { // expected-warning{{'HasBlockPointerMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ +// expected-warning{{'HasBlockPointerMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + NonPOD np; + int (^bp)(int); +}; + +struct HasBlockPointerMemberAndNonPOD1 { // expected-warning{{'HasBlockPointerMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ +// expected-warning{{'HasBlockPointerMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} + NonPOD np; + int (^bp[2][3])(int); +}; + +int check_non_pod_objc_pointer0[__is_pod(id)? 1 : -1]; +int check_non_pod_objc_pointer1[__is_pod(__strong id)? -1 : 1]; +int check_non_pod_objc_pointer2[__is_pod(__unsafe_unretained id)? 1 : -1]; +int check_non_pod_objc_pointer3[__is_pod(id[2][3])? 1 : -1]; +int check_non_pod_objc_pointer4[__is_pod(__unsafe_unretained id[2][3])? 1 : -1]; +int check_non_pod_block0[__is_pod(int (^)(int))? 1 : -1]; +int check_non_pod_block1[__is_pod(int (^ __unsafe_unretained)(int))? 1 : -1]; + +struct FlexibleArrayMember0 { + int length; + id array[]; // expected-error{{flexible array member 'array' of non-POD element type 'id __strong[]'}} +}; + +struct FlexibleArrayMember1 { + int length; + __unsafe_unretained id array[]; +}; + +// It's okay to pass a retainable type through an ellipsis. +void variadic(...); +void test_variadic() { + variadic(1, 17, @"Foo"); +} + +// It's okay to create a VLA of retainable types. +void vla(int n) { + id vla[n]; +} diff --git a/clang/test/ARCMT/cxx-rewrite.mm b/clang/test/ARCMT/cxx-rewrite.mm new file mode 100644 index 0000000..92bb718 --- /dev/null +++ b/clang/test/ARCMT/cxx-rewrite.mm @@ -0,0 +1,34 @@ +// 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" + +@interface NSString : NSObject ++(id)string; +@end + +struct foo { + NSString *s; + foo(NSString *s): s([s retain]){ + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + [[[NSString string] retain] release]; + [pool drain]; + if (s) + [s release]; + } + ~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; +} diff --git a/clang/test/ARCMT/cxx-rewrite.mm.result b/clang/test/ARCMT/cxx-rewrite.mm.result new file mode 100644 index 0000000..a2dc9a5 --- /dev/null +++ b/clang/test/ARCMT/cxx-rewrite.mm.result @@ -0,0 +1,32 @@ +// 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" + +@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; +} diff --git a/clang/test/ARCMT/dealloc.m b/clang/test/ARCMT/dealloc.m new file mode 100644 index 0000000..34df1a4 --- /dev/null +++ b/clang/test/ARCMT/dealloc.m @@ -0,0 +1,25 @@ +// 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 + +@interface A +- (id)retain; +- (id)autorelease; +- (oneway void)release; +- (void)dealloc; +@end + +void test1(A *a) { + [a dealloc]; +} + +@interface Test2 : A +- (void) dealloc; +@end + +@implementation Test2 +- (void) dealloc { + [super dealloc]; +} +@end diff --git a/clang/test/ARCMT/dealloc.m.result b/clang/test/ARCMT/dealloc.m.result new file mode 100644 index 0000000..3ff2885 --- /dev/null +++ b/clang/test/ARCMT/dealloc.m.result @@ -0,0 +1,21 @@ +// 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 + +@interface A +- (id)retain; +- (id)autorelease; +- (oneway void)release; +- (void)dealloc; +@end + +void test1(A *a) { +} + +@interface Test2 : A +- (void) dealloc; +@end + +@implementation Test2 +@end diff --git a/clang/test/ARCMT/dispatch.m b/clang/test/ARCMT/dispatch.m new file mode 100644 index 0000000..75c4a83 --- /dev/null +++ b/clang/test/ARCMT/dispatch.m @@ -0,0 +1,29 @@ +// 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" + +#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) { + dispatch_retain(o); + dispatch_release(o); + dispatch_retain(getme()); +} + +void func2(xpc_object_t o) { + xpc_retain(o); + xpc_release(o); +} diff --git a/clang/test/ARCMT/dispatch.m.result b/clang/test/ARCMT/dispatch.m.result new file mode 100644 index 0000000..e897672 --- /dev/null +++ b/clang/test/ARCMT/dispatch.m.result @@ -0,0 +1,25 @@ +// 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" + +#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) { + getme(); +} + +void func2(xpc_object_t o) { +} diff --git a/clang/test/ARCMT/driver-migrate.m b/clang/test/ARCMT/driver-migrate.m new file mode 100644 index 0000000..a912ad9 --- /dev/null +++ b/clang/test/ARCMT/driver-migrate.m @@ -0,0 +1,12 @@ +// RUN: %clang -### -ccc-arcmt-migrate /foo/bar -fsyntax-only %s 2>&1 | FileCheck %s + +// CHECK: "-arcmt-migrate" "-mt-migrate-directory" "{{[^"]*}}/foo/bar" + +// RUN: touch %t.o +// RUN: %clang -ccc-arcmt-check -target i386-apple-darwin9 -### %t.o 2> %t.log +// RUN: FileCheck -check-prefix=LINK %s < %t.log +// RUN: %clang -ccc-arcmt-migrate /foo/bar -target i386-apple-darwin9 -### %t.o 2> %t.log +// RUN: FileCheck -check-prefix=LINK %s < %t.log + +// LINK-NOT: {{ld(.exe)?"}} +// LINK: {{touch(.exe)?"}} diff --git a/clang/test/ARCMT/init.m b/clang/test/ARCMT/init.m new file mode 100644 index 0000000..9dbb1f8 --- /dev/null +++ b/clang/test/ARCMT/init.m @@ -0,0 +1,40 @@ +// 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 + +#define nil (void *)0 + +@interface NSObject +-init; +@end + +@interface A : NSObject +-init; +-init2; +-foo; ++alloc; +@end + +@implementation A +-(id) init { + [self init]; + id a; + [a init]; + a = [[A alloc] init]; + + return self; +} + +-(id) init2 { + [super init]; + return self; +} + +-(id) foo { + [self init]; + [super init]; + + return self; +} +@end diff --git a/clang/test/ARCMT/init.m.result b/clang/test/ARCMT/init.m.result new file mode 100644 index 0000000..d7f7300 --- /dev/null +++ b/clang/test/ARCMT/init.m.result @@ -0,0 +1,40 @@ +// 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 + +#define nil (void *)0 + +@interface NSObject +-init; +@end + +@interface A : NSObject +-init; +-init2; +-foo; ++alloc; +@end + +@implementation A +-(id) init { + if (!(self = [self init])) return nil; + id a; + [a init]; + a = [[A alloc] init]; + + return self; +} + +-(id) init2 { + if (!(self = [super init])) return nil; + return self; +} + +-(id) foo { + [self init]; + [super init]; + + return self; +} +@end diff --git a/clang/test/ARCMT/migrate-emit-errors.m b/clang/test/ARCMT/migrate-emit-errors.m new file mode 100644 index 0000000..95c0d2f --- /dev/null +++ b/clang/test/ARCMT/migrate-emit-errors.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -arcmt-migrate -mt-migrate-directory %t -arcmt-migrate-emit-errors %s 2>&1 | FileCheck %s +// RUN: rm -rf %t + +@protocol NSObject +- (oneway void)release; +@end + +void test(id p) { + [p release]; +} + +// CHECK: error: ARC forbids explicit message send of 'release'
\ No newline at end of file diff --git a/clang/test/ARCMT/migrate-plist-output.m b/clang/test/ARCMT/migrate-plist-output.m new file mode 100644 index 0000000..12efa93 --- /dev/null +++ b/clang/test/ARCMT/migrate-plist-output.m @@ -0,0 +1,52 @@ +// RUN: %clang_cc1 -arcmt-migrate -mt-migrate-directory %t.dir -arcmt-migrate-report-output %t.plist %s +// RUN: FileCheck %s -input-file=%t.plist +// RUN: rm -rf %t.dir + +@protocol NSObject +- (oneway void)release; +@end + +void test(id p) { + [p release]; +} + +// CHECK: <?xml version="1.0" encoding="UTF-8"?> +// CHECK: <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +// CHECK: <plist version="1.0"> +// CHECK: <dict> +// CHECK: <key>files</key> +// CHECK: <array> +// CHECK: </array> +// CHECK: <key>diagnostics</key> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>description</key><string>ARC forbids explicit message send of 'release'</string> +// CHECK: <key>category</key><string>ARC Restrictions</string> +// CHECK: <key>type</key><string>error</string> +// CHECK: <key>location</key> +// CHECK: <dict> +// CHECK: <key>line</key><integer>10</integer> +// CHECK: <key>col</key><integer>4</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <key>ranges</key> +// CHECK: <array> +// CHECK: <array> +// CHECK: <dict> +// CHECK: <key>line</key><integer>10</integer> +// CHECK: <key>col</key><integer>6</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: <dict> +// CHECK: <key>line</key><integer>10</integer> +// CHECK: <key>col</key><integer>12</integer> +// CHECK: <key>file</key><integer>0</integer> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </array> +// CHECK: </dict> +// CHECK: </plist> + +// DISABLE: mingw32 diff --git a/clang/test/ARCMT/migrate-space-in-path.m b/clang/test/ARCMT/migrate-space-in-path.m new file mode 100644 index 0000000..89dfe14 --- /dev/null +++ b/clang/test/ARCMT/migrate-space-in-path.m @@ -0,0 +1,6 @@ +// RUN: rm -rf %t.migrate +// RUN: %clang_cc1 -arcmt-migrate -mt-migrate-directory %t.migrate %S/"with space"/test1.m.in -x objective-c +// RUN: %clang_cc1 -arcmt-migrate -mt-migrate-directory %t.migrate %S/"with space"/test2.m.in -x objective-c +// RUN: c-arcmt-test -mt-migrate-directory %t.migrate | arcmt-test -verify-transformed-files %S/"with space"/test1.m.in.result %S/"with space"/test2.m.in.result %S/"with space"/test.h.result +// RUN: rm -rf %t.migrate +// DISABLE: mingw32 diff --git a/clang/test/ARCMT/migrate.m b/clang/test/ARCMT/migrate.m new file mode 100644 index 0000000..6f41258 --- /dev/null +++ b/clang/test/ARCMT/migrate.m @@ -0,0 +1,6 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -arcmt-migrate -mt-migrate-directory %t %S/Inputs/test1.m.in -x objective-c +// RUN: %clang_cc1 -arcmt-migrate -mt-migrate-directory %t %S/Inputs/test2.m.in -x objective-c +// 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/clang/test/ARCMT/no-canceling-bridge-to-bridge-cast.m b/clang/test/ARCMT/no-canceling-bridge-to-bridge-cast.m new file mode 100644 index 0000000..81841fb --- /dev/null +++ b/clang/test/ARCMT/no-canceling-bridge-to-bridge-cast.m @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -arcmt-check -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -verify %s +// DISABLE: mingw32 +// rdar://10387088 +typedef const void * CFTypeRef; +CFTypeRef CFBridgingRetain(id X); +id CFBridgingRelease(CFTypeRef); + +extern +CFTypeRef CFRetain(CFTypeRef cf); + +@interface INTF +{ + void *cf_format; + id objc_format; +} +@end + +@interface NSString ++ (id)stringWithFormat:(NSString *)format; +@end + +@implementation INTF +- (void) Meth { + NSString *result; + + result = (id) CFRetain([NSString stringWithFormat:@"PBXLoopMode"]); // expected-error {{cast of C pointer type 'CFTypeRef' (aka 'const void *') 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 'CFTypeRef' (aka 'const void *') into ARC}} + + result = (id) CFRetain((id)((objc_format))); // expected-error {{cast of C pointer type 'CFTypeRef' (aka 'const void *') 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 'CFTypeRef' (aka 'const void *') into ARC}} + + result = (id) CFRetain((id)((cf_format))); // expected-error {{cast of C pointer type 'CFTypeRef' (aka 'const void *') 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 'CFTypeRef' (aka 'const void *') into ARC}} + + result = (id) CFRetain((CFTypeRef)((objc_format))); + + result = (id) CFRetain(cf_format); // OK +} +@end + diff --git a/clang/test/ARCMT/nonobjc-to-objc-cast-2.m b/clang/test/ARCMT/nonobjc-to-objc-cast-2.m new file mode 100644 index 0000000..1ec0089 --- /dev/null +++ b/clang/test/ARCMT/nonobjc-to-objc-cast-2.m @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 %s +// DISABLE: mingw32 + +#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); + +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}} \ + // 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}} + void *vp = str; // expected-error {{requires a bridged cast}} expected-note {{use CFBridgingRetain call}} expected-note {{use __bridge}} +} + +void f2(NSString *s) { + CFStringRef ref; + ref = [(CFStringRef)[s string] retain]; // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast}} \ + // expected-error {{bad receiver type 'CFStringRef' (aka 'const struct __CFString *')}} \ + // 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 *')}} +} + +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}} +} diff --git a/clang/test/ARCMT/nonobjc-to-objc-cast.m b/clang/test/ARCMT/nonobjc-to-objc-cast.m new file mode 100644 index 0000000..fcdcd89 --- /dev/null +++ b/clang/test/ARCMT/nonobjc-to-objc-cast.m @@ -0,0 +1,62 @@ +// 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" + +@interface NSString : NSObject +-(id)string; +-(id)newString; +@end + +typedef const struct __CFString * CFStringRef; +extern const CFStringRef kUTTypePlainText; +extern const CFStringRef kUTTypeRTF; + +typedef const struct __CFAllocator * CFAllocatorRef; +typedef const struct __CFUUID * CFUUIDRef; + +extern const CFAllocatorRef kCFAllocatorDefault; + +extern CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid); + +void f(BOOL b, id p) { + NSString *str = (NSString *)kUTTypePlainText; + str = b ? kUTTypeRTF : kUTTypePlainText; + str = (NSString *)(b ? kUTTypeRTF : kUTTypePlainText); + str = (NSString *)p; // no change. + + CFUUIDRef _uuid; + NSString *_uuidString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid); + _uuidString = [(NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid) autorelease]; + _uuidString = CFRetain(_uuid); +} + +@implementation NSString (StrExt) +- (NSString *)stringEscapedAsURI { + CFStringRef str = (CFStringRef)self; + CFStringRef str2 = self; + return self; +} +@end + +extern void consumeParam(CFStringRef CF_CONSUMED p); + +void f2(NSString *s) { + CFStringRef ref = [s string]; + ref = (CFStringRef)[s string]; + ref = s.string; + ref = [NSString new]; + ref = [s newString]; + ref = (CFStringRef)[NSString new]; + ref = [[NSString alloc] init]; + ref = [[s string] retain]; + ref = CFRetain((CFStringRef)[s string]); + ref = CFRetain([s string]); + ref = CFRetain(s); + ref = [s retain]; + + consumeParam((CFStringRef)s); + consumeParam(s); +} diff --git a/clang/test/ARCMT/nonobjc-to-objc-cast.m.result b/clang/test/ARCMT/nonobjc-to-objc-cast.m.result new file mode 100644 index 0000000..b50a948 --- /dev/null +++ b/clang/test/ARCMT/nonobjc-to-objc-cast.m.result @@ -0,0 +1,62 @@ +// 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" + +@interface NSString : NSObject +-(id)string; +-(id)newString; +@end + +typedef const struct __CFString * CFStringRef; +extern const CFStringRef kUTTypePlainText; +extern const CFStringRef kUTTypeRTF; + +typedef const struct __CFAllocator * CFAllocatorRef; +typedef const struct __CFUUID * CFUUIDRef; + +extern const CFAllocatorRef kCFAllocatorDefault; + +extern CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid); + +void f(BOOL b, id p) { + NSString *str = (__bridge NSString *)kUTTypePlainText; + str = (__bridge NSString *)(b ? kUTTypeRTF : kUTTypePlainText); + str = (__bridge NSString *)(b ? kUTTypeRTF : kUTTypePlainText); + 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)); +} + +@implementation NSString (StrExt) +- (NSString *)stringEscapedAsURI { + CFStringRef str = (__bridge CFStringRef)self; + CFStringRef str2 = (__bridge CFStringRef)(self); + return self; +} +@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)); +} diff --git a/clang/test/ARCMT/objcmt-numeric-literals.m b/clang/test/ARCMT/objcmt-numeric-literals.m new file mode 100644 index 0000000..b86af4d --- /dev/null +++ b/clang/test/ARCMT/objcmt-numeric-literals.m @@ -0,0 +1,501 @@ +// 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 + +#define YES __objc_yes +#define NO __objc_no + +typedef long NSInteger; +typedef unsigned long NSUInteger; +typedef signed char BOOL; +#define nil ((void*) 0) + +@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 + +#define VAL_INT 2 +#define VAL_UINT 2U +#define VAL_CHAR 'a' + +void foo() { + [NSNumber numberWithChar:'a']; + [NSNumber numberWithChar:L'a']; + [NSNumber numberWithChar:2]; + [NSNumber numberWithChar:2U]; + [NSNumber numberWithChar:2u]; + [NSNumber numberWithChar:2L]; + [NSNumber numberWithChar:2l]; + [NSNumber numberWithChar:2LL]; + [NSNumber numberWithChar:2ll]; + [NSNumber numberWithChar:2ul]; + [NSNumber numberWithChar:2lu]; + [NSNumber numberWithChar:2ull]; + [NSNumber numberWithChar:2llu]; + [NSNumber numberWithChar:2.0]; + [NSNumber numberWithChar:2.0f]; + [NSNumber numberWithChar:2.0F]; + [NSNumber numberWithChar:2.0l]; + [NSNumber numberWithChar:2.0L]; + [NSNumber numberWithChar:0x2f]; + [NSNumber numberWithChar:04]; + [NSNumber numberWithChar:0]; + [NSNumber numberWithChar:0.0]; + [NSNumber numberWithChar:YES]; + [NSNumber numberWithChar:NO]; + [NSNumber numberWithChar:true]; + [NSNumber numberWithChar:false]; + [NSNumber numberWithChar:VAL_INT]; + [NSNumber numberWithChar:VAL_UINT]; + [NSNumber numberWithChar:VAL_CHAR]; + + [NSNumber numberWithUnsignedChar:'a']; + [NSNumber numberWithUnsignedChar:L'a']; + [NSNumber numberWithUnsignedChar:2]; + [NSNumber numberWithUnsignedChar:2U]; + [NSNumber numberWithUnsignedChar:2u]; + [NSNumber numberWithUnsignedChar:2L]; + [NSNumber numberWithUnsignedChar:2l]; + [NSNumber numberWithUnsignedChar:2LL]; + [NSNumber numberWithUnsignedChar:2ll]; + [NSNumber numberWithUnsignedChar:2ul]; + [NSNumber numberWithUnsignedChar:2lu]; + [NSNumber numberWithUnsignedChar:2ull]; + [NSNumber numberWithUnsignedChar:2llu]; + [NSNumber numberWithUnsignedChar:2.0]; + [NSNumber numberWithUnsignedChar:2.0f]; + [NSNumber numberWithUnsignedChar:2.0F]; + [NSNumber numberWithUnsignedChar:2.0l]; + [NSNumber numberWithUnsignedChar:2.0L]; + [NSNumber numberWithUnsignedChar:0x2f]; + [NSNumber numberWithUnsignedChar:04]; + [NSNumber numberWithUnsignedChar:0]; + [NSNumber numberWithUnsignedChar:0.0]; + [NSNumber numberWithUnsignedChar:YES]; + [NSNumber numberWithUnsignedChar:NO]; + [NSNumber numberWithUnsignedChar:true]; + [NSNumber numberWithUnsignedChar:false]; + [NSNumber numberWithUnsignedChar:VAL_INT]; + [NSNumber numberWithUnsignedChar:VAL_UINT]; + [NSNumber numberWithUnsignedChar:VAL_CHAR]; + + [NSNumber numberWithShort:'a']; + [NSNumber numberWithShort:L'a']; + [NSNumber numberWithShort:2]; + [NSNumber numberWithShort:2U]; + [NSNumber numberWithShort:2u]; + [NSNumber numberWithShort:2L]; + [NSNumber numberWithShort:2l]; + [NSNumber numberWithShort:2LL]; + [NSNumber numberWithShort:2ll]; + [NSNumber numberWithShort:2ul]; + [NSNumber numberWithShort:2lu]; + [NSNumber numberWithShort:2ull]; + [NSNumber numberWithShort:2llu]; + [NSNumber numberWithShort:2.0]; + [NSNumber numberWithShort:2.0f]; + [NSNumber numberWithShort:2.0F]; + [NSNumber numberWithShort:2.0l]; + [NSNumber numberWithShort:2.0L]; + [NSNumber numberWithShort:0x2f]; + [NSNumber numberWithShort:04]; + [NSNumber numberWithShort:0]; + [NSNumber numberWithShort:0.0]; + [NSNumber numberWithShort:YES]; + [NSNumber numberWithShort:NO]; + [NSNumber numberWithShort:true]; + [NSNumber numberWithShort:false]; + [NSNumber numberWithShort:VAL_INT]; + [NSNumber numberWithShort:VAL_UINT]; + + [NSNumber numberWithUnsignedShort:'a']; + [NSNumber numberWithUnsignedShort:L'a']; + [NSNumber numberWithUnsignedShort:2]; + [NSNumber numberWithUnsignedShort:2U]; + [NSNumber numberWithUnsignedShort:2u]; + [NSNumber numberWithUnsignedShort:2L]; + [NSNumber numberWithUnsignedShort:2l]; + [NSNumber numberWithUnsignedShort:2LL]; + [NSNumber numberWithUnsignedShort:2ll]; + [NSNumber numberWithUnsignedShort:2ul]; + [NSNumber numberWithUnsignedShort:2lu]; + [NSNumber numberWithUnsignedShort:2ull]; + [NSNumber numberWithUnsignedShort:2llu]; + [NSNumber numberWithUnsignedShort:2.0]; + [NSNumber numberWithUnsignedShort:2.0f]; + [NSNumber numberWithUnsignedShort:2.0F]; + [NSNumber numberWithUnsignedShort:2.0l]; + [NSNumber numberWithUnsignedShort:2.0L]; + [NSNumber numberWithUnsignedShort:0x2f]; + [NSNumber numberWithUnsignedShort:04]; + [NSNumber numberWithUnsignedShort:0]; + [NSNumber numberWithUnsignedShort:0.0]; + [NSNumber numberWithUnsignedShort:YES]; + [NSNumber numberWithUnsignedShort:NO]; + [NSNumber numberWithUnsignedShort:true]; + [NSNumber numberWithUnsignedShort:false]; + [NSNumber numberWithUnsignedShort:VAL_INT]; + [NSNumber numberWithUnsignedShort:VAL_UINT]; + + [NSNumber numberWithInt:'a']; + [NSNumber numberWithInt:L'a']; + [NSNumber numberWithInt:2]; + [NSNumber numberWithInt:2U]; + [NSNumber numberWithInt:2u]; + [NSNumber numberWithInt:2L]; + [NSNumber numberWithInt:2l]; + [NSNumber numberWithInt:2LL]; + [NSNumber numberWithInt:2ll]; + [NSNumber numberWithInt:2ul]; + [NSNumber numberWithInt:2lu]; + [NSNumber numberWithInt:2ull]; + [NSNumber numberWithInt:2llu]; + [NSNumber numberWithInt:2.0]; + [NSNumber numberWithInt:2.0f]; + [NSNumber numberWithInt:2.0F]; + [NSNumber numberWithInt:2.0l]; + [NSNumber numberWithInt:2.0L]; + [NSNumber numberWithInt:0x2f]; + [NSNumber numberWithInt:04]; + [NSNumber numberWithInt:0]; + [NSNumber numberWithInt:0.0]; + [NSNumber numberWithInt:YES]; + [NSNumber numberWithInt:NO]; + [NSNumber numberWithInt:true]; + [NSNumber numberWithInt:false]; + [NSNumber numberWithInt:VAL_INT]; + [NSNumber numberWithInt:VAL_UINT]; + + (void)[[NSNumber alloc] initWithInt:2]; + (void)[[NSNumber alloc] initWithInt:2U]; + + [NSNumber numberWithInt:+2]; + [NSNumber numberWithInt:-2]; + + [NSNumber numberWithUnsignedInt:'a']; + [NSNumber numberWithUnsignedInt:L'a']; + [NSNumber numberWithUnsignedInt:2]; + [NSNumber numberWithUnsignedInt:2U]; + [NSNumber numberWithUnsignedInt:2u]; + [NSNumber numberWithUnsignedInt:2L]; + [NSNumber numberWithUnsignedInt:2l]; + [NSNumber numberWithUnsignedInt:2LL]; + [NSNumber numberWithUnsignedInt:2ll]; + [NSNumber numberWithUnsignedInt:2ul]; + [NSNumber numberWithUnsignedInt:2lu]; + [NSNumber numberWithUnsignedInt:2ull]; + [NSNumber numberWithUnsignedInt:2llu]; + [NSNumber numberWithUnsignedInt:2.0]; + [NSNumber numberWithUnsignedInt:2.0f]; + [NSNumber numberWithUnsignedInt:2.0F]; + [NSNumber numberWithUnsignedInt:2.0l]; + [NSNumber numberWithUnsignedInt:2.0L]; + [NSNumber numberWithUnsignedInt:0x2f]; + [NSNumber numberWithUnsignedInt:04]; + [NSNumber numberWithUnsignedInt:0]; + [NSNumber numberWithUnsignedInt:0.0]; + [NSNumber numberWithUnsignedInt:YES]; + [NSNumber numberWithUnsignedInt:NO]; + [NSNumber numberWithUnsignedInt:true]; + [NSNumber numberWithUnsignedInt:false]; + [NSNumber numberWithUnsignedInt:VAL_INT]; + [NSNumber numberWithUnsignedInt:VAL_UINT]; + + [NSNumber numberWithLong:'a']; + [NSNumber numberWithLong:L'a']; + [NSNumber numberWithLong:2]; + [NSNumber numberWithLong:2U]; + [NSNumber numberWithLong:2u]; + [NSNumber numberWithLong:2L]; + [NSNumber numberWithLong:2l]; + [NSNumber numberWithLong:2LL]; + [NSNumber numberWithLong:2ll]; + [NSNumber numberWithLong:2ul]; + [NSNumber numberWithLong:2lu]; + [NSNumber numberWithLong:2ull]; + [NSNumber numberWithLong:2llu]; + [NSNumber numberWithLong:2.0]; + [NSNumber numberWithLong:2.0f]; + [NSNumber numberWithLong:2.0F]; + [NSNumber numberWithLong:2.0l]; + [NSNumber numberWithLong:2.0L]; + [NSNumber numberWithLong:0x2f]; + [NSNumber numberWithLong:04]; + [NSNumber numberWithLong:0]; + [NSNumber numberWithLong:0.0]; + [NSNumber numberWithLong:YES]; + [NSNumber numberWithLong:NO]; + [NSNumber numberWithLong:true]; + [NSNumber numberWithLong:false]; + [NSNumber numberWithLong:VAL_INT]; + [NSNumber numberWithLong:VAL_UINT]; + + [NSNumber numberWithUnsignedLong:'a']; + [NSNumber numberWithUnsignedLong:L'a']; + [NSNumber numberWithUnsignedLong:2]; + [NSNumber numberWithUnsignedLong:2U]; + [NSNumber numberWithUnsignedLong:2u]; + [NSNumber numberWithUnsignedLong:2L]; + [NSNumber numberWithUnsignedLong:2l]; + [NSNumber numberWithUnsignedLong:2LL]; + [NSNumber numberWithUnsignedLong:2ll]; + [NSNumber numberWithUnsignedLong:2ul]; + [NSNumber numberWithUnsignedLong:2lu]; + [NSNumber numberWithUnsignedLong:2ull]; + [NSNumber numberWithUnsignedLong:2llu]; + [NSNumber numberWithUnsignedLong:2.0]; + [NSNumber numberWithUnsignedLong:2.0f]; + [NSNumber numberWithUnsignedLong:2.0F]; + [NSNumber numberWithUnsignedLong:2.0l]; + [NSNumber numberWithUnsignedLong:2.0L]; + [NSNumber numberWithUnsignedLong:0x2f]; + [NSNumber numberWithUnsignedLong:04]; + [NSNumber numberWithUnsignedLong:0]; + [NSNumber numberWithUnsignedLong:0.0]; + [NSNumber numberWithUnsignedLong:YES]; + [NSNumber numberWithUnsignedLong:NO]; + [NSNumber numberWithUnsignedLong:true]; + [NSNumber numberWithUnsignedLong:false]; + [NSNumber numberWithUnsignedLong:VAL_INT]; + [NSNumber numberWithUnsignedLong:VAL_UINT]; + + [NSNumber numberWithLongLong:'a']; + [NSNumber numberWithLongLong:L'a']; + [NSNumber numberWithLongLong:2]; + [NSNumber numberWithLongLong:2U]; + [NSNumber numberWithLongLong:2u]; + [NSNumber numberWithLongLong:2L]; + [NSNumber numberWithLongLong:2l]; + [NSNumber numberWithLongLong:2LL]; + [NSNumber numberWithLongLong:2ll]; + [NSNumber numberWithLongLong:2ul]; + [NSNumber numberWithLongLong:2lu]; + [NSNumber numberWithLongLong:2ull]; + [NSNumber numberWithLongLong:2llu]; + [NSNumber numberWithLongLong:2.0]; + [NSNumber numberWithLongLong:2.0f]; + [NSNumber numberWithLongLong:2.0F]; + [NSNumber numberWithLongLong:2.0l]; + [NSNumber numberWithLongLong:2.0L]; + [NSNumber numberWithLongLong:0x2f]; + [NSNumber numberWithLongLong:04]; + [NSNumber numberWithLongLong:0]; + [NSNumber numberWithLongLong:0.0]; + [NSNumber numberWithLongLong:YES]; + [NSNumber numberWithLongLong:NO]; + [NSNumber numberWithLongLong:true]; + [NSNumber numberWithLongLong:false]; + [NSNumber numberWithLongLong:VAL_INT]; + [NSNumber numberWithLongLong:VAL_UINT]; + + [NSNumber numberWithUnsignedLongLong:'a']; + [NSNumber numberWithUnsignedLongLong:L'a']; + [NSNumber numberWithUnsignedLongLong:2]; + [NSNumber numberWithUnsignedLongLong:2U]; + [NSNumber numberWithUnsignedLongLong:2u]; + [NSNumber numberWithUnsignedLongLong:2L]; + [NSNumber numberWithUnsignedLongLong:2l]; + [NSNumber numberWithUnsignedLongLong:2LL]; + [NSNumber numberWithUnsignedLongLong:2ll]; + [NSNumber numberWithUnsignedLongLong:2ul]; + [NSNumber numberWithUnsignedLongLong:2lu]; + [NSNumber numberWithUnsignedLongLong:2ull]; + [NSNumber numberWithUnsignedLongLong:2llu]; + [NSNumber numberWithUnsignedLongLong:2.0]; + [NSNumber numberWithUnsignedLongLong:2.0f]; + [NSNumber numberWithUnsignedLongLong:2.0F]; + [NSNumber numberWithUnsignedLongLong:2.0l]; + [NSNumber numberWithUnsignedLongLong:2.0L]; + [NSNumber numberWithUnsignedLongLong:0x2f]; + [NSNumber numberWithUnsignedLongLong:04]; + [NSNumber numberWithUnsignedLongLong:0]; + [NSNumber numberWithUnsignedLongLong:0.0]; + [NSNumber numberWithUnsignedLongLong:YES]; + [NSNumber numberWithUnsignedLongLong:NO]; + [NSNumber numberWithUnsignedLongLong:true]; + [NSNumber numberWithUnsignedLongLong:false]; + [NSNumber numberWithUnsignedLongLong:VAL_INT]; + [NSNumber numberWithUnsignedLongLong:VAL_UINT]; + + [NSNumber numberWithFloat:'a']; + [NSNumber numberWithFloat:L'a']; + [NSNumber numberWithFloat:2]; + [NSNumber numberWithFloat:2U]; + [NSNumber numberWithFloat:2u]; + [NSNumber numberWithFloat:2L]; + [NSNumber numberWithFloat:2l]; + [NSNumber numberWithFloat:2LL]; + [NSNumber numberWithFloat:2ll]; + [NSNumber numberWithFloat:2ul]; + [NSNumber numberWithFloat:2lu]; + [NSNumber numberWithFloat:2ull]; + [NSNumber numberWithFloat:2llu]; + [NSNumber numberWithFloat:2.0]; + [NSNumber numberWithFloat:2.0f]; + [NSNumber numberWithFloat:2.0F]; + [NSNumber numberWithFloat:2.0l]; + [NSNumber numberWithFloat:2.0L]; + [NSNumber numberWithFloat:0x2f]; + [NSNumber numberWithFloat:04]; + [NSNumber numberWithFloat:0]; + [NSNumber numberWithFloat:0.0]; + [NSNumber numberWithFloat:YES]; + [NSNumber numberWithFloat:NO]; + [NSNumber numberWithFloat:true]; + [NSNumber numberWithFloat:false]; + [NSNumber numberWithFloat:VAL_INT]; + [NSNumber numberWithFloat:VAL_UINT]; + + [NSNumber numberWithDouble:'a']; + [NSNumber numberWithDouble:L'a']; + [NSNumber numberWithDouble:2]; + [NSNumber numberWithDouble:2U]; + [NSNumber numberWithDouble:2u]; + [NSNumber numberWithDouble:2L]; + [NSNumber numberWithDouble:2l]; + [NSNumber numberWithDouble:2LL]; + [NSNumber numberWithDouble:2ll]; + [NSNumber numberWithDouble:2ul]; + [NSNumber numberWithDouble:2lu]; + [NSNumber numberWithDouble:2ull]; + [NSNumber numberWithDouble:2llu]; + [NSNumber numberWithDouble:2.0]; + [NSNumber numberWithDouble:2.0f]; + [NSNumber numberWithDouble:2.0F]; + [NSNumber numberWithDouble:2.0l]; + [NSNumber numberWithDouble:2.0L]; + [NSNumber numberWithDouble:0x2f]; + [NSNumber numberWithDouble:04]; + [NSNumber numberWithDouble:0]; + [NSNumber numberWithDouble:0.0]; + [NSNumber numberWithDouble:YES]; + [NSNumber numberWithDouble:NO]; + [NSNumber numberWithDouble:true]; + [NSNumber numberWithDouble:false]; + [NSNumber numberWithDouble:VAL_INT]; + [NSNumber numberWithDouble:VAL_UINT]; + + [NSNumber numberWithBool:'a']; + [NSNumber numberWithBool:L'a']; + [NSNumber numberWithBool:2]; + [NSNumber numberWithBool:2U]; + [NSNumber numberWithBool:2u]; + [NSNumber numberWithBool:2L]; + [NSNumber numberWithBool:2l]; + [NSNumber numberWithBool:2LL]; + [NSNumber numberWithBool:2ll]; + [NSNumber numberWithBool:2ul]; + [NSNumber numberWithBool:2lu]; + [NSNumber numberWithBool:2ull]; + [NSNumber numberWithBool:2llu]; + [NSNumber numberWithBool:2.0]; + [NSNumber numberWithBool:2.0f]; + [NSNumber numberWithBool:2.0F]; + [NSNumber numberWithBool:2.0l]; + [NSNumber numberWithBool:2.0L]; + [NSNumber numberWithBool:0x2f]; + [NSNumber numberWithBool:04]; + [NSNumber numberWithBool:0]; + [NSNumber numberWithBool:0.0]; + [NSNumber numberWithBool:YES]; + [NSNumber numberWithBool:NO]; + [NSNumber numberWithBool:true]; + [NSNumber numberWithBool:false]; + [NSNumber numberWithBool:VAL_INT]; + [NSNumber numberWithBool:VAL_UINT]; + + [NSNumber numberWithInteger:'a']; + [NSNumber numberWithInteger:L'a']; + [NSNumber numberWithInteger:2]; + [NSNumber numberWithInteger:2U]; + [NSNumber numberWithInteger:2u]; + [NSNumber numberWithInteger:2L]; + [NSNumber numberWithInteger:2l]; + [NSNumber numberWithInteger:2LL]; + [NSNumber numberWithInteger:2ll]; + [NSNumber numberWithInteger:2ul]; + [NSNumber numberWithInteger:2lu]; + [NSNumber numberWithInteger:2ull]; + [NSNumber numberWithInteger:2llu]; + [NSNumber numberWithInteger:2.0]; + [NSNumber numberWithInteger:2.0f]; + [NSNumber numberWithInteger:2.0F]; + [NSNumber numberWithInteger:2.0l]; + [NSNumber numberWithInteger:2.0L]; + [NSNumber numberWithInteger:0x2f]; + [NSNumber numberWithInteger:04]; + [NSNumber numberWithInteger:0]; + [NSNumber numberWithInteger:0.0]; + [NSNumber numberWithInteger:YES]; + [NSNumber numberWithInteger:NO]; + [NSNumber numberWithInteger:true]; + [NSNumber numberWithInteger:false]; + [NSNumber numberWithInteger:VAL_INT]; + [NSNumber numberWithInteger:VAL_UINT]; + + [NSNumber numberWithUnsignedInteger:'a']; + [NSNumber numberWithUnsignedInteger:L'a']; + [NSNumber numberWithUnsignedInteger:2]; + [NSNumber numberWithUnsignedInteger:2U]; + [NSNumber numberWithUnsignedInteger:2u]; + [NSNumber numberWithUnsignedInteger:2L]; + [NSNumber numberWithUnsignedInteger:2l]; + [NSNumber numberWithUnsignedInteger:2LL]; + [NSNumber numberWithUnsignedInteger:2ll]; + [NSNumber numberWithUnsignedInteger:2ul]; + [NSNumber numberWithUnsignedInteger:2lu]; + [NSNumber numberWithUnsignedInteger:2ull]; + [NSNumber numberWithUnsignedInteger:2llu]; + [NSNumber numberWithUnsignedInteger:2.0]; + [NSNumber numberWithUnsignedInteger:2.0f]; + [NSNumber numberWithUnsignedInteger:2.0F]; + [NSNumber numberWithUnsignedInteger:2.0l]; + [NSNumber numberWithUnsignedInteger:2.0L]; + [NSNumber numberWithUnsignedInteger:0x2f]; + [NSNumber numberWithUnsignedInteger:04]; + [NSNumber numberWithUnsignedInteger:0]; + [NSNumber numberWithUnsignedInteger:0.0]; + [NSNumber numberWithUnsignedInteger:YES]; + [NSNumber numberWithUnsignedInteger:NO]; + [NSNumber numberWithUnsignedInteger:true]; + [NSNumber numberWithUnsignedInteger:false]; + [NSNumber numberWithUnsignedInteger:VAL_INT]; + [NSNumber numberWithUnsignedInteger:VAL_UINT]; +} diff --git a/clang/test/ARCMT/objcmt-numeric-literals.m.result b/clang/test/ARCMT/objcmt-numeric-literals.m.result new file mode 100644 index 0000000..1c4187a --- /dev/null +++ b/clang/test/ARCMT/objcmt-numeric-literals.m.result @@ -0,0 +1,501 @@ +// 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 + +#define YES __objc_yes +#define NO __objc_no + +typedef long NSInteger; +typedef unsigned long NSUInteger; +typedef signed char BOOL; +#define nil ((void*) 0) + +@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 + +#define VAL_INT 2 +#define VAL_UINT 2U +#define VAL_CHAR 'a' + +void foo() { + @'a'; + [NSNumber numberWithChar:L'a']; + [NSNumber numberWithChar:2]; + [NSNumber numberWithChar:2U]; + [NSNumber numberWithChar:2u]; + [NSNumber numberWithChar:2L]; + [NSNumber numberWithChar:2l]; + [NSNumber numberWithChar:2LL]; + [NSNumber numberWithChar:2ll]; + [NSNumber numberWithChar:2ul]; + [NSNumber numberWithChar:2lu]; + [NSNumber numberWithChar:2ull]; + [NSNumber numberWithChar:2llu]; + [NSNumber numberWithChar:2.0]; + [NSNumber numberWithChar:2.0f]; + [NSNumber numberWithChar:2.0F]; + [NSNumber numberWithChar:2.0l]; + [NSNumber numberWithChar:2.0L]; + [NSNumber numberWithChar:0x2f]; + [NSNumber numberWithChar:04]; + [NSNumber numberWithChar:0]; + [NSNumber numberWithChar:0.0]; + [NSNumber numberWithChar:YES]; + [NSNumber numberWithChar:NO]; + [NSNumber numberWithChar:true]; + [NSNumber numberWithChar:false]; + [NSNumber numberWithChar:VAL_INT]; + [NSNumber numberWithChar:VAL_UINT]; + @VAL_CHAR; + + [NSNumber numberWithUnsignedChar:'a']; + [NSNumber numberWithUnsignedChar:L'a']; + [NSNumber numberWithUnsignedChar:2]; + [NSNumber numberWithUnsignedChar:2U]; + [NSNumber numberWithUnsignedChar:2u]; + [NSNumber numberWithUnsignedChar:2L]; + [NSNumber numberWithUnsignedChar:2l]; + [NSNumber numberWithUnsignedChar:2LL]; + [NSNumber numberWithUnsignedChar:2ll]; + [NSNumber numberWithUnsignedChar:2ul]; + [NSNumber numberWithUnsignedChar:2lu]; + [NSNumber numberWithUnsignedChar:2ull]; + [NSNumber numberWithUnsignedChar:2llu]; + [NSNumber numberWithUnsignedChar:2.0]; + [NSNumber numberWithUnsignedChar:2.0f]; + [NSNumber numberWithUnsignedChar:2.0F]; + [NSNumber numberWithUnsignedChar:2.0l]; + [NSNumber numberWithUnsignedChar:2.0L]; + [NSNumber numberWithUnsignedChar:0x2f]; + [NSNumber numberWithUnsignedChar:04]; + [NSNumber numberWithUnsignedChar:0]; + [NSNumber numberWithUnsignedChar:0.0]; + [NSNumber numberWithUnsignedChar:YES]; + [NSNumber numberWithUnsignedChar:NO]; + [NSNumber numberWithUnsignedChar:true]; + [NSNumber numberWithUnsignedChar:false]; + [NSNumber numberWithUnsignedChar:VAL_INT]; + [NSNumber numberWithUnsignedChar:VAL_UINT]; + [NSNumber numberWithUnsignedChar:VAL_CHAR]; + + [NSNumber numberWithShort:'a']; + [NSNumber numberWithShort:L'a']; + [NSNumber numberWithShort:2]; + [NSNumber numberWithShort:2U]; + [NSNumber numberWithShort:2u]; + [NSNumber numberWithShort:2L]; + [NSNumber numberWithShort:2l]; + [NSNumber numberWithShort:2LL]; + [NSNumber numberWithShort:2ll]; + [NSNumber numberWithShort:2ul]; + [NSNumber numberWithShort:2lu]; + [NSNumber numberWithShort:2ull]; + [NSNumber numberWithShort:2llu]; + [NSNumber numberWithShort:2.0]; + [NSNumber numberWithShort:2.0f]; + [NSNumber numberWithShort:2.0F]; + [NSNumber numberWithShort:2.0l]; + [NSNumber numberWithShort:2.0L]; + [NSNumber numberWithShort:0x2f]; + [NSNumber numberWithShort:04]; + [NSNumber numberWithShort:0]; + [NSNumber numberWithShort:0.0]; + [NSNumber numberWithShort:YES]; + [NSNumber numberWithShort:NO]; + [NSNumber numberWithShort:true]; + [NSNumber numberWithShort:false]; + [NSNumber numberWithShort:VAL_INT]; + [NSNumber numberWithShort:VAL_UINT]; + + [NSNumber numberWithUnsignedShort:'a']; + [NSNumber numberWithUnsignedShort:L'a']; + [NSNumber numberWithUnsignedShort:2]; + [NSNumber numberWithUnsignedShort:2U]; + [NSNumber numberWithUnsignedShort:2u]; + [NSNumber numberWithUnsignedShort:2L]; + [NSNumber numberWithUnsignedShort:2l]; + [NSNumber numberWithUnsignedShort:2LL]; + [NSNumber numberWithUnsignedShort:2ll]; + [NSNumber numberWithUnsignedShort:2ul]; + [NSNumber numberWithUnsignedShort:2lu]; + [NSNumber numberWithUnsignedShort:2ull]; + [NSNumber numberWithUnsignedShort:2llu]; + [NSNumber numberWithUnsignedShort:2.0]; + [NSNumber numberWithUnsignedShort:2.0f]; + [NSNumber numberWithUnsignedShort:2.0F]; + [NSNumber numberWithUnsignedShort:2.0l]; + [NSNumber numberWithUnsignedShort:2.0L]; + [NSNumber numberWithUnsignedShort:0x2f]; + [NSNumber numberWithUnsignedShort:04]; + [NSNumber numberWithUnsignedShort:0]; + [NSNumber numberWithUnsignedShort:0.0]; + [NSNumber numberWithUnsignedShort:YES]; + [NSNumber numberWithUnsignedShort:NO]; + [NSNumber numberWithUnsignedShort:true]; + [NSNumber numberWithUnsignedShort:false]; + [NSNumber numberWithUnsignedShort:VAL_INT]; + [NSNumber numberWithUnsignedShort:VAL_UINT]; + + [NSNumber numberWithInt:'a']; + [NSNumber numberWithInt:L'a']; + @2; + @2; + @2; + @2; + @2; + @2; + @2; + @2; + @2; + @2; + @2; + [NSNumber numberWithInt:2.0]; + [NSNumber numberWithInt:2.0f]; + [NSNumber numberWithInt:2.0F]; + [NSNumber numberWithInt:2.0l]; + [NSNumber numberWithInt:2.0L]; + @0x2f; + @04; + @0; + [NSNumber numberWithInt:0.0]; + [NSNumber numberWithInt:YES]; + [NSNumber numberWithInt:NO]; + [NSNumber numberWithInt:true]; + [NSNumber numberWithInt:false]; + @VAL_INT; + [NSNumber numberWithInt:VAL_UINT]; + + (void)[[NSNumber alloc] initWithInt:2]; + (void)[[NSNumber alloc] initWithInt:2U]; + + @+2; + @-2; + + [NSNumber numberWithUnsignedInt:'a']; + [NSNumber numberWithUnsignedInt:L'a']; + @2U; + @2U; + @2u; + @2U; + @2u; + @2U; + @2u; + @2u; + @2u; + @2u; + @2u; + [NSNumber numberWithUnsignedInt:2.0]; + [NSNumber numberWithUnsignedInt:2.0f]; + [NSNumber numberWithUnsignedInt:2.0F]; + [NSNumber numberWithUnsignedInt:2.0l]; + [NSNumber numberWithUnsignedInt:2.0L]; + @0x2fU; + @04U; + @0U; + [NSNumber numberWithUnsignedInt:0.0]; + [NSNumber numberWithUnsignedInt:YES]; + [NSNumber numberWithUnsignedInt:NO]; + [NSNumber numberWithUnsignedInt:true]; + [NSNumber numberWithUnsignedInt:false]; + [NSNumber numberWithUnsignedInt:VAL_INT]; + @VAL_UINT; + + [NSNumber numberWithLong:'a']; + [NSNumber numberWithLong:L'a']; + @2L; + @2L; + @2l; + @2L; + @2l; + @2L; + @2l; + @2l; + @2l; + @2l; + @2l; + [NSNumber numberWithLong:2.0]; + [NSNumber numberWithLong:2.0f]; + [NSNumber numberWithLong:2.0F]; + [NSNumber numberWithLong:2.0l]; + [NSNumber numberWithLong:2.0L]; + @0x2fL; + @04L; + @0L; + [NSNumber numberWithLong:0.0]; + [NSNumber numberWithLong:YES]; + [NSNumber numberWithLong:NO]; + [NSNumber numberWithLong:true]; + [NSNumber numberWithLong:false]; + [NSNumber numberWithLong:VAL_INT]; + [NSNumber numberWithLong:VAL_UINT]; + + [NSNumber numberWithUnsignedLong:'a']; + [NSNumber numberWithUnsignedLong:L'a']; + @2UL; + @2UL; + @2ul; + @2UL; + @2ul; + @2UL; + @2ul; + @2ul; + @2lu; + @2ul; + @2ul; + [NSNumber numberWithUnsignedLong:2.0]; + [NSNumber numberWithUnsignedLong:2.0f]; + [NSNumber numberWithUnsignedLong:2.0F]; + [NSNumber numberWithUnsignedLong:2.0l]; + [NSNumber numberWithUnsignedLong:2.0L]; + @0x2fUL; + @04UL; + @0UL; + [NSNumber numberWithUnsignedLong:0.0]; + [NSNumber numberWithUnsignedLong:YES]; + [NSNumber numberWithUnsignedLong:NO]; + [NSNumber numberWithUnsignedLong:true]; + [NSNumber numberWithUnsignedLong:false]; + [NSNumber numberWithUnsignedLong:VAL_INT]; + [NSNumber numberWithUnsignedLong:VAL_UINT]; + + [NSNumber numberWithLongLong:'a']; + [NSNumber numberWithLongLong:L'a']; + @2LL; + @2LL; + @2ll; + @2LL; + @2ll; + @2LL; + @2ll; + @2ll; + @2ll; + @2ll; + @2ll; + [NSNumber numberWithLongLong:2.0]; + [NSNumber numberWithLongLong:2.0f]; + [NSNumber numberWithLongLong:2.0F]; + [NSNumber numberWithLongLong:2.0l]; + [NSNumber numberWithLongLong:2.0L]; + @0x2fLL; + @04LL; + @0LL; + [NSNumber numberWithLongLong:0.0]; + [NSNumber numberWithLongLong:YES]; + [NSNumber numberWithLongLong:NO]; + [NSNumber numberWithLongLong:true]; + [NSNumber numberWithLongLong:false]; + [NSNumber numberWithLongLong:VAL_INT]; + [NSNumber numberWithLongLong:VAL_UINT]; + + [NSNumber numberWithUnsignedLongLong:'a']; + [NSNumber numberWithUnsignedLongLong:L'a']; + @2ULL; + @2ULL; + @2ull; + @2ULL; + @2ull; + @2ULL; + @2ull; + @2ull; + @2ull; + @2ull; + @2llu; + [NSNumber numberWithUnsignedLongLong:2.0]; + [NSNumber numberWithUnsignedLongLong:2.0f]; + [NSNumber numberWithUnsignedLongLong:2.0F]; + [NSNumber numberWithUnsignedLongLong:2.0l]; + [NSNumber numberWithUnsignedLongLong:2.0L]; + @0x2fULL; + @04ULL; + @0ULL; + [NSNumber numberWithUnsignedLongLong:0.0]; + [NSNumber numberWithUnsignedLongLong:YES]; + [NSNumber numberWithUnsignedLongLong:NO]; + [NSNumber numberWithUnsignedLongLong:true]; + [NSNumber numberWithUnsignedLongLong:false]; + [NSNumber numberWithUnsignedLongLong:VAL_INT]; + [NSNumber numberWithUnsignedLongLong:VAL_UINT]; + + [NSNumber numberWithFloat:'a']; + [NSNumber numberWithFloat:L'a']; + @2.0f; + @2.0f; + @2.0f; + @2.0f; + @2.0f; + @2.0f; + @2.0f; + @2.0f; + @2.0f; + @2.0f; + @2.0f; + @2.0f; + @2.0f; + @2.0F; + @2.0f; + @2.0f; + [NSNumber numberWithFloat:0x2f]; + [NSNumber numberWithFloat:04]; + @0.0f; + @0.0f; + [NSNumber numberWithFloat:YES]; + [NSNumber numberWithFloat:NO]; + [NSNumber numberWithFloat:true]; + [NSNumber numberWithFloat:false]; + [NSNumber numberWithFloat:VAL_INT]; + [NSNumber numberWithFloat:VAL_UINT]; + + [NSNumber numberWithDouble:'a']; + [NSNumber numberWithDouble:L'a']; + @2.0; + @2.0; + @2.0; + @2.0; + @2.0; + @2.0; + @2.0; + @2.0; + @2.0; + @2.0; + @2.0; + @2.0; + @2.0; + @2.0; + @2.0; + @2.0; + [NSNumber numberWithDouble:0x2f]; + [NSNumber numberWithDouble:04]; + @0.0; + @0.0; + [NSNumber numberWithDouble:YES]; + [NSNumber numberWithDouble:NO]; + [NSNumber numberWithDouble:true]; + [NSNumber numberWithDouble:false]; + [NSNumber numberWithDouble:VAL_INT]; + [NSNumber numberWithDouble:VAL_UINT]; + + [NSNumber numberWithBool:'a']; + [NSNumber numberWithBool:L'a']; + [NSNumber numberWithBool:2]; + [NSNumber numberWithBool:2U]; + [NSNumber numberWithBool:2u]; + [NSNumber numberWithBool:2L]; + [NSNumber numberWithBool:2l]; + [NSNumber numberWithBool:2LL]; + [NSNumber numberWithBool:2ll]; + [NSNumber numberWithBool:2ul]; + [NSNumber numberWithBool:2lu]; + [NSNumber numberWithBool:2ull]; + [NSNumber numberWithBool:2llu]; + [NSNumber numberWithBool:2.0]; + [NSNumber numberWithBool:2.0f]; + [NSNumber numberWithBool:2.0F]; + [NSNumber numberWithBool:2.0l]; + [NSNumber numberWithBool:2.0L]; + [NSNumber numberWithBool:0x2f]; + [NSNumber numberWithBool:04]; + [NSNumber numberWithBool:0]; + [NSNumber numberWithBool:0.0]; + @YES; + @NO; + @true; + @false; + [NSNumber numberWithBool:VAL_INT]; + [NSNumber numberWithBool:VAL_UINT]; + + [NSNumber numberWithInteger:'a']; + [NSNumber numberWithInteger:L'a']; + @2; + @2; + @2; + @2L; + @2l; + @2; + @2; + @2; + @2; + @2; + @2; + [NSNumber numberWithInteger:2.0]; + [NSNumber numberWithInteger:2.0f]; + [NSNumber numberWithInteger:2.0F]; + [NSNumber numberWithInteger:2.0l]; + [NSNumber numberWithInteger:2.0L]; + @0x2f; + @04; + @0; + [NSNumber numberWithInteger:0.0]; + [NSNumber numberWithInteger:YES]; + [NSNumber numberWithInteger:NO]; + [NSNumber numberWithInteger:true]; + [NSNumber numberWithInteger:false]; + [NSNumber numberWithInteger:VAL_INT]; + [NSNumber numberWithInteger:VAL_UINT]; + + [NSNumber numberWithUnsignedInteger:'a']; + [NSNumber numberWithUnsignedInteger:L'a']; + @2U; + @2U; + @2u; + @2U; + @2u; + @2U; + @2u; + @2ul; + @2lu; + @2u; + @2u; + [NSNumber numberWithUnsignedInteger:2.0]; + [NSNumber numberWithUnsignedInteger:2.0f]; + [NSNumber numberWithUnsignedInteger:2.0F]; + [NSNumber numberWithUnsignedInteger:2.0l]; + [NSNumber numberWithUnsignedInteger:2.0L]; + @0x2fU; + @04U; + @0U; + [NSNumber numberWithUnsignedInteger:0.0]; + [NSNumber numberWithUnsignedInteger:YES]; + [NSNumber numberWithUnsignedInteger:NO]; + [NSNumber numberWithUnsignedInteger:true]; + [NSNumber numberWithUnsignedInteger:false]; + [NSNumber numberWithUnsignedInteger:VAL_INT]; + [NSNumber numberWithUnsignedInteger:VAL_UINT]; +} diff --git a/clang/test/ARCMT/objcmt-subscripting-literals.m b/clang/test/ARCMT/objcmt-subscripting-literals.m new file mode 100644 index 0000000..3d26efe --- /dev/null +++ b/clang/test/ARCMT/objcmt-subscripting-literals.m @@ -0,0 +1,137 @@ +// 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 + +typedef signed char BOOL; +#define nil ((void*) 0) + +@interface NSObject ++ (id)alloc; +@end + +@interface NSString : NSObject ++ (id)stringWithString:(NSString *)string; +- (id)initWithString:(NSString *)aString; +@end + +@interface NSArray : NSObject +- (id)objectAtIndex:(unsigned long)index; +- (id)objectAtIndexedSubscript:(int)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; + +- (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 NSDictionary : NSObject +- (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; + +- (id)objectForKey:(id)aKey; +@end + +@interface NSMutableDictionary : NSDictionary +- (void)setObject:(id)anObject forKey:(id)aKey; +- (void)setObject:(id)object forKeyedSubscript:(id)key; +@end + +@interface NSNumber : NSObject +@end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithInt:(int)value; +@end + +#define M(x) (x) +#define PAIR(x) @#x, [NSNumber numberWithInt:(x)] +#define TWO(x) ((x), (x)) + +@interface I +@end +@implementation I +-(void) foo { + NSString *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]; + dict = [NSDictionary dictionaryWithObjectsAndKeys: @"value1", @"key1", @"value2", @"key2", nil]; + dict = [NSDictionary dictionaryWithObjectsAndKeys: PAIR(1), PAIR(2), nil]; + dict = [NSDictionary dictionaryWithObjectsAndKeys: + @"value1", @"key1", +#ifdef BLAH + @"value2", @"key2", +#else + @"value3", @"key3", +#endif + nil ]; + + id o = [arr objectAtIndex:2]; + o = [dict objectForKey:@"key"]; + o = TWO([dict objectForKey:@"key"]); + o = [NSDictionary dictionaryWithObject:[NSDictionary dictionary] forKey:@"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"]; + [mdict setObject:[dict objectForKey:@"key2"] forKey: +#if 1 + @"key1" +#else + @"key2" +#endif + ]; + [mdict setObject:[dict objectForKey: +#if 2 + @"key3" +#else + @"key4" +#endif + ] forKey:@"key"]; + [mdict setObject:@"value" forKey:[dict objectForKey: +#if 3 + @"key5" +#else + @"key6" +#endif + ] ]; + [mdict setObject:@"val" forKey:[dict objectForKey:@"key2"]]; + [mdict setObject:[dict objectForKey:@"key1"] forKey:[dict objectForKey:[NSArray arrayWithObject:@"arrkey"]]]; + __strong NSArray **parr = 0; + o = [*parr objectAtIndex:2]; +} +@end diff --git a/clang/test/ARCMT/objcmt-subscripting-literals.m.result b/clang/test/ARCMT/objcmt-subscripting-literals.m.result new file mode 100644 index 0000000..8ac6dcc --- /dev/null +++ b/clang/test/ARCMT/objcmt-subscripting-literals.m.result @@ -0,0 +1,137 @@ +// 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 + +typedef signed char BOOL; +#define nil ((void*) 0) + +@interface NSObject ++ (id)alloc; +@end + +@interface NSString : NSObject ++ (id)stringWithString:(NSString *)string; +- (id)initWithString:(NSString *)aString; +@end + +@interface NSArray : NSObject +- (id)objectAtIndex:(unsigned long)index; +- (id)objectAtIndexedSubscript:(int)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; + +- (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 NSDictionary : NSObject +- (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; + +- (id)objectForKey:(id)aKey; +@end + +@interface NSMutableDictionary : NSDictionary +- (void)setObject:(id)anObject forKey:(id)aKey; +- (void)setObject:(id)object forKeyedSubscript:(id)key; +@end + +@interface NSNumber : NSObject +@end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithInt:(int)value; +@end + +#define M(x) (x) +#define PAIR(x) @#x, [NSNumber numberWithInt:(x)] +#define TWO(x) ((x), (x)) + +@interface I +@end +@implementation I +-(void) foo { + NSString *str; + NSArray *arr; + NSDictionary *dict; + + arr = @[]; + arr = @[str]; + arr = @[str, str]; + dict = @{}; + dict = @{str: arr}; + dict = @{@"key1": @"value1", @"key2": @"value2"}; + dict = [NSDictionary dictionaryWithObjectsAndKeys: PAIR(1), PAIR(2), nil]; + dict = [NSDictionary dictionaryWithObjectsAndKeys: + @"value1", @"key1", +#ifdef BLAH + @"value2", @"key2", +#else + @"value3", @"key3", +#endif + nil ]; + + id o = arr[2]; + o = dict[@"key"]; + o = TWO(dict[@"key"]); + o = @{@"key": @{}}; + NSMutableArray *marr = 0; + NSMutableDictionary *mdict = 0; + marr[2] = @"val"; + mdict[@"key"] = @"value"; + marr[2] = arr[4]; + mdict[@"key"] = dict[@"key2"]; + [mdict setObject:dict[@"key2"] forKey: +#if 1 + @"key1" +#else + @"key2" +#endif + ]; + mdict[@"key"] = [dict objectForKey: +#if 2 + @"key3" +#else + @"key4" +#endif + ]; + mdict[[dict objectForKey: +#if 3 + @"key5" +#else + @"key6" +#endif + ]] = @"value"; + mdict[dict[@"key2"]] = @"val"; + mdict[dict[@[@"arrkey"]]] = dict[@"key1"]; + __strong NSArray **parr = 0; + o = (*parr)[2]; +} +@end diff --git a/clang/test/ARCMT/releases-driver.m b/clang/test/ARCMT/releases-driver.m new file mode 100644 index 0000000..b75432a --- /dev/null +++ b/clang/test/ARCMT/releases-driver.m @@ -0,0 +1,68 @@ +// RUN: %clang_cc1 -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: cp %s %t +// RUN: %clang_cc1 -arcmt-modify -triple x86_64-apple-macosx10.6 -x objective-c %t +// RUN: diff %t %s.result +// RUN: rm %t + +typedef int BOOL; + +id IhaveSideEffect(); + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (id)retain; +- (oneway void)release; +@end + +@interface NSObject <NSObject> {} +@end + +@interface Foo : NSObject { + id bar; +} +@property (retain) id bar; +-(void)test:(id)obj; +@end + +@implementation Foo + +@synthesize bar; + +-(void)test:(id)obj { + id x = self.bar; + [x retain]; + self.bar = obj; + // do stuff with x; + [x release]; + + [IhaveSideEffect() release]; + + [x release], x = 0; +} + +@end + +void func(Foo *p) { + [p release]; + (([p release])); +} + +@interface Baz { + id <NSObject> _foo; +} +@end + +@implementation Baz +- dealloc { + [_foo release]; + return 0; +} +@end + +#define RELEASE_MACRO(x) [x release] +#define RELEASE_MACRO2(x) RELEASE_MACRO(x) + +void test2(id p) { + RELEASE_MACRO(p); + RELEASE_MACRO2(p); +} diff --git a/clang/test/ARCMT/releases-driver.m.result b/clang/test/ARCMT/releases-driver.m.result new file mode 100644 index 0000000..70c0aec --- /dev/null +++ b/clang/test/ARCMT/releases-driver.m.result @@ -0,0 +1,61 @@ +// RUN: %clang_cc1 -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: cp %s %t +// RUN: %clang_cc1 -arcmt-modify -triple x86_64-apple-macosx10.6 -x objective-c %t +// RUN: diff %t %s.result +// RUN: rm %t + +typedef int BOOL; + +id IhaveSideEffect(); + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (id)retain; +- (oneway void)release; +@end + +@interface NSObject <NSObject> {} +@end + +@interface Foo : NSObject { + id bar; +} +@property (strong) id bar; +-(void)test:(id)obj; +@end + +@implementation Foo + +@synthesize bar; + +-(void)test:(id)obj { + id x = self.bar; + self.bar = obj; + // do stuff with x; + + IhaveSideEffect(); + + x = 0; +} + +@end + +void func(Foo *p) { +} + +@interface Baz { + id <NSObject> _foo; +} +@end + +@implementation Baz +- dealloc { + return 0; +} +@end + +#define RELEASE_MACRO(x) [x release] +#define RELEASE_MACRO2(x) RELEASE_MACRO(x) + +void test2(id p) { +} diff --git a/clang/test/ARCMT/releases.m b/clang/test/ARCMT/releases.m new file mode 100644 index 0000000..867fab9 --- /dev/null +++ b/clang/test/ARCMT/releases.m @@ -0,0 +1,99 @@ +// RUN: %clang_cc1 -fobjc-exceptions -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-exceptions -fblocks -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#define nil 0 + +typedef int BOOL; + +id IhaveSideEffect(); + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (id)retain; +- (oneway void)release; +@end + +@interface NSObject <NSObject> {} +@end + +@interface Foo : NSObject { + id bar; +} +@property (retain) id bar; +-(void)test:(id)obj; +@end + +@implementation Foo + +@synthesize bar; + +-(void)test:(id)obj { + id x = self.bar; + [x retain]; + self.bar = obj; + // do stuff with x; + [x release]; + + [IhaveSideEffect() release]; + + [x release], x = 0; + + @try { + } @finally { + [x release]; + } +} + +@end + +void func(Foo *p) { + [p release]; + (([p release])); +} + +@interface Baz { + id <NSObject> _foo; +} +@end + +@implementation Baz +- dealloc { + [_foo release]; + return 0; +} +@end + +void block_test(Foo *p) { + id (^B)() = ^() { + if (p) { + id (^IB)() = ^() { + id bar = [p retain]; + [p release]; + return bar; + }; + IB(); + } + return [p retain]; + }; +} + +#define RELEASE_MACRO(x) [x release] +#define RELEASE_MACRO2(x) RELEASE_MACRO(x) + +void test2(id p) { + RELEASE_MACRO(p); + RELEASE_MACRO2(p); +} + +@implementation Foo2 + +static id internal_var = 0; + ++ (void)setIt:(id)newone { + if (internal_var != newone) { + [internal_var release]; + internal_var = [newone retain]; + } +} +@end diff --git a/clang/test/ARCMT/releases.m.result b/clang/test/ARCMT/releases.m.result new file mode 100644 index 0000000..556610a --- /dev/null +++ b/clang/test/ARCMT/releases.m.result @@ -0,0 +1,90 @@ +// RUN: %clang_cc1 -fobjc-exceptions -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-exceptions -fblocks -fsyntax-only -x objective-c %s > %t +// RUN: diff %t %s.result + +#define nil 0 + +typedef int BOOL; + +id IhaveSideEffect(); + +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (id)retain; +- (oneway void)release; +@end + +@interface NSObject <NSObject> {} +@end + +@interface Foo : NSObject { + id bar; +} +@property (strong) id bar; +-(void)test:(id)obj; +@end + +@implementation Foo + +@synthesize bar; + +-(void)test:(id)obj { + id x = self.bar; + self.bar = obj; + // do stuff with x; + + IhaveSideEffect(); + + x = 0; + + @try { + } @finally { + x = nil; + } +} + +@end + +void func(Foo *p) { +} + +@interface Baz { + id <NSObject> _foo; +} +@end + +@implementation Baz +- dealloc { + return 0; +} +@end + +void block_test(Foo *p) { + id (^B)() = ^() { + if (p) { + id (^IB)() = ^() { + id bar = p; + return bar; + }; + IB(); + } + return p; + }; +} + +#define RELEASE_MACRO(x) [x release] +#define RELEASE_MACRO2(x) RELEASE_MACRO(x) + +void test2(id p) { +} + +@implementation Foo2 + +static id internal_var = 0; + ++ (void)setIt:(id)newone { + if (internal_var != newone) { + internal_var = newone; + } +} +@end diff --git a/clang/test/ARCMT/remove-dealloc-method.m b/clang/test/ARCMT/remove-dealloc-method.m new file mode 100644 index 0000000..8e39fc8 --- /dev/null +++ b/clang/test/ARCMT/remove-dealloc-method.m @@ -0,0 +1,26 @@ +// 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 + +#define nil ((void*) 0) + +@interface Foo +@property (retain) id x; +@property (retain) id y; +@property (retain) id w; +@property (retain) id z; +@end + +@implementation Foo +@synthesize x; +@synthesize y; +@synthesize w; +@synthesize z; + +- (void) dealloc { + self.x = 0; + [self setY:nil]; + w = nil; + self.z = nil; +} +@end diff --git a/clang/test/ARCMT/remove-dealloc-method.m.result b/clang/test/ARCMT/remove-dealloc-method.m.result new file mode 100644 index 0000000..47e31f9 --- /dev/null +++ b/clang/test/ARCMT/remove-dealloc-method.m.result @@ -0,0 +1,20 @@ +// 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 + +#define nil ((void*) 0) + +@interface Foo +@property (strong) id x; +@property (strong) id y; +@property (strong) id w; +@property (strong) id z; +@end + +@implementation Foo +@synthesize x; +@synthesize y; +@synthesize w; +@synthesize z; + +@end diff --git a/clang/test/ARCMT/remove-dealloc-zerouts.m b/clang/test/ARCMT/remove-dealloc-zerouts.m new file mode 100644 index 0000000..4176ec5 --- /dev/null +++ b/clang/test/ARCMT/remove-dealloc-zerouts.m @@ -0,0 +1,44 @@ +// 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 + +@interface Foo +@property (retain) id x; +@property (retain) id y; +@property (retain) id w; +@property (retain) id z; +@property (strong) id q; +@end + +@implementation Foo +@synthesize x; +@synthesize y; +@synthesize w; +@synthesize q; +@dynamic z; + +- (void) dealloc { + self.x = self.y = self.w = 0; + self.x = 0, w = 0, y = 0; + [self setY:0]; + w = 0; + q = 0; + self.z = 0; +} +@end + +@interface Bar +@property (retain) Foo *a; +- (void) setA:(Foo*) val; +- (id) a; +@end + +@implementation Bar +- (void) dealloc { + [self setA:0]; // This is user-defined setter overriding synthesize, don't touch it. + self.a.x = 0; // every dealloc must zero out its own ivar. This patter is not recognized. +} +@synthesize a; +- (void) setA:(Foo*) val { } +- (id) a {return 0;} +@end diff --git a/clang/test/ARCMT/remove-dealloc-zerouts.m.result b/clang/test/ARCMT/remove-dealloc-zerouts.m.result new file mode 100644 index 0000000..9ae831a --- /dev/null +++ b/clang/test/ARCMT/remove-dealloc-zerouts.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 + +@interface Foo +@property (strong) id x; +@property (strong) id y; +@property (strong) id w; +@property (strong) id z; +@property (strong) id q; +@end + +@implementation Foo +@synthesize x; +@synthesize y; +@synthesize w; +@synthesize q; +@dynamic z; + +- (void) dealloc { + self.z = 0; +} +@end + +@interface Bar +@property (strong) Foo *a; +- (void) setA:(Foo*) val; +- (id) a; +@end + +@implementation Bar +- (void) dealloc { + [self setA:0]; // This is user-defined setter overriding synthesize, don't touch it. + self.a.x = 0; // every dealloc must zero out its own ivar. This patter is not recognized. +} +@synthesize a; +- (void) setA:(Foo*) val { } +- (id) a {return 0;} +@end diff --git a/clang/test/ARCMT/remove-statements.m b/clang/test/ARCMT/remove-statements.m new file mode 100644 index 0000000..286a8e7 --- /dev/null +++ b/clang/test/ARCMT/remove-statements.m @@ -0,0 +1,45 @@ +// 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" + +@interface myController : NSObject +-(id)test:(id)x; +@end + +#define MY_MACRO1(x) +#define MY_MACRO2(x) (void)x + +@implementation myController +-(id) test:(id) x { + [[x retain] release]; + return [[x retain] autorelease]; +} + +-(void)dealloc +{ + id array, array_already_empty; + for (id element in array_already_empty) { + } + + [array release]; + ; + + int b, b_array_already_empty; + if (b) + [array release]; + if (b_array_already_empty) ; + + if (b) { + [array release]; + } + if (b_array_already_empty) { + } + + if (b) + MY_MACRO1(array); + if (b) + MY_MACRO2(array); +} +@end diff --git a/clang/test/ARCMT/remove-statements.m.result b/clang/test/ARCMT/remove-statements.m.result new file mode 100644 index 0000000..6a4ea08 --- /dev/null +++ b/clang/test/ARCMT/remove-statements.m.result @@ -0,0 +1,38 @@ +// 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" + +@interface myController : NSObject +-(id)test:(id)x; +@end + +#define MY_MACRO1(x) +#define MY_MACRO2(x) (void)x + +@implementation myController +-(id) test:(id) x { + return x; +} + +-(void)dealloc +{ + id array, array_already_empty; + for (id element in array_already_empty) { + } + + ; + + int b, b_array_already_empty; + if (b_array_already_empty) ; + + if (b_array_already_empty) { + } + + if (b) + MY_MACRO1(array); + if (b) + MY_MACRO2(array); +} +@end diff --git a/clang/test/ARCMT/retains.m b/clang/test/ARCMT/retains.m new file mode 100644 index 0000000..60283a6 --- /dev/null +++ b/clang/test/ARCMT/retains.m @@ -0,0 +1,71 @@ +// 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" + +id IhaveSideEffect(); + +@interface Foo : NSObject { + id bar; +} +@property (retain) id bar; +-(id)test:(id)obj; +-(id)something; +@end + +#define Something_Macro(key, comment) \ + [[Foo new] something] + +@implementation Foo + +@synthesize bar; + +-(id)something {} + +-(id)test:(id)obj { + id x = self.bar; + [x retain]; + self.bar = obj; + if (obj) + [obj retain]; + + [Something_Macro(@"foo", "@bar") retain]; + + [IhaveSideEffect() retain]; + + [[self something] retain]; + + [[self retain] something]; + + [[IhaveSideEffect() retain] release]; + [[x retain] release]; + // do stuff with x; + [x release]; + return [self retain]; +} + +- (id)test1 { + id x=0; + ([x retain]); + return ((([x retain]))); +} +@end + +id foo (Foo *p) { + p = [p retain]; + return ([p retain]); +} + +void block_tests(Foo *p) { + id (^B)() = ^() { + if (p) { + id (^IB)() = ^() { + id bar = [p retain]; + return bar; + }; + IB(); + } + return [p retain]; + }; +} diff --git a/clang/test/ARCMT/retains.m.result b/clang/test/ARCMT/retains.m.result new file mode 100644 index 0000000..2011e50 --- /dev/null +++ b/clang/test/ARCMT/retains.m.result @@ -0,0 +1,65 @@ +// 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" + +id IhaveSideEffect(); + +@interface Foo : NSObject { + id bar; +} +@property (strong) id bar; +-(id)test:(id)obj; +-(id)something; +@end + +#define Something_Macro(key, comment) \ + [[Foo new] something] + +@implementation Foo + +@synthesize bar; + +-(id)something {} + +-(id)test:(id)obj { + id x = self.bar; + self.bar = obj; + + Something_Macro(@"foo", "@bar"); + + IhaveSideEffect(); + + [self something]; + + [self something]; + + IhaveSideEffect(); + // do stuff with x; + return self; +} + +- (id)test1 { + id x=0; + return (((x))); +} +@end + +id foo (Foo *p) { + p = p; + return (p); +} + +void block_tests(Foo *p) { + id (^B)() = ^() { + if (p) { + id (^IB)() = ^() { + id bar = p; + return bar; + }; + IB(); + } + return p; + }; +} diff --git a/clang/test/ARCMT/rewrite-block-var.m b/clang/test/ARCMT/rewrite-block-var.m new file mode 100644 index 0000000..538f16c --- /dev/null +++ b/clang/test/ARCMT/rewrite-block-var.m @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fblocks -fsyntax-only -fobjc-arc -x objective-c -fobjc-runtime-has-weak %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fblocks -fsyntax-only %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface Foo : NSObject +-(Foo *)something; +@end + +void bar(void (^block)()); + +void test1(Foo *p) { + __block Foo *x = p; // __block used just to break cycle. + bar(^{ + [x something]; + }); +} + +void test2(Foo *p) { + __block Foo *x; // __block used as output variable. + bar(^{ + x = [p something]; + }); +} + +void test3(Foo *p) { + __block Foo *x; // __block used as output variable. + bar(^{ + [x something]; + }); + bar(^{ + x = 0; + }); +} + +void test4(Foo *p) { + __block Foo *x = p; // __block used just to break cycle. + bar(^{ + [x something]; + }); + bar(^{ + [x something]; + }); +} diff --git a/clang/test/ARCMT/rewrite-block-var.m.result b/clang/test/ARCMT/rewrite-block-var.m.result new file mode 100644 index 0000000..a9d0b0f --- /dev/null +++ b/clang/test/ARCMT/rewrite-block-var.m.result @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fblocks -fsyntax-only -fobjc-arc -x objective-c -fobjc-runtime-has-weak %s.result +// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fblocks -fsyntax-only %s > %t +// RUN: diff %t %s.result + +#include "Common.h" + +@interface Foo : NSObject +-(Foo *)something; +@end + +void bar(void (^block)()); + +void test1(Foo *p) { + __weak Foo *x = p; // __block used just to break cycle. + bar(^{ + [x something]; + }); +} + +void test2(Foo *p) { + __block Foo *x; // __block used as output variable. + bar(^{ + x = [p something]; + }); +} + +void test3(Foo *p) { + __block Foo *x; // __block used as output variable. + bar(^{ + [x something]; + }); + bar(^{ + x = 0; + }); +} + +void test4(Foo *p) { + __weak Foo *x = p; // __block used just to break cycle. + bar(^{ + [x something]; + }); + bar(^{ + [x something]; + }); +} diff --git a/clang/test/ARCMT/safe-arc-assign.m b/clang/test/ARCMT/safe-arc-assign.m new file mode 100644 index 0000000..4a0a575 --- /dev/null +++ b/clang/test/ARCMT/safe-arc-assign.m @@ -0,0 +1,14 @@ +// 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 + +void test12(id collection) { + for (id x in collection) { + x = 0; + x = 0; + } + + for (__strong id x in collection) { + x = 0; + } +} diff --git a/clang/test/ARCMT/safe-arc-assign.m.result b/clang/test/ARCMT/safe-arc-assign.m.result new file mode 100644 index 0000000..c25955e --- /dev/null +++ b/clang/test/ARCMT/safe-arc-assign.m.result @@ -0,0 +1,14 @@ +// 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 + +void test12(id collection) { + for (__strong id x in collection) { + x = 0; + x = 0; + } + + for (__strong id x in collection) { + x = 0; + } +} diff --git a/clang/test/ARCMT/with space/test.h b/clang/test/ARCMT/with space/test.h new file mode 100644 index 0000000..756295f --- /dev/null +++ b/clang/test/ARCMT/with space/test.h @@ -0,0 +1,15 @@ +@protocol NSObject +- (oneway void)release; +@end + +#ifdef PART1 +static inline void part1(id p) { + [p release]; +} +#endif + +#ifdef PART2 +static inline void part2(id p) { + [p release]; +} +#endif diff --git a/clang/test/ARCMT/with space/test.h.result b/clang/test/ARCMT/with space/test.h.result new file mode 100644 index 0000000..0638a33 --- /dev/null +++ b/clang/test/ARCMT/with space/test.h.result @@ -0,0 +1,13 @@ +@protocol NSObject +- (oneway void)release; +@end + +#ifdef PART1 +static inline void part1(id p) { +} +#endif + +#ifdef PART2 +static inline void part2(id p) { +} +#endif diff --git a/clang/test/ARCMT/with space/test1.m.in b/clang/test/ARCMT/with space/test1.m.in new file mode 100644 index 0000000..8416a88 --- /dev/null +++ b/clang/test/ARCMT/with space/test1.m.in @@ -0,0 +1,6 @@ +#define PART1 +#include "test.h" + +void test1(id p) { + [p release]; +} diff --git a/clang/test/ARCMT/with space/test1.m.in.result b/clang/test/ARCMT/with space/test1.m.in.result new file mode 100644 index 0000000..f351fe6 --- /dev/null +++ b/clang/test/ARCMT/with space/test1.m.in.result @@ -0,0 +1,5 @@ +#define PART1 +#include "test.h" + +void test1(id p) { +} diff --git a/clang/test/ARCMT/with space/test2.m.in b/clang/test/ARCMT/with space/test2.m.in new file mode 100644 index 0000000..99f87b0 --- /dev/null +++ b/clang/test/ARCMT/with space/test2.m.in @@ -0,0 +1,6 @@ +#define PART2 +#include "test.h" + +void test2(id p) { + [p release]; +} diff --git a/clang/test/ARCMT/with space/test2.m.in.result b/clang/test/ARCMT/with space/test2.m.in.result new file mode 100644 index 0000000..f8e918c --- /dev/null +++ b/clang/test/ARCMT/with space/test2.m.in.result @@ -0,0 +1,5 @@ +#define PART2 +#include "test.h" + +void test2(id p) { +} diff --git a/clang/test/ARCMT/with-arc-mode-check.m b/clang/test/ARCMT/with-arc-mode-check.m new file mode 100644 index 0000000..33f31f5 --- /dev/null +++ b/clang/test/ARCMT/with-arc-mode-check.m @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -arcmt-check -fsyntax-only -fobjc-arc -x objective-c %s + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { + [p release]; +} diff --git a/clang/test/ARCMT/with-arc-mode-migrate.m b/clang/test/ARCMT/with-arc-mode-migrate.m new file mode 100644 index 0000000..4688594 --- /dev/null +++ b/clang/test/ARCMT/with-arc-mode-migrate.m @@ -0,0 +1,13 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: %clang_cc1 -arcmt-migrate -mt-migrate-directory %t -fsyntax-only -fobjc-arc %s +// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result +// RUN: rm -rf %t + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { + [p release]; +} diff --git a/clang/test/ARCMT/with-arc-mode-migrate.m.result b/clang/test/ARCMT/with-arc-mode-migrate.m.result new file mode 100644 index 0000000..dd34b99 --- /dev/null +++ b/clang/test/ARCMT/with-arc-mode-migrate.m.result @@ -0,0 +1,12 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: %clang_cc1 -arcmt-migrate -mt-migrate-directory %t -fsyntax-only -fobjc-arc %s +// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result +// RUN: rm -rf %t + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { +} diff --git a/clang/test/ARCMT/with-arc-mode-modify.m b/clang/test/ARCMT/with-arc-mode-modify.m new file mode 100644 index 0000000..fbbd630 --- /dev/null +++ b/clang/test/ARCMT/with-arc-mode-modify.m @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: cp %s %t +// RUN: %clang_cc1 -arcmt-modify -fsyntax-only -fobjc-arc -x objective-c %t +// RUN: diff %t %s.result +// RUN: rm %t + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { + [p release]; +} diff --git a/clang/test/ARCMT/with-arc-mode-modify.m.result b/clang/test/ARCMT/with-arc-mode-modify.m.result new file mode 100644 index 0000000..631f276 --- /dev/null +++ b/clang/test/ARCMT/with-arc-mode-modify.m.result @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: cp %s %t +// RUN: %clang_cc1 -arcmt-modify -fsyntax-only -fobjc-arc -x objective-c %t +// RUN: diff %t %s.result +// RUN: rm %t + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { +} |