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/Rewriter | |
parent | 3d206f03985b50beacae843d880bccdc91a9f424 (diff) |
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/Rewriter')
124 files changed, 3966 insertions, 0 deletions
diff --git a/clang/test/Rewriter/blockcast3.mm b/clang/test/Rewriter/blockcast3.mm new file mode 100644 index 0000000..ceafcff --- /dev/null +++ b/clang/test/Rewriter/blockcast3.mm @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -E %s -o %t.mm +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %t.mm -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o %t-modern-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-modern-rw.cpp %s +// radar 7607781 + +typedef struct { + int a; + int b; +} mystruct; + +void g(int (^block)(mystruct s)) { + mystruct x; + int v = block(x); +} + +void f(const void **arg) { + __block const void **q = arg; + g(^(mystruct s){ + *q++ = (void*)s.a; + return 314; + }); +} + +// CHECK-LP: (__Block_byref_q_0 *)&q diff --git a/clang/test/Rewriter/blockstruct.m b/clang/test/Rewriter/blockstruct.m new file mode 100644 index 0000000..ef85c58 --- /dev/null +++ b/clang/test/Rewriter/blockstruct.m @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar://8918702 + +typedef void (^b_t)(void); +void a(b_t work) { } +struct _s { + int a; +}; +struct _s *r(); + +void f() { + __block struct _s *s = 0; + a(^{ + s = (struct _s *)r(); + }); +} diff --git a/clang/test/Rewriter/crash.m b/clang/test/Rewriter/crash.m new file mode 100644 index 0000000..c61100e --- /dev/null +++ b/clang/test/Rewriter/crash.m @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi -o - %s +// rdar://5950938 +@interface NSArray {} ++ (id)arrayWithObjects:(id)firstObj, ...; +@end + +@interface NSConstantString {} +@end + +int main() { + id foo = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", 0]; + return 0; +} + +// rdar://6291588 +@protocol A +@end + +@interface Foo +@end + +void func() { + id <A> obj = (id <A>)[Foo bar]; +} + diff --git a/clang/test/Rewriter/dllimport-typedef.c b/clang/test/Rewriter/dllimport-typedef.c new file mode 100644 index 0000000..72cea70 --- /dev/null +++ b/clang/test/Rewriter/dllimport-typedef.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-NEG %s +// RUN: %clang_cc1 -triple i686-pc-win32 -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-POS %s + +// Do not report an error with including dllimport in the typedef when -fms-extensions is specified. +// Addresses <rdar://problem/7653870>. +typedef __declspec(dllimport) int CB(void); + +// This function is added just to trigger a diagnostic. This way we can test how many +// diagnostics we expect. +void bar() { return 1; } + +// CHECK-NEG: error: void function 'bar' should not return a value +// CHECK-NEG: 1 error generated +// CHECK-POS: warning: 'dllimport' attribute only applies to variables and functions +// CHECK-POS: error: void function 'bar' should not return a value +// CHECK-POS: 1 warning and 1 error generated + diff --git a/clang/test/Rewriter/finally.m b/clang/test/Rewriter/finally.m new file mode 100644 index 0000000..8fd475c --- /dev/null +++ b/clang/test/Rewriter/finally.m @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi -fobjc-exceptions -verify %s -o - + +int main() { + @try { + printf("executing try"); // expected-warning{{implicitly declaring library function 'printf' with type 'int (const char *, ...)'}} \ + // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}} + return(0); // expected-warning{{rewriter doesn't support user-specified control flow semantics for @try/@finally (code may not execute properly)}} + } @finally { + printf("executing finally"); + } + while (1) { + @try { + printf("executing try"); + break; + } @finally { + printf("executing finally"); + } + printf("executing after finally block"); + } + @try { + printf("executing try"); + } @finally { + printf("executing finally"); + } + return 0; +} + +void test_sync_with_implicit_finally() { + id foo; + @synchronized (foo) { + return; // The rewriter knows how to generate code for implicit finally + } +} + +void test2_try_with_implicit_finally() { + @try { + return; // The rewriter knows how to generate code for implicit finally + } @catch (id e) { + + } +} + diff --git a/clang/test/Rewriter/func-in-impl.m b/clang/test/Rewriter/func-in-impl.m new file mode 100644 index 0000000..350a726 --- /dev/null +++ b/clang/test/Rewriter/func-in-impl.m @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -E %s -o %t.m +// RUN: %clang_cc1 -fobjc-fragile-abi -rewrite-objc %t.m -o - | FileCheck %s + +@interface I { + id _delegate; +} +-(void)foo; +@end + +@implementation I + +static void KKKK(int w); + +-(void) foo { + KKKK(0); +} + +static void KKKK(int w) { + I *self = (I *)0; + if ([self->_delegate respondsToSelector:@selector(handlePortMessage:)]) { + } +} + +-(void) foo2 { + KKKK(0); +} + +@end + +// CHECK: if (((id (*)(id, SEL, ...))(void *)objc_msgSend)((id)((struct I_IMPL *)self)->_delegate, sel_registerName("respondsToSelector:"), sel_registerName("handlePortMessage:"))) diff --git a/clang/test/Rewriter/id-test-3.m b/clang/test/Rewriter/id-test-3.m new file mode 100644 index 0000000..d7a7bf3 --- /dev/null +++ b/clang/test/Rewriter/id-test-3.m @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@protocol P +- (id<P>) Meth: (id<P>) Arg; +@end + +@interface INTF<P> +- (id<P>)IMeth; +@end + +@implementation INTF +- (id<P>)IMeth { return [(id<P>)self Meth: (id<P>)0]; } +- (id<P>) Meth : (id<P>) Arg { return 0; } +@end diff --git a/clang/test/Rewriter/inner-block-helper-funcs.mm b/clang/test/Rewriter/inner-block-helper-funcs.mm new file mode 100644 index 0000000..d30e1dc --- /dev/null +++ b/clang/test/Rewriter/inner-block-helper-funcs.mm @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// rdar://9846759 + +typedef void (^dispatch_block_t)(void); + +extern int printf(const char*, ...); + +extern "C" dispatch_block_t Block_copy(dispatch_block_t aBlock); + +int main (int argc, char *argv[]) { + + dispatch_block_t innerBlock = ^{printf("argc = %d\n", argc); }; + id innerObject = 0; + + printf("innerBlock is %x\n", innerBlock); + + dispatch_block_t wrapperBlock = ^{ + printf("innerBlock is %x %x\n", innerBlock, innerObject); + }; + + wrapperBlock(); + + dispatch_block_t copiedBlock = Block_copy(wrapperBlock); + copiedBlock(); + + return 0; +} +// CHECK-LP: _Block_object_assign((void*)&dst->innerBlock, (void*)src->innerBlock, 7 +// CHECK-LP: _Block_object_dispose((void*)src->innerBlock, 7 +// CHECK-LP: _Block_object_assign((void*)&dst->innerObject, (void*)src->innerObject, 3 +// CHECK-LP: _Block_object_dispose((void*)src->innerObject, 3 diff --git a/clang/test/Rewriter/instancetype-test.mm b/clang/test/Rewriter/instancetype-test.mm new file mode 100644 index 0000000..7885055 --- /dev/null +++ b/clang/test/Rewriter/instancetype-test.mm @@ -0,0 +1,77 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp + +void *sel_registerName(const char *); + +@interface Root ++ (instancetype)alloc; +- (instancetype)init; // expected-note{{overridden method is part of the 'init' method family}} +- (instancetype)self; +- (Class)class; + +@property (assign) Root *selfProp; +- (instancetype)selfProp; +@end + +@protocol Proto1 +@optional +- (instancetype)methodInProto1; +@end + +@protocol Proto2 +@optional +- (instancetype)methodInProto2; // expected-note{{overridden method returns an instance of its class type}} +- (instancetype)otherMethodInProto2; // expected-note{{overridden method returns an instance of its class type}} +@end + +@interface Subclass1 : Root +- (instancetype)initSubclass1; +- (void)methodOnSubclass1; ++ (instancetype)allocSubclass1; +@end + +@interface Subclass2 : Root +- (instancetype)initSubclass2; +- (void)methodOnSubclass2; +@end + +// Sanity check: the basic initialization pattern. +void test_instancetype_alloc_init_simple() { + Root *r1 = [[Root alloc] init]; + Subclass1 *sc1 = [[Subclass1 alloc] init]; +} + +// Test that message sends to instancetype methods have the right type. +void test_instancetype_narrow_method_search() { + // instancetype on class methods + Subclass1 *sc1 = [[Subclass1 alloc] initSubclass2]; // expected-warning{{'Subclass1' may not respond to 'initSubclass2'}} + Subclass2 *sc2 = [[Subclass2 alloc] initSubclass2]; // okay + + // instancetype on instance methods + [[[Subclass1 alloc] init] methodOnSubclass2]; // expected-warning{{'Subclass1' may not respond to 'methodOnSubclass2'}} + [[[Subclass2 alloc] init] methodOnSubclass2]; + + // instancetype on class methods using protocols + [[Subclass1<Proto1> alloc] methodInProto2]; // expected-warning{{method '-methodInProto2' not found (return type defaults to 'id')}} + [[Subclass1<Proto2> alloc] methodInProto2]; + + // instancetype on instance methods + Subclass1<Proto1> *sc1proto1 = 0; + [[sc1proto1 self] methodInProto2]; // expected-warning{{method '-methodInProto2' not found (return type defaults to 'id')}} + Subclass1<Proto2> *sc1proto2 = 0; + [[sc1proto2 self] methodInProto2]; + + // Exact type checks + // Message sends to Class. + // FIXME. This is not supported due to missing capability in rewriter and not due to instancetype issues + // Subclass1<Proto1> *sc1proto1_2 = [[[sc1proto1 class] alloc] init]; + + // Property access + [sc1proto1.self methodInProto2]; // expected-warning{{method '-methodInProto2' not found (return type defaults to 'id')}} + [sc1proto2.self methodInProto2]; + + [sc1proto1.selfProp methodInProto2]; // expected-warning{{method '-methodInProto2' not found (return type defaults to 'id')}} + [sc1proto2.selfProp methodInProto2]; +} diff --git a/clang/test/Rewriter/ivar-encoding-1.m b/clang/test/Rewriter/ivar-encoding-1.m new file mode 100644 index 0000000..d294943 --- /dev/null +++ b/clang/test/Rewriter/ivar-encoding-1.m @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@interface Intf +{ + id ivar; + id ivar1[12]; + + id **ivar3; + + id (*ivar4) (id, id); +} +@end + +@implementation Intf +@end diff --git a/clang/test/Rewriter/ivar-encoding-2.m b/clang/test/Rewriter/ivar-encoding-2.m new file mode 100644 index 0000000..da60c79 --- /dev/null +++ b/clang/test/Rewriter/ivar-encoding-2.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@implementation Intf +{ + id ivar; + id ivar1[12]; + + id **ivar3; + + id (*ivar4) (id, id); +} +@end diff --git a/clang/test/Rewriter/metadata-test-1.m b/clang/test/Rewriter/metadata-test-1.m new file mode 100644 index 0000000..b2d6e8d --- /dev/null +++ b/clang/test/Rewriter/metadata-test-1.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@interface Intf +@end + +@implementation Intf(Category) +- (void) CatMeth {} +@end + +@implementation Another +- (void) CatMeth {} +@end diff --git a/clang/test/Rewriter/metadata-test-2.m b/clang/test/Rewriter/metadata-test-2.m new file mode 100644 index 0000000..90399f7 --- /dev/null +++ b/clang/test/Rewriter/metadata-test-2.m @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +typedef struct _NSPoint { + float x; + float y; +} NSPoint; + +@interface Intf +- (void) MyMeth : (NSPoint) Arg1; +@end + +@implementation Intf +- (void) MyMeth : (NSPoint) Arg1{} +@end + diff --git a/clang/test/Rewriter/method-encoding-1.m b/clang/test/Rewriter/method-encoding-1.m new file mode 100644 index 0000000..27abea5 --- /dev/null +++ b/clang/test/Rewriter/method-encoding-1.m @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@protocol P1 +- (void) MyProtoMeth : (int **) arg1 : (void*) arg2; ++ (void) MyProtoMeth : (int **) arg1 : (void*) arg2; +@end + +@interface Intf <P1> +- (char *) MyMeth : (double) arg1 : (char *[12]) arg2; +- (id) address:(void *)location with:(unsigned **)arg2; +@end + +@implementation Intf +- (char *) MyMeth : (double) arg1 : (char *[12]) arg2{ return 0; } +- (void) MyProtoMeth : (int **) arg1 : (void*) arg2 {} ++ (void) MyProtoMeth : (int **) arg1 : (void*) arg2 {} +- (id) address:(void *)location with:(unsigned **)arg2{ return 0; } +@end diff --git a/clang/test/Rewriter/missing-dllimport.c b/clang/test/Rewriter/missing-dllimport.c new file mode 100644 index 0000000..1dfc04c --- /dev/null +++ b/clang/test/Rewriter/missing-dllimport.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-NEG %s +// RUN: %clang_cc1 -triple i686-pc-win32 -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-POS %s + +// Do not report that 'foo()' is redeclared without dllimport attribute with -fms-extensions +// specified. Addresses <rdar://problem/7653912>. + +__declspec(dllimport) int __cdecl foo(void); +inline int __cdecl foo() { return 0; } + +// This function is added just to trigger a diagnostic. This way we can test how many +// diagnostics we expect. +void bar() { return 1; } + +// CHECK-NEG: error: void function 'bar' should not return a value +// CHECK-NEG: 1 error generated +// CHECK-POS: warning: 'foo' redeclared without dllimport attribute: previous dllimport ignored +// CHECK-POS: error: void function 'bar' should not return a value +// CHECK-POS: 1 warning and 1 error generated + diff --git a/clang/test/Rewriter/objc-bool-literal-check-modern.mm b/clang/test/Rewriter/objc-bool-literal-check-modern.mm new file mode 100644 index 0000000..3386197 --- /dev/null +++ b/clang/test/Rewriter/objc-bool-literal-check-modern.mm @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -E %s -o %t.mm +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s +// rdar://11124775 + +typedef bool BOOL; + +BOOL yes() { + return __objc_yes; +} + +BOOL no() { + return __objc_no; +} + +BOOL which (int flag) { + return flag ? yes() : no(); +} + +int main() { + which (__objc_yes); + which (__objc_no); + return __objc_yes; +} + +// CHECK: return ((bool)1); +// CHECK: return ((bool)0); +// CHECK: which (((bool)1)); +// CHECK: which (((bool)0)); +// CHECK: return ((bool)1); diff --git a/clang/test/Rewriter/objc-bool-literal-modern-1.mm b/clang/test/Rewriter/objc-bool-literal-modern-1.mm new file mode 100644 index 0000000..7825172 --- /dev/null +++ b/clang/test/Rewriter/objc-bool-literal-modern-1.mm @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"__declspec(X)=" %t-rw.cpp +// rdar://11231426 + +typedef bool BOOL; + +BOOL yes() { + return __objc_yes; +} + +BOOL no() { + return __objc_no; +} + +BOOL which (int flag) { + return flag ? yes() : no(); +} + +int main() { + which (__objc_yes); + which (__objc_no); + return __objc_yes; +} + +void y(BOOL (^foo)()); + +void x() { + y(^{ + return __objc_yes; + }); +} diff --git a/clang/test/Rewriter/objc-bool-literal-modern.mm b/clang/test/Rewriter/objc-bool-literal-modern.mm new file mode 100644 index 0000000..328ee6b --- /dev/null +++ b/clang/test/Rewriter/objc-bool-literal-modern.mm @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -x objective-c++ -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -D"__declspec(X)=" %t-rw.cpp +// rdar://11124775 + +typedef bool BOOL; + +BOOL yes() { + return __objc_yes; +} + +BOOL no() { + return __objc_no; +} + +BOOL which (int flag) { + return flag ? yes() : no(); +} + +int main() { + which (__objc_yes); + which (__objc_no); + return __objc_yes; +} diff --git a/clang/test/Rewriter/objc-encoding-bug-1.m b/clang/test/Rewriter/objc-encoding-bug-1.m new file mode 100644 index 0000000..083b570 --- /dev/null +++ b/clang/test/Rewriter/objc-encoding-bug-1.m @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +typedef struct NSMethodFrameArgInfo { + struct NSMethodFrameArgInfo *subInfo; + struct NSMethodFrameArgInfo *an; +} NSMethodFrameArgInfo; + +@interface NSMethodSignature +- (NSMethodFrameArgInfo *)_argInfo; +@end + +@implementation NSMethodSignature + +- (NSMethodFrameArgInfo *)_argInfo{ + return 0; +} + +@end + diff --git a/clang/test/Rewriter/objc-ivar-receiver-1.m b/clang/test/Rewriter/objc-ivar-receiver-1.m new file mode 100644 index 0000000..5195042 --- /dev/null +++ b/clang/test/Rewriter/objc-ivar-receiver-1.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - | grep 'newInv->_container' + +@interface NSMutableArray +- (void)addObject:(id)addObject; +@end + +@interface NSInvocation { +@private + id _container; +} ++ (NSInvocation *)invocationWithMethodSignature; + +@end + +@implementation NSInvocation + ++ (NSInvocation *)invocationWithMethodSignature { + NSInvocation *newInv; + id obj = newInv->_container; + [newInv->_container addObject:0]; + return 0; +} +@end diff --git a/clang/test/Rewriter/objc-modern-class-init-hooks.mm b/clang/test/Rewriter/objc-modern-class-init-hooks.mm new file mode 100644 index 0000000..c294c79 --- /dev/null +++ b/clang/test/Rewriter/objc-modern-class-init-hooks.mm @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -E %s -o %t.mm +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s +// rdar:// 11124354 + +@interface Root @end + +@interface Super : Root +@end + +@interface Sub : Super +@end + +@implementation Sub @end + +@implementation Root @end + +@interface Root(Cat) @end + +@interface Sub(Cat) @end + +@implementation Root(Cat) @end + +@implementation Sub(Cat) @end + + +// CHECK: #pragma section(".objc_inithooks$B", long, read, write) +// CHECK: __declspec(allocate(".objc_inithooks$B")) static void *OBJC_CLASS_SETUP[] = { +// CHECK: (void *)&OBJC_CLASS_SETUP_$_Sub, +// CHECK: (void *)&OBJC_CLASS_SETUP_$_Root, +// CHECK: }; + +// CHECK: #pragma section(".objc_inithooks$B", long, read, write) +// CHECK: __declspec(allocate(".objc_inithooks$B")) static void *OBJC_CATEGORY_SETUP[] = { +// CHECK: (void *)&OBJC_CATEGORY_SETUP_$_Root_$_Cat, +// CHECK: (void *)&OBJC_CATEGORY_SETUP_$_Sub_$_Cat, +// CHECK: }; diff --git a/clang/test/Rewriter/objc-modern-class-init.mm b/clang/test/Rewriter/objc-modern-class-init.mm new file mode 100644 index 0000000..b0326a4 --- /dev/null +++ b/clang/test/Rewriter/objc-modern-class-init.mm @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar:// 11076938 + +@interface Root @end + +@interface Super : Root +@end + +@interface Sub : Super +@end + +@implementation Sub @end + +@implementation Root @end + +@interface Root(Cat) @end + +@interface Sub(Cat) @end + +@implementation Root(Cat) @end + +@implementation Sub(Cat) @end diff --git a/clang/test/Rewriter/objc-modern-container-subscript.mm b/clang/test/Rewriter/objc-modern-container-subscript.mm new file mode 100644 index 0000000..d6bb9c2 --- /dev/null +++ b/clang/test/Rewriter/objc-modern-container-subscript.mm @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar://11203853 + +void *sel_registerName(const char *); + +typedef unsigned int size_t; +@protocol P @end + +@interface NSMutableArray +#if __has_feature(objc_subscripting) +- (id)objectAtIndexedSubscript:(size_t)index; +- (void)setObject:(id)object atIndexedSubscript:(size_t)index; +#endif +@end + +#if __has_feature(objc_subscripting) +@interface XNSMutableArray +- (id)objectAtIndexedSubscript:(size_t)index; +- (void)setObject:(id)object atIndexedSubscript:(size_t)index; +#endif +@end + +@interface NSMutableDictionary +- (id)objectForKeyedSubscript:(id)key; +- (void)setObject:(id)object forKeyedSubscript:(id)key; +@end + +@class NSString; + +int main() { + NSMutableArray<P> * array; + id oldObject = array[10]; + + array[10] = oldObject; + + id unknown_array; + oldObject = unknown_array[1]; + + unknown_array[1] = oldObject; + + NSMutableDictionary *dictionary; + NSString *key; + id newObject; + oldObject = dictionary[key]; + dictionary[key] = newObject; // replace oldObject with newObject +} + diff --git a/clang/test/Rewriter/objc-modern-implicit-cast.mm b/clang/test/Rewriter/objc-modern-implicit-cast.mm new file mode 100644 index 0000000..e612199 --- /dev/null +++ b/clang/test/Rewriter/objc-modern-implicit-cast.mm @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar://11202764 + +typedef void(^BL)(void); + +id return_id(void(^block)(void)) { + return block; +} + +BL return_block(id obj) { + return obj; +} + +int main() +{ + void(^block)(void); + id obj; + block = obj; // AnyPointerToBlockPointerCast + obj = block; // BlockPointerToObjCPointerCast + + id obj1 = block; + + void(^block1)(void) = obj1; + + return_id(block1); + + return_id(obj1); + + return_block(block1); + + return_block(obj1); +} diff --git a/clang/test/Rewriter/objc-modern-ivar-receiver-1.mm b/clang/test/Rewriter/objc-modern-ivar-receiver-1.mm new file mode 100644 index 0000000..a5c17a6 --- /dev/null +++ b/clang/test/Rewriter/objc-modern-ivar-receiver-1.mm @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -E %s -o %t.mm +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s + +void *sel_registerName(const char *); + +@interface NSMutableArray +- (void)addObject:(id)addObject; +@end + +@interface NSInvocation { +@private + id _container; +} ++ (NSInvocation *)invocationWithMethodSignature; + +@end + +@implementation NSInvocation + ++ (NSInvocation *)invocationWithMethodSignature { + NSInvocation *newInv; + id obj = newInv->_container; + [newInv->_container addObject:0]; + return 0; +} +@end + +// CHECK: id obj = (*(id *)((char *)newInv + OBJC_IVAR_$_NSInvocation$_container)); +// rdar://11076938 +// CHECK: struct _class_t *superclass; +// CHECK: extern "C" __declspec(dllimport) struct objc_cache _objc_empty_cache; diff --git a/clang/test/Rewriter/objc-modern-linkage-spec.mm b/clang/test/Rewriter/objc-modern-linkage-spec.mm new file mode 100644 index 0000000..028d787 --- /dev/null +++ b/clang/test/Rewriter/objc-modern-linkage-spec.mm @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -x objective-c++ -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-attributes -D"__declspec(X)=" %t-rw.cpp +// rdar://11169733 + +extern "C" __declspec(dllexport) +@interface Test @end + +@implementation Test @end + +extern "C" { +__declspec(dllexport) +@interface Test1 @end + +@implementation Test1 @end + +__declspec(dllexport) +@interface Test2 @end + +@implementation Test2 @end +}; + diff --git a/clang/test/Rewriter/objc-modern-metadata-visibility.mm b/clang/test/Rewriter/objc-modern-metadata-visibility.mm new file mode 100644 index 0000000..42adf86 --- /dev/null +++ b/clang/test/Rewriter/objc-modern-metadata-visibility.mm @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -E %s -o %t.mm +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s +// rdar://11144048 + +@class NSString; + +@interface NSObject { + Class isa; +} +@end + +@interface Sub : NSObject { + int subIvar; + NSString *nsstring; +@private + id PrivateIvar; +} +@end + +@implementation Sub +- (id) MyNSString { return subIvar ? PrivateIvar : nsstring; } +@end + +@interface NSString @end +@implementation NSString @end + +// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" __declspec(dllimport) unsigned long OBJC_IVAR_$_Sub$subIvar; +// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" unsigned long OBJC_IVAR_$_Sub$PrivateIvar; +// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" __declspec(dllimport) unsigned long OBJC_IVAR_$_Sub$nsstring; +// CHECK: #pragma warning(disable:4273) +// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" __declspec(dllexport) unsigned long int OBJC_IVAR_$_Sub$subIvar +// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" __declspec(dllexport) unsigned long int OBJC_IVAR_$_Sub$nsstring +// CHECK: __declspec(allocate(".objc_ivar$B")) extern "C" unsigned long int OBJC_IVAR_$_Sub$PrivateIvar +// CHECK: extern "C" __declspec(dllimport) struct _class_t OBJC_METACLASS_$_NSObject; +// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_METACLASS_$_Sub +// CHECK: extern "C" __declspec(dllimport) struct _class_t OBJC_CLASS_$_NSObject; +// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_CLASS_$_Sub +// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_CLASS_$_NSString; +// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_METACLASS_$_NSString +// CHECK: extern "C" __declspec(dllexport) struct _class_t OBJC_CLASS_$_NSString diff --git a/clang/test/Rewriter/objc-modern-numeric-literal.mm b/clang/test/Rewriter/objc-modern-numeric-literal.mm new file mode 100644 index 0000000..5f0b1fc --- /dev/null +++ b/clang/test/Rewriter/objc-modern-numeric-literal.mm @@ -0,0 +1,69 @@ +// RUN: %clang_cc1 -E %s -o %t.mm +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s +// rdar://10803676 + +extern "C" void *sel_registerName(const char *); + +typedef bool BOOL; +typedef long NSInteger; +typedef unsigned long NSUInteger; + +#if __has_feature(objc_bool) +#define YES __objc_yes +#define NO __objc_no +#else +#define YES ((BOOL)1) +#define NO ((BOOL)0) +#endif + +@interface NSNumber ++ (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 + +int main(int argc, const char *argv[]) { + // character literals. + NSNumber *theLetterZ = @'Z'; // equivalent to [NSNumber numberWithChar:'Z'] + + // integral literals. + NSNumber *fortyTwo = @42; // equivalent to [NSNumber numberWithInt:42] + NSNumber *fortyTwoUnsigned = @42U; // equivalent to [NSNumber numberWithUnsignedInt:42U] + NSNumber *fortyTwoLong = @42L; // equivalent to [NSNumber numberWithLong:42L] + NSNumber *fortyTwoLongLong = @42LL; // equivalent to [NSNumber numberWithLongLong:42LL] + + // floating point literals. + NSNumber *piFloat = @3.141592654F; // equivalent to [NSNumber numberWithFloat:3.141592654F] + NSNumber *piDouble = @3.1415926535; // equivalent to [NSNumber numberWithDouble:3.1415926535] + + // BOOL literals. + NSNumber *yesNumber = @YES; // equivalent to [NSNumber numberWithBool:YES] + NSNumber *noNumber = @NO; // equivalent to [NSNumber numberWithBool:NO] + + NSNumber *trueNumber = @true; // equivalent to [NSNumber numberWithBool:(BOOL)true] + NSNumber *falseNumber = @false; // equivalent to [NSNumber numberWithBool:(BOOL)false] +} + +// CHECK: NSNumber *theLetterZ = ((NSNumber *(*)(id, SEL, char))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithChar:"), 'Z'); +// CHECK: NSNumber *fortyTwo = ((NSNumber *(*)(id, SEL, int))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithInt:"), 42); +// CHECK: NSNumber *fortyTwoUnsigned = ((NSNumber *(*)(id, SEL, unsigned int))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithUnsignedInt:"), 42U); +// CHECK: NSNumber *fortyTwoLong = ((NSNumber *(*)(id, SEL, long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLong:"), 42L); +// CHECK: NSNumber *fortyTwoLongLong = ((NSNumber *(*)(id, SEL, long long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLongLong:"), 42LL); +// CHECK: NSNumber *piFloat = ((NSNumber *(*)(id, SEL, float))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithFloat:"), 3.1415927); +// CHECK: NSNumber *piDouble = ((NSNumber *(*)(id, SEL, double))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithDouble:"), 3.1415926535); +// CHECK: NSNumber *yesNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), true); +// CHECK: NSNumber *noNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), false); +// CHECK: NSNumber *trueNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), true); +// CHECK: NSNumber *falseNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), false); diff --git a/clang/test/Rewriter/objc-modern-property-attributes.mm b/clang/test/Rewriter/objc-modern-property-attributes.mm new file mode 100644 index 0000000..7d74a95 --- /dev/null +++ b/clang/test/Rewriter/objc-modern-property-attributes.mm @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -E %s -o %t.mm +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s + +// rdar://11095151 + +typedef void (^void_block_t)(void); + +@interface PropertyClass { + int q; + void_block_t __completion; + PropertyClass* YVAR; + id ID; +} +@property int q; +@property int r; + +@property (copy) void_block_t completionBlock; +@property (retain) PropertyClass* Yblock; +@property (copy) id ID; + +@end + +@implementation PropertyClass +@synthesize q; // attributes should be "Ti,Vq" +@dynamic r; // attributes should be "Ti,D" +@synthesize completionBlock=__completion; // "T@?,C,V__completion" +@synthesize Yblock = YVAR; // "T@\"PropertyClass\",&,VYVAR" +@synthesize ID; // "T@,C,VID" +@end + +// CHECK: Ti,Vq +// CHECK: Ti,D +// CHECK: T@?,C,V__completion +// CHECK: T@\"PropertyClass\",&,VYVAR + diff --git a/clang/test/Rewriter/objc-string-concat-1.m b/clang/test/Rewriter/objc-string-concat-1.m new file mode 100644 index 0000000..80a9f04 --- /dev/null +++ b/clang/test/Rewriter/objc-string-concat-1.m @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@class NSString; + +@interface NSConstantString; +@end + + + +NSConstantString *t0 = @"123"; +NSConstantString *t = @"123" @"4567"; // concat +NSConstantString *t1 = @"123" @"4567" /* COMMENT */ @"89"; // concat +NSConstantString *t2 = @"123" @/* COMMENT */ "4567"; // concat + diff --git a/clang/test/Rewriter/objc-super-test.m b/clang/test/Rewriter/objc-super-test.m new file mode 100644 index 0000000..fa95ad2 --- /dev/null +++ b/clang/test/Rewriter/objc-super-test.m @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - | grep objc_msgSendSuper | grep MainMethod + +typedef struct objc_selector *SEL; +typedef struct objc_object *id; + +@interface SUPER +- (int) MainMethod; +@end + +@interface MyDerived : SUPER +- (int) instanceMethod; +@end + +@implementation MyDerived +- (int) instanceMethod { + return [super MainMethod]; +} +@end diff --git a/clang/test/Rewriter/objc-synchronized-1.m b/clang/test/Rewriter/objc-synchronized-1.m new file mode 100644 index 0000000..df55536 --- /dev/null +++ b/clang/test/Rewriter/objc-synchronized-1.m @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +id SYNCH_EXPR(); +void SYNCH_BODY(); +void SYNCH_BEFORE(); +void SYNC_AFTER(); + +void foo(id sem) +{ + SYNCH_BEFORE(); + @synchronized (SYNCH_EXPR()) { + SYNCH_BODY(); + return; + } + SYNC_AFTER(); + @synchronized ([sem self]) { + SYNCH_BODY(); + return; + } +} diff --git a/clang/test/Rewriter/properties.m b/clang/test/Rewriter/properties.m new file mode 100644 index 0000000..493fc3f --- /dev/null +++ b/clang/test/Rewriter/properties.m @@ -0,0 +1,57 @@ +// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fms-extensions -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +void *sel_registerName(const char *); + +@interface Foo { + int i; + int rrrr; + Foo *o; +} +@property int i; +@property(readonly) int rrrr; +@property int d; +@property(retain) Foo *o; + +- (void)foo; +@end + +@implementation Foo +@synthesize i; +@synthesize rrrr; +@synthesize o; + +@dynamic d; + +- (void)foo { + i = 99; +} + +- (int)bar { + return i; +} +@end + +@interface Bar { +} +@end + +@implementation Bar + +static int func(int i) { return 0; } + +- (void)baz { + Foo *obj1, *obj2; + int i; + if (obj1.i == obj2.rrrr) + obj1.i = 33; + obj1.i = func(obj2.rrrr); + obj1.i = obj2.rrrr; + obj1.i = (obj2.rrrr); + [obj1 setI:[obj2 rrrr]]; + obj1.i = [obj2 rrrr]; + obj1.i = 3 + [obj2 rrrr]; + i = obj1.o.i; + obj1.o.i = 77; +} +@end diff --git a/clang/test/Rewriter/property-dot-syntax.mm b/clang/test/Rewriter/property-dot-syntax.mm new file mode 100644 index 0000000..c8ee723 --- /dev/null +++ b/clang/test/Rewriter/property-dot-syntax.mm @@ -0,0 +1,46 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar:// 8520727 + +void *sel_registerName(const char *); + +@class NSString; + +@protocol CoreDAVAccountInfoProvider +- (NSString *)userAgentHeader; +@end + +@interface CoreDAVTask +{ + id<CoreDAVAccountInfoProvider> _accountInfoProvider; +} +- (void)METHOD; +@end + +@implementation CoreDAVTask +- (void)METHOD { + if ([_accountInfoProvider userAgentHeader]) { + } + if (_accountInfoProvider.userAgentHeader) { + } +} +@end + +//rdar: // 8541517 +@interface A { } +@property (retain) NSString *scheme; +@end + +@interface B : A { + NSString* _schemeName; +} +@end + + +@implementation B +-(void) test { + B *b; + b.scheme = _schemeName; // error because of this line +} +@end + diff --git a/clang/test/Rewriter/protocol-rewrite-1.m b/clang/test/Rewriter/protocol-rewrite-1.m new file mode 100644 index 0000000..687a259 --- /dev/null +++ b/clang/test/Rewriter/protocol-rewrite-1.m @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +typedef struct MyWidget { + int a; +} MyWidget; + +MyWidget gWidget = { 17 }; + +@protocol MyProto +- (MyWidget *)widget; +@end + +@interface Foo +@end + +@interface Bar: Foo <MyProto> +@end + +@interface Container ++ (MyWidget *)elementForView:(Foo *)view; +@end + +@implementation Foo +@end + +@implementation Bar +- (MyWidget *)widget { + return &gWidget; +} +@end + +@implementation Container ++ (MyWidget *)elementForView:(Foo *)view +{ + MyWidget *widget = (void*)0; + if (@protocol(MyProto)) { + widget = [(id <MyProto>)view widget]; + } + return widget; +} +@end + +int main(void) { + id view; + MyWidget *w = [Container elementForView: view]; + + return 0; +} diff --git a/clang/test/Rewriter/protocol-rewrite-2.m b/clang/test/Rewriter/protocol-rewrite-2.m new file mode 100644 index 0000000..e0ec4f9 --- /dev/null +++ b/clang/test/Rewriter/protocol-rewrite-2.m @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o %t.cpp +// RUN: %clang_cc1 -fsyntax-only %t.cpp + +// rdar://10234024 +@protocol Foo; +@protocol Foo +@end diff --git a/clang/test/Rewriter/rewrite-anonymous-union.m b/clang/test/Rewriter/rewrite-anonymous-union.m new file mode 100644 index 0000000..339524f --- /dev/null +++ b/clang/test/Rewriter/rewrite-anonymous-union.m @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi -o - %s +// rdar://6948022 + +typedef unsigned int uint32_t; + +typedef struct { + union { + uint32_t daysOfWeek; + uint32_t dayOfMonth; + }; + uint32_t nthOccurrence; +} OSPatternSpecificData; + +@interface NSNumber ++ (NSNumber *)numberWithLong:(long)value; +@end + +@interface OSRecurrence { + OSPatternSpecificData _pts; +} +- (void)_setTypeSpecificInfoOnRecord; +@end + +@implementation OSRecurrence +- (void)_setTypeSpecificInfoOnRecord +{ + [NSNumber numberWithLong:(_pts.dayOfMonth >= 31 ? -1 : _pts.dayOfMonth)]; +} +@end + diff --git a/clang/test/Rewriter/rewrite-api-bug.m b/clang/test/Rewriter/rewrite-api-bug.m new file mode 100644 index 0000000..ebaa0be --- /dev/null +++ b/clang/test/Rewriter/rewrite-api-bug.m @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@interface MyDerived +- (void) instanceMethod; +@end + +@implementation MyDerived +- (void) instanceMethod { +} +@end + diff --git a/clang/test/Rewriter/rewrite-block-argument.m b/clang/test/Rewriter/rewrite-block-argument.m new file mode 100644 index 0000000..898f983 --- /dev/null +++ b/clang/test/Rewriter/rewrite-block-argument.m @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" -emit-llvm -o %t %t-rw.cpp +// radar 7987817 + +void *sel_registerName(const char *); + +@interface Test { +} +@end + +@implementation Test + +- (void)enumerateProvidersWithBlock:(void (^)(void))block { + block(); +} + +- (void)providerEnumerator { + ^(void (^providerBlock)(void)) { + [self enumerateProvidersWithBlock:providerBlock]; + }; +} + +- (void)testNilBlock { + [self enumerateProvidersWithBlock:0]; +} + +@end + + + +int main(int argc, char *argv[]) { + return 0; +} diff --git a/clang/test/Rewriter/rewrite-block-consts.mm b/clang/test/Rewriter/rewrite-block-consts.mm new file mode 100644 index 0000000..1d6de8c --- /dev/null +++ b/clang/test/Rewriter/rewrite-block-consts.mm @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D__block="" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar:// 8243071 + +void x(int y) {} +void f() { + const int bar = 3; + int baz = 4; + __block int bab = 4; + __block const int bas = 5; + void (^b)() = ^{ + x(bar); + x(baz); + x(bab); + x(bas); + b(); + }; + b(); +} diff --git a/clang/test/Rewriter/rewrite-block-ivar-call.mm b/clang/test/Rewriter/rewrite-block-ivar-call.mm new file mode 100644 index 0000000..2ec27b3 --- /dev/null +++ b/clang/test/Rewriter/rewrite-block-ivar-call.mm @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -rewrite-objc -fobjc-fragile-abi -o - %s + +@interface Foo { + void (^_block)(void); +} +@end + +@implementation Foo +- (void)bar { + _block(); +} +@end diff --git a/clang/test/Rewriter/rewrite-block-literal-1.mm b/clang/test/Rewriter/rewrite-block-literal-1.mm new file mode 100644 index 0000000..f152117 --- /dev/null +++ b/clang/test/Rewriter/rewrite-block-literal-1.mm @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 9254348 +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp +// rdar://11259664 + +void *sel_registerName(const char *); +typedef void (^BLOCK_TYPE)(void); + +@interface CoreDAVTaskGroup +{ + int IVAR; +} +@property int IVAR; +- (void) setCompletionBlock : (BLOCK_TYPE) arg; +@end + +@implementation CoreDAVTaskGroup +- (void)_finishInitialSync { + CoreDAVTaskGroup *folderPost; + folderPost.completionBlock = ^{ + self.IVAR = 0; + [self _finishInitialSync]; + }; + + [folderPost setCompletionBlock : (^{ + self.IVAR = 0; + })]; +} +@dynamic IVAR; +- (void) setCompletionBlock : (BLOCK_TYPE) arg {} +@end + + diff --git a/clang/test/Rewriter/rewrite-block-literal.mm b/clang/test/Rewriter/rewrite-block-literal.mm new file mode 100644 index 0000000..083312e --- /dev/null +++ b/clang/test/Rewriter/rewrite-block-literal.mm @@ -0,0 +1,76 @@ +// RUN: %clang_cc1 -E %s -o %t.mm +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp + +// rdar: // 11006566 + +void I( void (^)(void)); +void (^noop)(void); + +void nothing(); +int printf(const char*, ...); + +typedef void (^T) (void); + +void takeblock(T); +int takeintint(int (^C)(int)) { return C(4); } + +T somefunction() { + if (^{ }) + nothing(); + + noop = ^{}; + + noop = ^{printf("\nClosure\n"); }; + + I(^{ }); + + return ^{printf("\nClosure\n"); }; +} +void test2() { + int x = 4; + + takeblock(^{ printf("%d\n", x); }); + + while (1) { + takeblock(^{ + while(1) break; // ok + }); + break; + } +} + +void test4() { + void (^noop)(void) = ^{}; + void (*noop2)() = 0; +} + +void myfunc(int (^block)(int)) {} + +void myfunc3(const int *x); + +void test5() { + int a; + + myfunc(^(int abcd) { + myfunc3(&a); + return 1; + }); +} + +void *X; + +static int global_x = 10; +void (^global_block)(void) = ^{ printf("global x is %d\n", global_x); }; + +// CHECK: static __global_block_block_impl_0 __global_global_block_block_impl_0((void *)__global_block_block_func_0, &__global_block_block_desc_0_DATA); +// CHECK: void (*global_block)(void) = (void (*)())&__global_global_block_block_impl_0; + +typedef void (^void_block_t)(void); + +static const void_block_t myBlock = ^{ }; + +static const void_block_t myBlock2 = ^ void(void) { }; diff --git a/clang/test/Rewriter/rewrite-block-pointer.mm b/clang/test/Rewriter/rewrite-block-pointer.mm new file mode 100644 index 0000000..58407a7 --- /dev/null +++ b/clang/test/Rewriter/rewrite-block-pointer.mm @@ -0,0 +1,109 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp +// radar 7638400 + +typedef void * id; +void *sel_registerName(const char *); + +@interface X +@end + +void foo(void (^block)(int)); + +@implementation X +static void enumerateIt(void (^block)(id, id, char *)) { + foo(^(int idx) { }); +} +@end + +// radar 7651312 +void apply(void (^block)(int)); + +static void x(int (^cmp)(int, int)) { + x(cmp); +} + +static void y(int (^cmp)(int, int)) { + apply(^(int sect) { + x(cmp); + }); +} + +// radar 7659483 +void *_Block_copy(const void *aBlock); +void x(void (^block)(void)) { + block = ((__typeof(block))_Block_copy((const void *)(block))); +} + +// radar 7682763 +@interface Y { +@private + id _private; +} +- (void (^)(void))f; +@end + +typedef void (^void_block_t)(void); + +@interface YY { + void_block_t __completion; +} +@property (copy) void_block_t f; +@end + +@implementation Y +- (void (^)(void))f { + return [_private f]; +} + +@end + +// rdar: //8608902 +@protocol CoreDAVAccountInfoProvider; +@protocol CodeProvider; +typedef void (^BDVDiscoveryCompletionHandler)(int success, id<CoreDAVAccountInfoProvider> discoveredInfo); +typedef void (^BDVDiscoveryCompletion)(id<CodeProvider> codeInfo, int success, id<CoreDAVAccountInfoProvider> discoveredInfo); +typedef void (^BDVDiscovery)(int success); +typedef void (^BDVDisc)(id<CoreDAVAccountInfoProvider> discoveredInfo, id<CodeProvider> codeInfo, + int success, id<CoreDAVAccountInfoProvider, CodeProvider> Info); +typedef void (^BLOCK)(id, id<CoreDAVAccountInfoProvider>, id<CodeProvider> codeInfo); +typedef void (^EMPTY_BLOCK)(); +typedef void (^ BDVDiscoveryCompletion1 )(id<CodeProvider> codeInfo, int success, id<CoreDAVAccountInfoProvider> discoveredInfo); + +void (^BL)(void(^arg1)(), int i1, void(^arg)(int)); + +typedef void (^iscoveryCompletionHandler)(void(^arg1)(), id<CoreDAVAccountInfoProvider> discoveredInfo); + +typedef void (^DVDisc)(id<CoreDAVAccountInfoProvider> discoveredInfo, id<CodeProvider> codeInfo, + void(^arg1)(), int i1, void(^arg)(id<CoreDAVAccountInfoProvider>), + int success, id<CoreDAVAccountInfoProvider, CodeProvider> Info); + + +@interface I @end +@interface INTF @end +void (^BLINT)(I<CoreDAVAccountInfoProvider>* ARG, INTF<CodeProvider, CoreDAVAccountInfoProvider>* ARG1); + +void test8608902() { + BDVDiscoveryCompletionHandler ppp; + ppp(1, 0); +} + +void test9204669() { + __attribute__((__blocks__(byref))) char (^addChangeToData)(); + + addChangeToData = ^() { + return 'b'; + }; + addChangeToData(); +} + +void test9204669_1() { + __attribute__((__blocks__(byref))) void (^addChangeToData)(); + + addChangeToData = ^() { + addChangeToData(); + }; +} + diff --git a/clang/test/Rewriter/rewrite-block-property.m b/clang/test/Rewriter/rewrite-block-property.m new file mode 100644 index 0000000..5c44b7d --- /dev/null +++ b/clang/test/Rewriter/rewrite-block-property.m @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +// rdar://9055596 +void *sel_registerName(const char *); + +typedef void (^FooBlock) (int foo, int bar, int baz); + +@interface Foo { } +@property (readwrite, copy, nonatomic) FooBlock fooBlock; +@end + +static void Bar (Foo * foo) { + foo.fooBlock (1,2,3); +} diff --git a/clang/test/Rewriter/rewrite-byref-in-nested-blocks.mm b/clang/test/Rewriter/rewrite-byref-in-nested-blocks.mm new file mode 100644 index 0000000..a659383 --- /dev/null +++ b/clang/test/Rewriter/rewrite-byref-in-nested-blocks.mm @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp +// radar 7692350 + +void f(void (^block)(void)); + +@interface X { + int y; +} +- (void)foo; +@end + +@implementation X +- (void)foo { + __block int kerfluffle; + // radar 7692183 + __block x; + f(^{ + f(^{ + y = 42; + kerfluffle = 1; + x = 2; + }); + }); +} +@end diff --git a/clang/test/Rewriter/rewrite-byref-vars.mm b/clang/test/Rewriter/rewrite-byref-vars.mm new file mode 100644 index 0000000..14a182a --- /dev/null +++ b/clang/test/Rewriter/rewrite-byref-vars.mm @@ -0,0 +1,57 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 7540194 + +extern "C" __declspec(dllexport) void BreakTheRewriter(int i) { + __block int aBlockVariable = 0; + void (^aBlock)(void) = ^ { + aBlockVariable = 42; + }; + aBlockVariable++; + if (i) { + __block int bbBlockVariable = 0; + void (^aBlock)(void) = ^ { + bbBlockVariable = 42; + }; + } +} + +__declspec(dllexport) extern "C" __declspec(dllexport) void XXXXBreakTheRewriter(void) { + + __block int aBlockVariable = 0; + void (^aBlock)(void) = ^ { + aBlockVariable = 42; + }; + aBlockVariable++; + void (^bBlocks)(void) = ^ { + aBlockVariable = 43; + }; + void (^c)(void) = ^ { + aBlockVariable = 44; + }; + +} + +@interface I +{ + id list; +} +- (void) Meth; +// radar 7589385 use before definition +- (void) allObjects; +@end + +@implementation I +// radar 7589385 use before definition +- (void) allObjects { + __attribute__((__blocks__(byref))) id *listp; + + ^(void) { + *listp++ = 0; + }; +} +- (void) Meth { __attribute__((__blocks__(byref))) void ** listp = (void **)list; } +@end + +// $CLANG -cc1 -fms-extensions -rewrite-objc -fobjc-fragile-abi -x objective-c++ -fblocks bug.mm +// g++ -c -D"__declspec(X)=" bug.cpp diff --git a/clang/test/Rewriter/rewrite-captured-nested-bvar.c b/clang/test/Rewriter/rewrite-captured-nested-bvar.c new file mode 100644 index 0000000..a48de4b --- /dev/null +++ b/clang/test/Rewriter/rewrite-captured-nested-bvar.c @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -x c -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: FileCheck --input-file=%t-rw.cpp %s +// rdar://9006279 + +void q(void (^p)(void)) { + p(); +} + +void f() { + __block char BYREF_VAR_CHECK = 'a'; + __block char d = 'd'; + q(^{ + q(^{ + __block char e = 'e'; + char l = 'l'; + BYREF_VAR_CHECK = 'b'; + d = 'd'; + q(^{ + e = '1'; + BYREF_VAR_CHECK = '2'; + d = '3'; + } + ); + }); + }); +} + +int main() { + f(); + return 0; +} + +// CHECK 2: (__Block_byref_BYREF_VAR_CHECK_0 *)BYREF_VAR_CHECK +// CHECK: (__Block_byref_BYREF_VAR_CHECK_0 *)&BYREF_VAR_CHECK +// CHECK: (struct __Block_byref_BYREF_VAR_CHECK_0 *)&BYREF_VAR_CHECK, (struct __Block_byref_d_1 *)&d, 570425344)); diff --git a/clang/test/Rewriter/rewrite-cast-ivar-access.mm b/clang/test/Rewriter/rewrite-cast-ivar-access.mm new file mode 100644 index 0000000..ccc1cde --- /dev/null +++ b/clang/test/Rewriter/rewrite-cast-ivar-access.mm @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// radar 7575882 + +@interface F { + int supervar; +} +@end + +@interface G : F { +@public + int ivar; +} +@end + +@implementation G +- (void)foo:(F *)arg { + int q = arg->supervar; + int v = ((G *)arg)->ivar; +} +@end + +void objc_assign_strongCast(id); +void __CFAssignWithWriteBarrier(void **location, void *value) { + objc_assign_strongCast((id)value); +} + +// radar 7607605 +@interface RealClass { + @public + int f; +} +@end + +@implementation RealClass +@end + +@interface Foo { + id reserved; +} +@end + +@implementation Foo +- (void)bar { + ((RealClass*)reserved)->f = 99; +} +@end + +// CHECK-LP: ((struct G_IMPL *)arg)->ivar + +// CHECK-LP: objc_assign_strongCast((id)value) + +// CHECK-LP: ((struct RealClass_IMPL *)((RealClass *)((struct Foo_IMPL *)self)->reserved))->f diff --git a/clang/test/Rewriter/rewrite-cast-ivar-modern-access.mm b/clang/test/Rewriter/rewrite-cast-ivar-modern-access.mm new file mode 100644 index 0000000..4a6cb32 --- /dev/null +++ b/clang/test/Rewriter/rewrite-cast-ivar-modern-access.mm @@ -0,0 +1,46 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +@interface F { + int supervar; +} +@end + +@interface G : F { +@public + int ivar; +} +@end + +@implementation G +- (void)foo:(F *)arg { + int q = arg->supervar; + int v = ((G *)arg)->ivar; +} +@end + +void objc_assign_strongCast(id); +void __CFAssignWithWriteBarrier(void **location, void *value) { + objc_assign_strongCast((id)value); +} + +// radar 7607605 +@interface RealClass { + @public + int f; +} +@end + +@implementation RealClass +@end + +@interface Foo { + id reserved; +} +@end + +@implementation Foo +- (void)bar { + ((RealClass*)reserved)->f = 99; +} +@end diff --git a/clang/test/Rewriter/rewrite-cast-to-bool.mm b/clang/test/Rewriter/rewrite-cast-to-bool.mm new file mode 100644 index 0000000..b3272b6 --- /dev/null +++ b/clang/test/Rewriter/rewrite-cast-to-bool.mm @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 9899834 + +void *sel_registerName(const char *); + +@interface NSURLDownload +-(void)setBool:(bool)Arg; +@end + +@implementation NSURLDownload +- (void) Meth +{ + [self setBool:(signed char)1]; +} +@end + diff --git a/clang/test/Rewriter/rewrite-category-property.mm b/clang/test/Rewriter/rewrite-category-property.mm new file mode 100644 index 0000000..b54bb67 --- /dev/null +++ b/clang/test/Rewriter/rewrite-category-property.mm @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -x objective-c++ -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// radar 7630636 + +@class Y, Z; + +@interface A +@property (readonly) Y *y; +@end + +@interface A (cat) +@property (readonly) Z *z; +@end + +// CHECK-LP: // @property (readonly) Z *z; diff --git a/clang/test/Rewriter/rewrite-constructor-init.mm b/clang/test/Rewriter/rewrite-constructor-init.mm new file mode 100644 index 0000000..f12de1f --- /dev/null +++ b/clang/test/Rewriter/rewrite-constructor-init.mm @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar : // 8213998 + +typedef unsigned int NSUInteger; + +typedef struct _NSRange { + NSUInteger location; + NSUInteger length; +} NSRange; + +static __inline NSRange NSMakeRange(NSUInteger loc, NSUInteger len) { + NSRange r; + r.location = loc; + r.length = len; + return r; +} + +void bar() { + __block NSRange previousRange = NSMakeRange(0, 0); + void (^blk)() = ^{ + previousRange = NSMakeRange(1, 0); + }; +} diff --git a/clang/test/Rewriter/rewrite-eh.m b/clang/test/Rewriter/rewrite-eh.m new file mode 100644 index 0000000..46d1930 --- /dev/null +++ b/clang/test/Rewriter/rewrite-eh.m @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi -fobjc-exceptions -o - %s +// rdar://7522880 + +@interface NSException +@end + +@interface Foo +@end + +@implementation Foo +- (void)bar { + @try { + } @catch (NSException *e) { + } + @catch (Foo *f) { + } + @catch (...) { + } +} +@end diff --git a/clang/test/Rewriter/rewrite-elaborated-type.mm b/clang/test/Rewriter/rewrite-elaborated-type.mm new file mode 100644 index 0000000..a0c7e43 --- /dev/null +++ b/clang/test/Rewriter/rewrite-elaborated-type.mm @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D_Bool=bool -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D_Bool=bool -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp +// radar 8143056 + +typedef struct objc_class *Class; +typedef unsigned NSPointerFunctionsOptions; +extern "C" id NSClassFromObject(id object); +void *sel_registerName(const char *); + +struct NSSlice { + int i1; +}; + +@interface NSConcretePointerFunctions { + @public + struct NSSlice slice; +} +- (bool)initializeSlice:(struct NSSlice *)slicep withOptions:(NSPointerFunctionsOptions)options; +@end + +@implementation NSConcretePointerFunctions +- (id)initWithOptions:(NSPointerFunctionsOptions)options { + if (![NSClassFromObject(self) initializeSlice:&slice withOptions:options]) + return 0; + return self; + } +- (bool)initializeSlice:(struct NSSlice *)slicep withOptions:(NSPointerFunctionsOptions)options { + return 0; + } +@end + +@interface I1 @end + +@implementation I1 ++ (struct s1 *) f0 { + return 0; +} +@end diff --git a/clang/test/Rewriter/rewrite-extern-c.mm b/clang/test/Rewriter/rewrite-extern-c.mm new file mode 100644 index 0000000..c610493 --- /dev/null +++ b/clang/test/Rewriter/rewrite-extern-c.mm @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -rewrite-objc -fobjc-fragile-abi -o - %s +// radar 7546096 + +extern "C" { + short foo() { } +} +typedef unsigned char Boolean; + diff --git a/clang/test/Rewriter/rewrite-foreach-1.m b/clang/test/Rewriter/rewrite-foreach-1.m new file mode 100644 index 0000000..f57e13c --- /dev/null +++ b/clang/test/Rewriter/rewrite-foreach-1.m @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@protocol P @end + +@interface MyList +@end + +@implementation MyList +- (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount +{ + return 0; +} +@end + +@interface MyList (BasicTest) +- (void)compilerTestAgainst; +@end + +int LOOP(); +@implementation MyList (BasicTest) +- (void)compilerTestAgainst { + id el; + for (el in self) + { LOOP(); } + for (id el1 in self) + LOOP(); + + for (el in (self)) + if (el) + LOOP(); + + for (el in ((self))) + if (el) + LOOP(); +} +@end + diff --git a/clang/test/Rewriter/rewrite-foreach-2.m b/clang/test/Rewriter/rewrite-foreach-2.m new file mode 100644 index 0000000..228612a --- /dev/null +++ b/clang/test/Rewriter/rewrite-foreach-2.m @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@protocol P @end + +@interface MyList +@end + +@implementation MyList +- (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount +{ + return 0; +} +@end + +@interface MyList (BasicTest) +- (void)compilerTestAgainst; +@end + +int LOOP(); +int INNERLOOP(); +void END_LOOP(); +@implementation MyList (BasicTest) +- (void)compilerTestAgainst { + id el; + for (el in self) + { LOOP(); + for (id el1 in self) + INNER_LOOP(); + + END_LOOP(); + } +} +@end + diff --git a/clang/test/Rewriter/rewrite-foreach-3.m b/clang/test/Rewriter/rewrite-foreach-3.m new file mode 100644 index 0000000..ef3803f --- /dev/null +++ b/clang/test/Rewriter/rewrite-foreach-3.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@protocol P @end + +@interface MyList +@end + +@implementation MyList +- (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount +{ + return 0; +} +@end + +@interface MyList (BasicTest) +- (void)compilerTestAgainst; +@end + +int LOOP(); +@implementation MyList (BasicTest) +- (void)compilerTestAgainst { + MyList * el; + for (el in self) + { LOOP(); } + for (MyList * el1 in self) + LOOP(); +} +@end + diff --git a/clang/test/Rewriter/rewrite-foreach-4.m b/clang/test/Rewriter/rewrite-foreach-4.m new file mode 100644 index 0000000..42cb2fb --- /dev/null +++ b/clang/test/Rewriter/rewrite-foreach-4.m @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@interface MyList +- (id) allKeys; +@end + +@implementation MyList +- (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount +{ + return 0; +} +- (id) allKeys { return 0; } +@end + +@interface MyList (BasicTest) +- (void)compilerTestAgainst; +@end + +int LOOP(); +@implementation MyList (BasicTest) +- (void)compilerTestAgainst { + MyList * el; + for (el in [el allKeys]) { LOOP(); + } + + for (id el1 in[el allKeys]) { LOOP(); + } + for (el in([el allKeys])) { LOOP(); + } +} +@end + diff --git a/clang/test/Rewriter/rewrite-foreach-5.m b/clang/test/Rewriter/rewrite-foreach-5.m new file mode 100644 index 0000000..2940f45 --- /dev/null +++ b/clang/test/Rewriter/rewrite-foreach-5.m @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +void *sel_registerName(const char *); +void objc_enumerationMutation(id); + +@interface MyList +- (id) allKeys; +@end + +@implementation MyList +- (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount +{ + return 0; +} +- (id) allKeys { return 0; } +@end + +@interface MyList (BasicTest) +- (void)compilerTestAgainst; +@end + +int LOOP(); +@implementation MyList (BasicTest) +- (void)compilerTestAgainst { + MyList * el; + int i; + for (el in [el allKeys]) { + for (i = 0; i < 10; i++) + if (i == 5) + break; + + if (el == 0) + break; + if (el != self) + continue; + LOOP(); + } + + for (id el1 in[el allKeys]) { + LOOP(); + for (el in self) { + if (el) + continue; + } + if (el1) + break; + } +} +@end + diff --git a/clang/test/Rewriter/rewrite-foreach-6.m b/clang/test/Rewriter/rewrite-foreach-6.m new file mode 100644 index 0000000..968c6f4 --- /dev/null +++ b/clang/test/Rewriter/rewrite-foreach-6.m @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar://5716356 +// FIXME: Should be able to pipe into clang, but code is not +// yet correct for other reasons: rdar://5716940 + +void *sel_registerName(const char *); +void objc_enumerationMutation(id); + +@class NSNotification; +@class NSMutableArray; + +void foo(NSMutableArray *notificationArray, id X) { + for (NSNotification *notification in notificationArray) + [X postNotification:notification]; +} + diff --git a/clang/test/Rewriter/rewrite-foreach-7.m b/clang/test/Rewriter/rewrite-foreach-7.m new file mode 100644 index 0000000..8c9293f --- /dev/null +++ b/clang/test/Rewriter/rewrite-foreach-7.m @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@class NSArray; +int main() { + NSArray *foo; + for (Class c in foo) { } +} diff --git a/clang/test/Rewriter/rewrite-foreach-in-block.mm b/clang/test/Rewriter/rewrite-foreach-in-block.mm new file mode 100644 index 0000000..fd34212 --- /dev/null +++ b/clang/test/Rewriter/rewrite-foreach-in-block.mm @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp +// rdar:// 9878420 + +void objc_enumerationMutation(id); +void *sel_registerName(const char *); +typedef void (^CoreDAVCompletionBlock)(void); + +@interface I +- (void)M; +- (id) ARR; +@property (readwrite, copy, nonatomic) CoreDAVCompletionBlock c; +@end + +@implementation I +- (void)M { + I* ace; + self.c = ^() { + // sanity test for the changes. + [ace ARR]; + for (I *privilege in [ace ARR]) { } + }; + self.c = ^() { + // sanity test for the changes. + [ace ARR]; + }; +} +@end diff --git a/clang/test/Rewriter/rewrite-foreach-protocol-id.m b/clang/test/Rewriter/rewrite-foreach-protocol-id.m new file mode 100644 index 0000000..034fb7a --- /dev/null +++ b/clang/test/Rewriter/rewrite-foreach-protocol-id.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar:// 9039342 + +void *sel_registerName(const char *); +void objc_enumerationMutation(id); + +@protocol CoreDAVLeafDataPayload @end + +@class NSString; + +@interface CoreDAVAction +- (id) context; +@end + +@interface I +{ + id uuidsToAddActions; +} +@end + +@implementation I +- (void) Meth { + for (id<CoreDAVLeafDataPayload> uuid in uuidsToAddActions) { + CoreDAVAction *action = 0; + id <CoreDAVLeafDataPayload> payload = [action context]; + } +} +@end diff --git a/clang/test/Rewriter/rewrite-forward-class.m b/clang/test/Rewriter/rewrite-forward-class.m new file mode 100644 index 0000000..0ac620a --- /dev/null +++ b/clang/test/Rewriter/rewrite-forward-class.m @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar://6969189 + +@class XX; +@class YY, ZZ, QQ; +@class ISyncClient, SMSession, ISyncManager, ISyncSession, SMDataclassInfo, SMClientInfo, + DMCConfiguration, DMCStatusEntry; + +@interface QQ + +@end + +@interface SMDataclassInfo : QQ +- (XX*) Meth; +- (DMCStatusEntry*)Meth2; +@end + +@implementation SMDataclassInfo +- (XX*) Meth { return 0; } +- (DMCStatusEntry*)Meth2 { return 0; } +@end + +@interface YY +{ + ISyncClient *p1; + ISyncSession *p2; +} +@property (copy) ISyncClient *p1; +@end + +@implementation YY +@synthesize p1; +@end + diff --git a/clang/test/Rewriter/rewrite-forward-class.mm b/clang/test/Rewriter/rewrite-forward-class.mm new file mode 100644 index 0000000..8e4eda6 --- /dev/null +++ b/clang/test/Rewriter/rewrite-forward-class.mm @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +extern "C" { +@class XX; +@class YY, ZZ, QQ; +@class ISyncClient, SMSession, ISyncManager, ISyncSession, SMDataclassInfo, SMClientInfo, + DMCConfiguration, DMCStatusEntry; + +@interface QQ + +@end + +@interface SMDataclassInfo : QQ +- (XX*) Meth; +- (DMCStatusEntry*)Meth2; +@end + +@implementation SMDataclassInfo +- (XX*) Meth { return 0; } +- (DMCStatusEntry*)Meth2 { return 0; } +@end + +@interface YY +{ + ISyncClient *p1; + ISyncSession *p2; +} +@property (copy) ISyncClient *p1; +@end + +@implementation YY +@synthesize p1; +@end + +extern "C" { +@class CCC; +@class Protocol, P , Q; +int I,J,K; +}; + +}; + + diff --git a/clang/test/Rewriter/rewrite-function-decl.mm b/clang/test/Rewriter/rewrite-function-decl.mm new file mode 100644 index 0000000..883d393 --- /dev/null +++ b/clang/test/Rewriter/rewrite-function-decl.mm @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -fms-extensions -rewrite-objc -fobjc-fragile-abi -x objective-c++ -fblocks -o - %s + +extern "C" __declspec(dllexport) void BreakTheRewriter(void) { + __block int aBlockVariable = 0; + void (^aBlock)(void) = ^ { + aBlockVariable = 42; + }; + aBlockVariable++; + void (^bBlocks)(void) = ^ { + aBlockVariable = 43; + }; + void (^c)(void) = ^ { + aBlockVariable = 44; + }; + +} +__declspec(dllexport) extern "C" void AnotherBreakTheRewriter(int *p1, double d) { + + __block int bBlockVariable = 0; + void (^aBlock)(void) = ^ { + bBlockVariable = 42; + }; + bBlockVariable++; + void (^bBlocks)(void) = ^ { + bBlockVariable = 43; + }; + void (^c)(void) = ^ { + bBlockVariable = 44; + }; + +} diff --git a/clang/test/Rewriter/rewrite-implementation.mm b/clang/test/Rewriter/rewrite-implementation.mm new file mode 100644 index 0000000..2cc3387 --- /dev/null +++ b/clang/test/Rewriter/rewrite-implementation.mm @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 7649577 + +@interface a +@end + +@interface b : a +@end + +@implementation b +@end + +@interface NSArray @end +@class NSArray; +@implementation NSArray @end diff --git a/clang/test/Rewriter/rewrite-ivar-use.m b/clang/test/Rewriter/rewrite-ivar-use.m new file mode 100644 index 0000000..53b07c4 --- /dev/null +++ b/clang/test/Rewriter/rewrite-ivar-use.m @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 7490331 + +void *sel_registerName(const char *); + +@interface Foo { + int a; + id b; +} +- (void)bar; +- (void)baz:(id)q; +@end + +@implementation Foo +// radar 7522803 +static void foo(id bar) { + int i = ((Foo *)bar)->a; +} + +- (void)bar { + a = 42; + [self baz:b]; +} +- (void)baz:(id)q { +} +@end + diff --git a/clang/test/Rewriter/rewrite-local-externs-in-block.mm b/clang/test/Rewriter/rewrite-local-externs-in-block.mm new file mode 100644 index 0000000..35d282b --- /dev/null +++ b/clang/test/Rewriter/rewrite-local-externs-in-block.mm @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 7735987 + +extern "C" int printf(const char*, ...); + +void bar(void (^block)()) { + block(); +} + +int main() { + static int myArr[3] = {1, 2, 3}; + printf ("%d %d %d\n", myArr[0], myArr[1], myArr[2]); + + bar(^{ + printf ("%d %d %d\n", myArr[0], myArr[1], myArr[2]); + myArr[0] = 42; + myArr[2] = 100; + printf ("%d %d %d\n", myArr[0], myArr[1], myArr[2]); + }); + + printf ("%d %d %d\n", myArr[0], myArr[1], myArr[2]); +} diff --git a/clang/test/Rewriter/rewrite-local-static-id.mm b/clang/test/Rewriter/rewrite-local-static-id.mm new file mode 100644 index 0000000..b002b6e --- /dev/null +++ b/clang/test/Rewriter/rewrite-local-static-id.mm @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" -emit-llvm -o %t %t-rw.cpp +// radar 7946975 + +void *sel_registerName(const char *); + +@interface foo +@end + +@interface foo2 : foo ++ (id)x; +@end + +typedef void (^b_t)(void); + +void bar(b_t block); + +void f() { + static id foo = 0; + bar(^{ + foo = [foo2 x]; + }); +} + diff --git a/clang/test/Rewriter/rewrite-message-expr.mm b/clang/test/Rewriter/rewrite-message-expr.mm new file mode 100644 index 0000000..dafb31b --- /dev/null +++ b/clang/test/Rewriter/rewrite-message-expr.mm @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// radar 7617047 + +@interface Baz +- (id)y; ++ (id)z; +@end + +@interface Foo { +@public + int bar; +} +@end + +extern Foo* x(id a); + +int f(Baz *baz) { + int i = x([Baz z])->bar; + int j = ((Foo*)[Baz z])->bar; + int k = x([baz y])->bar; + return i+j+k; +} + +// CHECK-LP: ((struct Foo_IMPL *)x(((id (*)(id, SEL))(void *)objc_msgSend)(objc_getClass("Baz"), sel_registerName("z"))))->bar diff --git a/clang/test/Rewriter/rewrite-modern-array-literal.mm b/clang/test/Rewriter/rewrite-modern-array-literal.mm new file mode 100644 index 0000000..208e646 --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-array-literal.mm @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -x objective-c++ -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar://10803676 + +extern "C" void *sel_registerName(const char *); +@class NSString; + +@interface NSNumber ++ (NSNumber *)numberWithChar:(char)value; ++ (NSNumber *)numberWithInt:(int)value; +@end + +typedef unsigned long NSUInteger; + +@interface NSArray ++ (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt; +@end + +int i; +int main() { + NSArray *array = @[ @"Hello", @1234 ]; + if (i) { + NSArray *array = @[ @"Hello", @1234 ]; + } + NSArray *array1 = @[ @"Hello", @1234, @[ @"Hello", @1234 ] ]; +} + diff --git a/clang/test/Rewriter/rewrite-modern-block-ivar-call.mm b/clang/test/Rewriter/rewrite-modern-block-ivar-call.mm new file mode 100644 index 0000000..1bafbdd --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-block-ivar-call.mm @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -E %s -o %t.m +// RUN: %clang_cc1 -fblocks -rewrite-objc -fms-extensions %t.m -o %t-rw.cpp +// RUN: FileCheck --input-file=%t-rw.cpp %s +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +@interface Foo { + void (^_block)(void); +} +@end + +@implementation Foo +- (void)bar { + _block(); +} +@end + +// CHECK: ((void (*)(struct __block_impl *))((struct __block_impl *)(*(void (**)(void))((char *)self + OBJC_IVAR_$_Foo$_block)))->FuncPtr)((struct __block_impl *)(*(void (**)(void))((char *)self + OBJC_IVAR_$_Foo$_block))); diff --git a/clang/test/Rewriter/rewrite-modern-block.mm b/clang/test/Rewriter/rewrite-modern-block.mm new file mode 100644 index 0000000..8da723d --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-block.mm @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar://11230308 + +typedef struct { + char byte0; + char byte1; +} CFUUIDBytes; + +void x(void *); + +void y() { + __block CFUUIDBytes bytes; + + void (^bar)() = ^{ + x(&bytes); + }; +} + +// rdar://11236342 +int foo() { + __block int hello; +} diff --git a/clang/test/Rewriter/rewrite-modern-catch.m b/clang/test/Rewriter/rewrite-modern-catch.m new file mode 100644 index 0000000..1900301 --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-catch.m @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +void foo(id arg); + +@interface NSException +@end + +@interface Foo +@end + +@implementation Foo +- (void)bar { + @try { + } @catch (NSException *e) { + foo(e); + } + @catch (Foo *f) { + } + @catch (...) { + @try { + } + @catch (Foo *f1) { + foo(f1); + } + @catch (id pid) { + foo(pid); + } + } +} +@end diff --git a/clang/test/Rewriter/rewrite-modern-class.mm b/clang/test/Rewriter/rewrite-modern-class.mm new file mode 100644 index 0000000..b6be98a --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-class.mm @@ -0,0 +1,70 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +@protocol PROTO @end + +@interface empty_root @end + +@interface root_with_ivars +{ + id ROOT_IVAR; + id ROOT1_IVAR; +} +@end + +@interface MAXIMAL : root_with_ivars<PROTO> +{ + double D_IVAR; + double D_PROPERTY; +} +- (void) V_METH; +@end + +@implementation MAXIMAL +- (void) V_METH {} +@end +//========================================= +@interface empty_class @end + +@implementation empty_class @end +//========================================= +@interface class_empty_root : empty_root @end + +@implementation class_empty_root @end +//========================================= +@interface class_with_ivars : empty_root +{ + int class_with_ivars_IVAR; +} +@end + +@implementation class_with_ivars @end +//========================================= +@interface class_has_no_ivar : root_with_ivars @end + +@implementation class_has_no_ivar @end + +//============================class needs to be synthesized here===================== +@interface SUPER { +@public + double divar; + SUPER *p_super; +} +@end + +@interface INTF @end + +@implementation INTF +- (SUPER *) Meth : (SUPER *)arg { + return arg->p_super; +} +@end + +@class FORM_CLASS; +@interface INTF_DECL { +} +@end + +double Meth(INTF_DECL *p, FORM_CLASS *f) { + return 1.34; +} diff --git a/clang/test/Rewriter/rewrite-modern-container-literal.mm b/clang/test/Rewriter/rewrite-modern-container-literal.mm new file mode 100644 index 0000000..2c2f61d --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-container-literal.mm @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -x objective-c++ -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar://10803676 + +void *sel_registerName(const char *); +typedef unsigned long NSUInteger; +typedef long NSInteger; +typedef bool BOOL; + +@interface NSNumber ++ (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 + +@protocol NSCopying @end + +@interface NSDictionary ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt; +@end + +@interface NSArray ++ (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt; +@end + +@interface NSString<NSCopying> +@end + +id NSUserName(); + +@interface NSDate ++ (id)date; +@end + +int main() { +NSArray *array = @[ @"Hello", NSUserName(), [NSDate date], [NSNumber numberWithInt:42]]; + +NSDictionary *dictionary = @{ @"name" : NSUserName(), @"date" : [NSDate date], @"process" : @"processInfo"}; + +NSDictionary *dict = @{ @"name":@666, @"man":@__objc_yes, @"date":@1.3 }; + +} + diff --git a/clang/test/Rewriter/rewrite-modern-extern-c-func-decl.mm b/clang/test/Rewriter/rewrite-modern-extern-c-func-decl.mm new file mode 100644 index 0000000..82d5a4d --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-extern-c-func-decl.mm @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -fms-extensions -U__declspec -rewrite-objc -x objective-c++ -fblocks -o %t-rw.cpp %s +// RUN: %clang_cc1 -fsyntax-only -Werror -Wno-address-of-temporary -Wno-attributes -D"Class=void*" -D"id=void*" -D"SEL=void*" -U__declspec -D"__declspec(X)=" %t-rw.cpp +// rdar://11131490 + +extern "C" __declspec(dllexport) void BreakTheRewriter(void) { + __block int aBlockVariable = 0; + void (^aBlock)(void) = ^ { + aBlockVariable = 42; + }; + aBlockVariable++; + void (^bBlocks)(void) = ^ { + aBlockVariable = 43; + }; + void (^c)(void) = ^ { + aBlockVariable = 44; + }; + +} +__declspec(dllexport) extern "C" void AnotherBreakTheRewriter(int *p1, double d) { + + __block int bBlockVariable = 0; + void (^aBlock)(void) = ^ { + bBlockVariable = 42; + }; + bBlockVariable++; + void (^bBlocks)(void) = ^ { + bBlockVariable = 43; + }; + void (^c)(void) = ^ { + bBlockVariable = 44; + }; + +} + +int + +__declspec (dllexport) + +main (int argc, char *argv[]) +{ + __block int bBlockVariable = 0; + void (^aBlock)(void) = ^ { + bBlockVariable = 42; + }; +} diff --git a/clang/test/Rewriter/rewrite-modern-ivar-use.mm b/clang/test/Rewriter/rewrite-modern-ivar-use.mm new file mode 100644 index 0000000..ec8d2c7 --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-ivar-use.mm @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw-modern.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw-modern.cpp + +void *sel_registerName(const char *); + +@interface Foo { + int a; + id b; +} +- (void)bar; +- (void)baz:(id)q; +@end + +@implementation Foo +// radar 7522803 +static void foo(id bar) { + int i = ((Foo *)bar)->a; +} + +- (void)bar { + a = 42; +} +- (void)baz:(id)q { +} +@end + diff --git a/clang/test/Rewriter/rewrite-modern-ivars-1.mm b/clang/test/Rewriter/rewrite-modern-ivars-1.mm new file mode 100644 index 0000000..376d300 --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-ivars-1.mm @@ -0,0 +1,89 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +@interface NSCheapMutableString { +@private + struct S s0; + union { + char *fat; + unsigned char *thin; + } contents; + + struct { + unsigned int isFat:1; + unsigned int freeWhenDone:1; + unsigned int refs:30; + } flags; + + struct S { + int iS1; + double dS1; + } others; + + union U { + int iU1; + double dU1; + } u_others; + + enum { + One, Two + } E1; + + enum e { + Yes = 1, + No = 0 + } BoOl; + + struct S s1; + + enum e E2; + + union { + char *fat; + unsigned char *thin; + } Last_contents; + + struct { + unsigned int isFat:1; + unsigned int freeWhenDone:1; + unsigned int refs:30; + } Last_flags; +} +@end + +@interface III { +@private + struct S s0; + + union { + char *fat; + unsigned char *thin; + } contents; + + struct { + unsigned int isFat:1; + unsigned int freeWhenDone:1; + unsigned int refs:30; + } flags; + + enum { + One1 = 1000, Two1, Three1 + } E1; + + struct S s1; + + enum e E2; + + union { + char *fat; + unsigned char *thin; + } Last_contents; + + struct { + unsigned int isFat:1; + unsigned int freeWhenDone:1; + unsigned int refs:30; + } Last_flags; +} +@end + diff --git a/clang/test/Rewriter/rewrite-modern-ivars-2.mm b/clang/test/Rewriter/rewrite-modern-ivars-2.mm new file mode 100644 index 0000000..0faed5c --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-ivars-2.mm @@ -0,0 +1,101 @@ +// RUN: %clang_cc1 -triple i386-apple-darwin9 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +@interface B @end + +@interface A { + struct s0 { + int f0; + int f1; + } f0; + id f1; +__weak B *f2; + int f3 : 5; + struct s1 { + int *f0; + int *f1; + } f4[2][1]; +} +@end + +@interface C : A +@property int p3; +@end + +@implementation C +@synthesize p3 = _p3; +@end + +@interface A() +@property int p0; +@property (assign) __strong id p1; +@property (assign) __weak id p2; +@end + +// FIXME: Check layout for this class, once it is clear what the right +// answer is. +@implementation A +@synthesize p0 = _p0; +@synthesize p1 = _p1; +@synthesize p2 = _p2; +@end + +@interface D : A +@property int p3; +@end + +// FIXME: Check layout for this class, once it is clear what the right +// answer is. +@implementation D +@synthesize p3 = _p3; +@end + +typedef unsigned short UInt16; + + +typedef signed char BOOL; +typedef unsigned int FSCatalogInfoBitmap; + +@interface NSFileLocationComponent { + @private + + id _specifierOrStandardizedPath; + BOOL _carbonCatalogInfoAndNameAreValid; + FSCatalogInfoBitmap _carbonCatalogInfoMask; + id _name; + id _containerComponent; + id _presentableName; + id _iconAsAttributedString; +} +@end + +@implementation NSFileLocationComponent @end + +// rdar://11229770 + +@interface Foo { + int bar:26; +} +@end + +@implementation Foo +@end + +@interface Foo1 { + int bar:26; + int bar2:4; +} +@end + +@implementation Foo1 +@end + +@interface Foo3 { + int foo; + int bar:26; +} +@end + +@implementation Foo3 +@end + diff --git a/clang/test/Rewriter/rewrite-modern-ivars.mm b/clang/test/Rewriter/rewrite-modern-ivars.mm new file mode 100644 index 0000000..5e01a44 --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-ivars.mm @@ -0,0 +1,64 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +@protocol P @end +@protocol P1 @end +@interface INTF +{ + id CLASS_IVAR; + id<P, P1> Q_IVAR; + + void (^_block)(id<P>); + void (*_fptr)(void (^_block)(id<P>)); + char CLASS_EXT_IVAR; + id<P, P1> (^ext_block)(id<P>, INTF<P,P1>*, INTF*); + id IMPL_IVAR; + double D_IMPL_IVAR; + INTF<P> *(*imp_fptr)(void (^_block)(id<P>, INTF<P,P1>*)); + id arr[100]; +} +@end + +@implementation INTF @end + +@interface MISC_INTF +{ + id CLASS_IVAR; + id<P, P1> Q_IVAR; + + void (^_block)(id<P>); + void (*_fptr)(void (^_block)(id<P>)); + unsigned int BF : 8; +} +@end + +@interface MISC_INTF() +{ + char CLASS_EXT_IVAR; + id<P, P1> (^ext_block)(id<P>, MISC_INTF<P,P1>*, MISC_INTF*); +} +@end + +@interface MISC_INTF() { + int II1; + double DD1; } +@end + +@interface MISC_INTF() { int II2; double DD2; } +@end + +@interface MISC_INTF() { int II3; + double DD3; } +@end + +@interface MISC_INTF() { int II4; double DD4; +} +@end + +@implementation MISC_INTF +{ + id IMPL_IVAR; + double D_IMPL_IVAR; + MISC_INTF<P> *(*imp_fptr)(void (^_block)(id<P>, MISC_INTF<P,P1>*)); +} +@end diff --git a/clang/test/Rewriter/rewrite-modern-nested-ivar.mm b/clang/test/Rewriter/rewrite-modern-nested-ivar.mm new file mode 100644 index 0000000..13e31cd --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-nested-ivar.mm @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -E %s -o %t.m +// RUN: %clang_cc1 -fblocks -rewrite-objc -fms-extensions %t.m -o %t-rw.cpp +// RUN: FileCheck --input-file=%t-rw.cpp %s +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +@interface NSURLResponse { +@public + NSURLResponse *InnerResponse; +} +@end + +@interface NSCachedURLResponseInternal +{ + @public + NSURLResponse *response; +} +@end + +@interface NSCachedURLResponse +{ + @private + NSCachedURLResponseInternal *_internal; +} +- (void) Meth; +@end + +@implementation NSCachedURLResponse +- (void) Meth { + _internal->response->InnerResponse = 0; + } +@end + +// CHECK: (*(NSURLResponse **)((char *)(*(NSURLResponse **)((char *)(*(NSCachedURLResponseInternal **)((char *)self + OBJC_IVAR_$_NSCachedURLResponse$_internal)) + OBJC_IVAR_$_NSCachedURLResponseInternal$response)) + OBJC_IVAR_$_NSURLResponse$InnerResponse)) = 0; diff --git a/clang/test/Rewriter/rewrite-modern-protocol-1.mm b/clang/test/Rewriter/rewrite-modern-protocol-1.mm new file mode 100644 index 0000000..7b737fe --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-protocol-1.mm @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -E %s -o %t.mm +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s +// rdar://11248048 + +@protocol NSCopying @end + +@interface INTF<NSCopying> +@end + +@implementation INTF @end + +// CHECK: static struct _protocol_t _OBJC_PROTOCOL_NSCopying +// CHECK: static struct _protocol_t *_OBJC_LABEL_PROTOCOL_$_NSCopying = &_OBJC_PROTOCOL_NSCopying; + diff --git a/clang/test/Rewriter/rewrite-modern-protocol.mm b/clang/test/Rewriter/rewrite-modern-protocol.mm new file mode 100644 index 0000000..a4bd617 --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-protocol.mm @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +@protocol ROOT @end + +@protocol P1 @end + +@protocol P2<ROOT> @end + +@class NSObject; + +@protocol PROTO <P1, P2> +- (id) INST_METHOD; ++ (id) CLASS_METHOD : (id)ARG; +@property id Prop_in_PROTO; +@optional +- (id) opt_instance_method; ++ (id) opt_class_method; +@property (readonly, retain) NSObject *AnotherProperty; +@required +- (id) req; +@optional +- (id) X_opt_instance_method; ++ (id) X_opt_class_method; +@end + +@interface INTF <PROTO, ROOT> +@end + +@implementation INTF +@end diff --git a/clang/test/Rewriter/rewrite-modern-struct-ivar.mm b/clang/test/Rewriter/rewrite-modern-struct-ivar.mm new file mode 100644 index 0000000..09c02df --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-struct-ivar.mm @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -E %s -o %t.mm +// RUN: %clang_cc1 -fblocks -rewrite-objc -fms-extensions %t.mm -o %t-rw.cpp +// RUN: FileCheck --input-file=%t-rw.cpp %s +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +struct S { + int i1; + double d1; + void (^block1)(); +}; + +@interface I +{ + struct S struct_ivar; + + struct S *pstruct_ivar; +} +@end + +@implementation I +- (struct S) dMeth{ return struct_ivar; } +@end + +// CHECK: return (*(struct S *)((char *)self + OBJC_IVAR_$_I$struct_ivar)); diff --git a/clang/test/Rewriter/rewrite-modern-super.mm b/clang/test/Rewriter/rewrite-modern-super.mm new file mode 100644 index 0000000..ee397b3 --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-super.mm @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=struct objc_object *" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar://11239894 + +extern "C" void *sel_registerName(const char *); + +typedef struct objc_class * Class; + +@interface Sub +- (void)dealloc; +@end + +@interface I : Sub +- (void)dealloc; +@end + +@implementation I +- (void)dealloc { + return; + [super dealloc]; +} +@end + diff --git a/clang/test/Rewriter/rewrite-modern-synchronized.m b/clang/test/Rewriter/rewrite-modern-synchronized.m new file mode 100644 index 0000000..e895339 --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-synchronized.m @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +typedef struct objc_class *Class; +typedef struct objc_object { + Class isa; +} *id; + +void *sel_registerName(const char *); + +id SYNCH_EXPR(); +void SYNCH_BODY(); +void SYNCH_BEFORE(); +void SYNC_AFTER(); + +void foo(id sem) +{ + SYNCH_BEFORE(); + @synchronized (SYNCH_EXPR()) { + SYNCH_BODY(); + return; + } + SYNC_AFTER(); + @synchronized ([sem self]) { + SYNCH_BODY(); + return; + } +} + +void test_sync_with_implicit_finally() { + id foo; + @synchronized (foo) { + return; // The rewriter knows how to generate code for implicit finally + } +} diff --git a/clang/test/Rewriter/rewrite-modern-throw.m b/clang/test/Rewriter/rewrite-modern-throw.m new file mode 100644 index 0000000..1912384 --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-throw.m @@ -0,0 +1,67 @@ +// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +typedef struct objc_class *Class; +typedef struct objc_object { + Class isa; +} *id; + +void *sel_registerName(const char *); + +@interface Foo @end +void TRY(); +void SPLATCH(); +void MYTRY(); +void MYCATCH(); + +void foo() { + @try { TRY(); } + @catch (...) { SPLATCH(); @throw; } +} + +int main() +{ + + @try { + MYTRY(); + } + + @catch (Foo* localException) { + MYCATCH(); + @throw localException; + } + + // no catch clause + @try { } + @finally { } +} + + +@interface INST +{ + INST* throw_val; +} + +- (id) ThrowThis; + +- (void) MainMeth; + +@end + + +@implementation INST +- (id) ThrowThis { return 0; } + +- (void) MainMeth { + @try { + MYTRY(); + } + @catch (Foo* localException) { + MYCATCH(); + @throw [self ThrowThis]; + } + @catch (...) { + @throw [throw_val ThrowThis]; + } +} +@end diff --git a/clang/test/Rewriter/rewrite-modern-try-catch-finally.m b/clang/test/Rewriter/rewrite-modern-try-catch-finally.m new file mode 100644 index 0000000..9beab7d --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-try-catch-finally.m @@ -0,0 +1,63 @@ +// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +typedef struct objc_class *Class; +typedef struct objc_object { + Class isa; +} *id; + +extern int printf(const char *, ...); + +int main() { + @try { + } + @finally { + } + while (1) { + @try { + printf("executing try"); + break; + } @finally { + printf("executing finally"); + } + printf("executing after finally block"); + } + @try { + printf("executing try"); + } @finally { + printf("executing finally"); + } + return 0; +} + +void test2_try_with_implicit_finally() { + @try { + return; + } @catch (id e) { + + } +} + +void FINALLY(); +void TRY(); +void CATCH(); + +@interface NSException +@end + +@interface Foo +@end + +@implementation Foo +- (void)bar { + @try { + TRY(); + } + @catch (NSException *e) { + CATCH(); + } + @finally { + FINALLY(); + } +} +@end diff --git a/clang/test/Rewriter/rewrite-modern-try-finally.m b/clang/test/Rewriter/rewrite-modern-try-finally.m new file mode 100644 index 0000000..500133b --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-try-finally.m @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +typedef struct objc_class *Class; +typedef struct objc_object { + Class isa; +} *id; + +void FINALLY(); +void TRY(); +void INNER_FINALLY(); +void INNER_TRY(); +void CHECK(); + +@interface Foo +@end + +@implementation Foo +- (void)bar { + @try { + TRY(); + } + @finally { + FINALLY(); + } + CHECK(); + @try { + TRY(); + } + @finally { + @try { + INNER_TRY(); + } + @finally { + INNER_FINALLY(); + } + FINALLY(); + } +} +@end diff --git a/clang/test/Rewriter/rewrite-modern-typeof.mm b/clang/test/Rewriter/rewrite-modern-typeof.mm new file mode 100644 index 0000000..4650ab7 --- /dev/null +++ b/clang/test/Rewriter/rewrite-modern-typeof.mm @@ -0,0 +1,46 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -Wno-attributes -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +extern "C" { +extern "C" void *_Block_copy(const void *aBlock); +extern "C" void _Block_release(const void *aBlock); +} + +int main() { + __attribute__((__blocks__(byref))) int a = 42; + int save_a = a; + + void (^b)(void) = ^{ + ((__typeof(^{ a = 2; }))_Block_copy((const void *)(^{ a = 2; }))); + }; + + ((__typeof(b))_Block_copy((const void *)(b))); + + return 0; +} + +// CHECK-LP: ((void (^)(void))_Block_copy((const void *)(b))) + +// radar 7628153 +void f() { + int a; + __typeof__(a) aVal = a; + char *a1t = (char *)@encode(__typeof__(a)); + __typeof__(aVal) bVal; + char *a2t = (char *)@encode(__typeof__(bVal)); + __typeof__(bVal) cVal = bVal; + char *a3t = (char *)@encode(__typeof__(cVal)); + +} + +// rdar://11239324 +void x() { + id y; + void (^z)() = ^{ }; + y = (id)((__typeof(z))_Block_copy((const void *)(z))); +} + +// CHECK-LP: int aVal = a; + +// CHECK-LP: int bVal; diff --git a/clang/test/Rewriter/rewrite-nest.m b/clang/test/Rewriter/rewrite-nest.m new file mode 100644 index 0000000..a08f947 --- /dev/null +++ b/clang/test/Rewriter/rewrite-nest.m @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@interface NSMapTable @end +@interface NSEnumerator @end + +typedef unsigned int NSUInteger; + +@interface NSConcreteMapTable : NSMapTable { +@public + NSUInteger capacity; +} +@end + +@interface NSConcreteMapTableValueEnumerator : NSEnumerator { + NSConcreteMapTable *mapTable; +} +@end + +@implementation NSConcreteMapTableValueEnumerator + +- nextObject { + while (mapTable->capacity) { + } + return 0; +} +@end + diff --git a/clang/test/Rewriter/rewrite-nested-blocks-1.mm b/clang/test/Rewriter/rewrite-nested-blocks-1.mm new file mode 100644 index 0000000..25b17cf --- /dev/null +++ b/clang/test/Rewriter/rewrite-nested-blocks-1.mm @@ -0,0 +1,49 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp +// radar 7696893 + +void *sel_registerName(const char *); + +void f(void (^block)(void)); +void f2(id); +void f3(int); +char f4(id, id); + +@interface Baz +- (void)b:(void (^)(void))block; +@end + +@interface Bar +@end + +@interface Foo { + int _x; +} +@end + +@implementation Foo +- (void)method:(Bar *)up { + Baz *down; + int at; + id cq; + __block char didit = 'a'; + __block char upIsFinished = 'b'; + f(^{ + id old_cq; + f2(cq); + [down b:^{ + [down b:^{ + f(^{ + didit = f4(up, down); + upIsFinished = 'c'; + self->_x++; + }); + }]; + }]; + f2(old_cq); + f3(at); + }); +} +@end diff --git a/clang/test/Rewriter/rewrite-nested-blocks-2.mm b/clang/test/Rewriter/rewrite-nested-blocks-2.mm new file mode 100644 index 0000000..d1513f3 --- /dev/null +++ b/clang/test/Rewriter/rewrite-nested-blocks-2.mm @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// grep "static void __FUNC_block_copy_" %t-rw.cpp | count 2 +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp +// grep "static void __FUNC_block_copy_" %t-modern-rw.cpp | count 2 +// rdar://8499592 + +void Outer(void (^bk)()); +void Inner(void (^bk)()); +void INNER_FUNC(id d); + +void FUNC() { + + id bar = (id)42; + Outer(^{ + Inner(^{ + INNER_FUNC(bar); + }); + }); +} diff --git a/clang/test/Rewriter/rewrite-nested-blocks.mm b/clang/test/Rewriter/rewrite-nested-blocks.mm new file mode 100644 index 0000000..d492afa --- /dev/null +++ b/clang/test/Rewriter/rewrite-nested-blocks.mm @@ -0,0 +1,58 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp +// radar 7682149 + + +void f(void (^block)(void)); + +@interface X { + int y; +} +- (void)foo; +@end + +@implementation X +- (void)foo { + f(^{ + f(^{ + f(^{ + y=42; + }); + }); +}); + +} +@end + +struct S { + int y; +}; + +void foo () { + struct S *SELF; + f(^{ + f(^{ + SELF->y = 42; + }); + }); +} + +// radar 7692419 +@interface Bar +@end + +void f(Bar *); +void q(void (^block)(void)); + +void x() { + void (^myblock)(Bar *b) = ^(Bar *b) { + q(^{ + f(b); + }); + }; + + Bar *b = (Bar *)42; + myblock(b); +} diff --git a/clang/test/Rewriter/rewrite-nested-ivar.mm b/clang/test/Rewriter/rewrite-nested-ivar.mm new file mode 100644 index 0000000..bab221d --- /dev/null +++ b/clang/test/Rewriter/rewrite-nested-ivar.mm @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw-modern.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw-modern.cpp +// radar 7583971 + + +@interface NSURLResponse { +@public + NSURLResponse *InnerResponse; +} +@end + +@interface NSCachedURLResponseInternal +{ + @public + NSURLResponse *response; +} +@end + +@interface NSCachedURLResponse +{ + @private + NSCachedURLResponseInternal *_internal; +} +- (void) Meth; +@end + +@implementation NSCachedURLResponse +- (void) Meth { + _internal->response->InnerResponse = 0; + } +@end diff --git a/clang/test/Rewriter/rewrite-nested-property-in-blocks.mm b/clang/test/Rewriter/rewrite-nested-property-in-blocks.mm new file mode 100755 index 0000000..7f9361e --- /dev/null +++ b/clang/test/Rewriter/rewrite-nested-property-in-blocks.mm @@ -0,0 +1,54 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fms-extensions -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fms-extensions -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp +// radar 8608293 + +void *sel_registerName(const char *); + +extern "C" void nowarn(id); + +extern "C" void noblockwarn(void (^)()); + +@interface INTFOFPROP +@property (readwrite, retain) INTFOFPROP *outer; +@property (readwrite, retain) id inner; +@end + +@interface NSSet +- (NSSet *)objectsPassingTest:(char (^)(id obj, char *stop))predicate ; +@end + +@interface INTF +- (NSSet *)Meth; +@end + +@implementation INTF + +- (NSSet *)Meth +{ + NSSet *aces; + + noblockwarn(^() { + INTFOFPROP *ace; + nowarn(ace.outer.inner); + noblockwarn(^() { + INTFOFPROP *ace; + nowarn(ace.outer.inner); + }); + }); + + noblockwarn(^() { + INTFOFPROP *ace; + nowarn(ace.outer.inner); + }); + +return [aces objectsPassingTest:^(id obj, char *stop) + { + INTFOFPROP *ace = (INTFOFPROP *)obj; + nowarn(ace.outer.inner); + return (char)0; + }]; + +} +@end diff --git a/clang/test/Rewriter/rewrite-no-nextline.mm b/clang/test/Rewriter/rewrite-no-nextline.mm new file mode 100644 index 0000000..4ef3715 --- /dev/null +++ b/clang/test/Rewriter/rewrite-no-nextline.mm @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 7946975 + +@interface RootObject { +} +@end void doStuff(); +int main(int argc, char *argv[]) { + return 0; +} diff --git a/clang/test/Rewriter/rewrite-property-attributes.mm b/clang/test/Rewriter/rewrite-property-attributes.mm new file mode 100644 index 0000000..c707603 --- /dev/null +++ b/clang/test/Rewriter/rewrite-property-attributes.mm @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 7214439 + +typedef void (^void_block_t)(void); + +@interface Y { + void_block_t __completion; + Y* YVAR; + id ID; +} +@property (copy) void_block_t completionBlock; +@property (retain) Y* Yblock; +@property (copy) id ID; +@end + +@implementation Y +@synthesize completionBlock=__completion; +@synthesize Yblock = YVAR; +@synthesize ID; +@end + diff --git a/clang/test/Rewriter/rewrite-property-set-cfstring.mm b/clang/test/Rewriter/rewrite-property-set-cfstring.mm new file mode 100644 index 0000000..3ac9065 --- /dev/null +++ b/clang/test/Rewriter/rewrite-property-set-cfstring.mm @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar:// 8527018 + +void *sel_registerName(const char *); + +@class NSString; +@interface CoreDAVDiscoveryAccountInfo { + NSString *_scheme; +} +@property (retain) NSString *scheme; +- (void) Meth ; +@end + +@implementation CoreDAVDiscoveryAccountInfo +@synthesize scheme=_scheme; +- (void) Meth { + CoreDAVDiscoveryAccountInfo *discoveryInfo; + discoveryInfo.scheme = @"https"; +} +@end diff --git a/clang/test/Rewriter/rewrite-protocol-property.mm b/clang/test/Rewriter/rewrite-protocol-property.mm new file mode 100644 index 0000000..3a53f23 --- /dev/null +++ b/clang/test/Rewriter/rewrite-protocol-property.mm @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -Did="void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar:// 8558702 + +@class NSString; +@interface NSObject @end + +@protocol P +@property (retain) NSString* test; +@end + + +@interface A : NSObject <P> { + NSString* _test; +} +@end + + +@implementation A +@synthesize test=_test; +@end + diff --git a/clang/test/Rewriter/rewrite-protocol-qualified.mm b/clang/test/Rewriter/rewrite-protocol-qualified.mm new file mode 100644 index 0000000..f828724 --- /dev/null +++ b/clang/test/Rewriter/rewrite-protocol-qualified.mm @@ -0,0 +1,50 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"id=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 7589414 + +@protocol NSPortDelegate; +@interface NSConnection @end + +@interface NSMessagePort +- (void) clone; +@end + +@implementation NSMessagePort +- (void) clone { + NSConnection <NSPortDelegate> *conn = 0; + id <NSPortDelegate> *idc = 0; +} +@end + +// radar 7607413 +@protocol Proto1, Proto2; + +@protocol Proto +@end + +unsigned char func(id<Proto1, Proto2> inProxy); + +id bar(id); + +void f() { + id a; + id b = bar((id <Proto>)a); +} + +// rdar://8472487 +@protocol NSObject @end +@class NSRunLoop; + +@protocol CoreDAVTaskManager <NSObject> + @property (retain) NSRunLoop *workRunLoop; +@end + + +// rdar://8475819 +@protocol some_protocol; + +void foo (int n) +{ + id<some_protocol> array[n]; +} + diff --git a/clang/test/Rewriter/rewrite-protocol-type-1.m b/clang/test/Rewriter/rewrite-protocol-type-1.m new file mode 100644 index 0000000..5246df4 --- /dev/null +++ b/clang/test/Rewriter/rewrite-protocol-type-1.m @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@protocol MyProto1 +@end + +@protocol MyProto2 +@end + +@interface INTF @end + +INTF <MyProto1> *g1; + +INTF <MyProto1, MyProto2> *g2, *g3; + +INTF <MyProto1> * Func(INTF <MyProto1> *p2, INTF<MyProto1> *p3, INTF *p4, INTF<MyProto1> *p5) +{ + return p2; +} + +INTF <MyProto1, MyProto2> * Func1(INTF *p2, INTF<MyProto1, MyProto2> *p3, INTF *p4, INTF<MyProto1> *p5) +{ + return p3; +} + +@interface Foo +@property int (*hashFunction)(const void *item, int (*size)(const void *item)); +@end diff --git a/clang/test/Rewriter/rewrite-qualified-id.mm b/clang/test/Rewriter/rewrite-qualified-id.mm new file mode 100644 index 0000000..f54bae9 --- /dev/null +++ b/clang/test/Rewriter/rewrite-qualified-id.mm @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 7680953 + +typedef void * id; + +@protocol foo +@end + +@interface CL +{ + id <foo> changeSource; + CL <foo>* changeSource1; +} +@end + +typedef struct x +{ + id <foo> changeSource; +} x; + diff --git a/clang/test/Rewriter/rewrite-rewritten-initializer.mm b/clang/test/Rewriter/rewrite-rewritten-initializer.mm new file mode 100644 index 0000000..14734f9 --- /dev/null +++ b/clang/test/Rewriter/rewrite-rewritten-initializer.mm @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// radar 7669784 + +typedef void * id; +void *sel_registerName(const char *); + +@interface NSMutableString +- (NSMutableString *)string; +@end + +@interface Z +@end + +@implementation Z + +- (void)x { + id numbers; + int i, numbersCount = 42; + __attribute__((__blocks__(byref))) int blockSum = 0; + void (^add)(id n, int idx, char *stop) = ^(id n, int idx, char *stop) { }; + [numbers enumerateObjectsUsingBlock:add]; + NSMutableString *forwardAppend = [NSMutableString string]; + __attribute__((__blocks__(byref))) NSMutableString *blockAppend = [NSMutableString string]; +} + +@end + diff --git a/clang/test/Rewriter/rewrite-static-block.mm b/clang/test/Rewriter/rewrite-static-block.mm new file mode 100644 index 0000000..4ee227e --- /dev/null +++ b/clang/test/Rewriter/rewrite-static-block.mm @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp -emit-llvm -o %t-rw.ll +// RUN: FileCheck --input-file=%t-rw.ll %s + +typedef void (^void_block_t)(void); + +static const void_block_t myblock = ^{ + +}; + +// CHECK: myblock = internal global diff --git a/clang/test/Rewriter/rewrite-super-message.mm b/clang/test/Rewriter/rewrite-super-message.mm new file mode 100644 index 0000000..d770b33 --- /dev/null +++ b/clang/test/Rewriter/rewrite-super-message.mm @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -DKEEP_ATTRIBUTES -D"id=struct objc_object *" -D"Class=struct objc_class *" -D"SEL=void*" -D"__declspec(X)=" -emit-llvm -o - %t-rw.cpp | FileCheck %t-rw.cpp +// radar 7738453 + +void *sel_registerName(const char *); + +@interface __NSCFType +@end + +@interface __NSCFString : __NSCFType +- (const char *)UTF8String; +@end + +@implementation __NSCFString +- (const char *)UTF8String { + return (const char *)[super UTF8String]; +} +@end + +// CHECK: call %struct.objc_class* @class_getSuperclass + +@class NSZone; + +@interface NSObject { +} + ++ (id)allocWithZone:(NSZone *)zone; +@end + + +@interface NSArray : NSObject +@end + +@implementation NSArray ++ (id)allocWithZone:(NSZone *)zone { + return [super allocWithZone:zone]; +} +@end + +@interface XNSArray +{ + Class isa; +} +@end + +@class XNSArray; + +@interface __NSArray0 : XNSArray +@end + +@implementation __NSArray0 @end diff --git a/clang/test/Rewriter/rewrite-trivial-constructor.mm b/clang/test/Rewriter/rewrite-trivial-constructor.mm new file mode 100644 index 0000000..f14f4b1 --- /dev/null +++ b/clang/test/Rewriter/rewrite-trivial-constructor.mm @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fms-extensions -rewrite-objc -fobjc-fragile-abi -x objective-c++ -fblocks -o - %s +// radar 7537770 + +typedef struct { + int a; + int b; +} s; + +extern void CFBasicHashApply(int (^block)(s)) { + int used, cnt; + for (int idx = 0; 0 < used && idx < cnt; idx++) { + s bkt; + if (0 < bkt.a) { + if (!block(bkt)) { + return; + } + used--; + } + } +} + diff --git a/clang/test/Rewriter/rewrite-try-catch.m b/clang/test/Rewriter/rewrite-try-catch.m new file mode 100644 index 0000000..b4d13b6 --- /dev/null +++ b/clang/test/Rewriter/rewrite-try-catch.m @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@interface Foo @end +@interface GARF @end + +void foo() { + @try { TRY(); } + @catch (...) { SPLATCH(); @throw; } +} + +int main() +{ + + @try { + MYTRY(); + } + + @catch (Foo* localException) { + MYCATCH(); + @throw; + } + + // no catch clause + @try { } + @finally { } +} + diff --git a/clang/test/Rewriter/rewrite-typeof.mm b/clang/test/Rewriter/rewrite-typeof.mm new file mode 100644 index 0000000..24e3bcc --- /dev/null +++ b/clang/test/Rewriter/rewrite-typeof.mm @@ -0,0 +1,39 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s + +extern "C" { +extern "C" void *_Block_copy(const void *aBlock); +extern "C" void _Block_release(const void *aBlock); +} + +int main() { + __attribute__((__blocks__(byref))) int a = 42; + int save_a = a; + + void (^b)(void) = ^{ + ((__typeof(^{ a = 2; }))_Block_copy((const void *)(^{ a = 2; }))); + }; + + ((__typeof(b))_Block_copy((const void *)(b))); + + return 0; +} + +// CHECK-LP: ((void (^)(void))_Block_copy((const void *)(b))) + +// radar 7628153 +void f() { + int a; + __typeof__(a) aVal = a; + char *a1t = (char *)@encode(__typeof__(a)); + __typeof__(aVal) bVal; + char *a2t = (char *)@encode(__typeof__(bVal)); + __typeof__(bVal) cVal = bVal; + char *a3t = (char *)@encode(__typeof__(cVal)); + +} + + +// CHECK-LP: int aVal = a; + +// CHECK-LP: int bVal; diff --git a/clang/test/Rewriter/rewrite-unique-block-api.mm b/clang/test/Rewriter/rewrite-unique-block-api.mm new file mode 100644 index 0000000..1dcc1b6 --- /dev/null +++ b/clang/test/Rewriter/rewrite-unique-block-api.mm @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp +// radar 7630551 + +void f(void (^b)(char c)); + +@interface a +- (void)processStuff; +@end + +@implementation a +- (void)processStuff { + f(^(char x) { }); +} +@end + +@interface b +- (void)processStuff; +@end + +@implementation b +- (void)processStuff { + f(^(char x) { }); +} +@end diff --git a/clang/test/Rewriter/rewrite-user-defined-accessors.mm b/clang/test/Rewriter/rewrite-user-defined-accessors.mm new file mode 100644 index 0000000..3c38e17 --- /dev/null +++ b/clang/test/Rewriter/rewrite-user-defined-accessors.mm @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -Did="void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// rdar:// 8570020 + +@interface Foo { + Foo *foo; +} + +@property (retain, nonatomic) Foo *foo; + +@end + +@implementation Foo + +- (Foo *)foo { + if (!foo) { + foo = 0; + } + return foo; +} + + +- (void) setFoo : (Foo *) arg { + foo = arg; +} + +@synthesize foo; + +@end + diff --git a/clang/test/Rewriter/rewrite-vararg.m b/clang/test/Rewriter/rewrite-vararg.m new file mode 100644 index 0000000..bd58a6a --- /dev/null +++ b/clang/test/Rewriter/rewrite-vararg.m @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp +// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp + +// rdar://9056351 +void *sel_registerName(const char *); + +@interface NSObject @end +@class NSString; + +@protocol P + -(void)ParliamentFunkadelic; +@end + +@interface Foo { + NSObject <P> *_dataSource; +} +@end + +@interface Bar { } ++(void)WhateverBar:(NSString*)format, ...; +@end + +@implementation Foo +-(void)WhateverFoo { + [Bar WhateverBar:@"ISyncSessionDriverDataSource %@ responded poorly", _dataSource]; +} +@end diff --git a/clang/test/Rewriter/rewrite-weak-attr.m b/clang/test/Rewriter/rewrite-weak-attr.m new file mode 100644 index 0000000..60c6fc8 --- /dev/null +++ b/clang/test/Rewriter/rewrite-weak-attr.m @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -fblocks -Dnil=0 -rewrite-objc -fobjc-fragile-abi -o - %s +int main() { + __weak __block id foo = nil; + __block id foo2 = nil; + id foo3 = nil; + + void (^myblock)() = ^{ + foo = nil; + foo2 = nil; + [foo3 bar]; + id foo4 = foo3; + }; +} diff --git a/clang/test/Rewriter/static-type-protocol-1.m b/clang/test/Rewriter/static-type-protocol-1.m new file mode 100644 index 0000000..bafe286 --- /dev/null +++ b/clang/test/Rewriter/static-type-protocol-1.m @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@protocol Proto +- (void) ProtoDidget; +@end + +@protocol MyProto <Proto> +- (void) widget; +@end + +@interface Foo +- (void)StillMode; +@end + +@interface Container ++ (void)MyMeth; +@end + +@implementation Container ++ (void)MyMeth +{ + Foo *view; + [(Foo <MyProto> *)view StillMode]; + [(Foo <MyProto> *)view widget]; + [(Foo <MyProto> *)view ProtoDidget]; +} +@end diff --git a/clang/test/Rewriter/undecl-objc-h.m b/clang/test/Rewriter/undecl-objc-h.m new file mode 100644 index 0000000..5c3e693 --- /dev/null +++ b/clang/test/Rewriter/undecl-objc-h.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +typedef struct S { + int * pint; + int size; +}NSRec; + +@interface SUPER +- (NSRec) MainMethod : (NSRec) Arg1 : (NSRec) Arg2; +@end + +@interface MyDerived : SUPER +{ + NSRec d; +} +- (int) instanceMethod; +- (int) another : (int) arg; +- (NSRec) MainMethod : (NSRec) Arg1 : (NSRec) Arg2; +@end + +@implementation MyDerived +- (int) instanceMethod { + return [self another : [self MainMethod : d : d].size]; +} + +- (int) another : (int) arg { return arg; } +- (NSRec) MainMethod : (NSRec) Arg1 : (NSRec) Arg2 { return Arg2; } +@end + diff --git a/clang/test/Rewriter/undeclared-method-1.m b/clang/test/Rewriter/undeclared-method-1.m new file mode 100644 index 0000000..9b4ca19 --- /dev/null +++ b/clang/test/Rewriter/undeclared-method-1.m @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@interface Derived @end + +int main(void) { + Derived *v ; + [v free]; + return 0; +} diff --git a/clang/test/Rewriter/undef-field-reference-1.m b/clang/test/Rewriter/undef-field-reference-1.m new file mode 100644 index 0000000..9c067a8 --- /dev/null +++ b/clang/test/Rewriter/undef-field-reference-1.m @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +@interface MyDerived +{ +@public + int IVAR; +} +@end + +MyDerived *pd; +int main() { + return pd->IVAR; +} + + diff --git a/clang/test/Rewriter/unnamed-bf-modern-write.mm b/clang/test/Rewriter/unnamed-bf-modern-write.mm new file mode 100644 index 0000000..892382f --- /dev/null +++ b/clang/test/Rewriter/unnamed-bf-modern-write.mm @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -E %s -o %t.mm +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s + +@interface Foo { +@private + int first; + int :1; + int third :1; + int :1; + int fifth :1; +} +@end +@implementation Foo +@end + +// CHECK: struct Foo_IMPL { +// CHECK-NEXT: int first; +// CHECK-NEXT: int : 1; +// CHECK-NEXT: int third : 1; +// CHECK-NEXT: int : 1; +// CHECK-NEXT: int fifth : 1; +// CHECK-NEXT: char : 0; +// CHECK-NEXT: }; diff --git a/clang/test/Rewriter/va-method.m b/clang/test/Rewriter/va-method.m new file mode 100644 index 0000000..c232d23 --- /dev/null +++ b/clang/test/Rewriter/va-method.m @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -rewrite-objc -fobjc-fragile-abi %s -o - + +#include <stdarg.h> + +@interface NSObject @end +@interface XX : NSObject @end + +@implementation XX +- (void)encodeValuesOfObjCTypes:(const char *)types, ... { + va_list ap; + va_start(ap, types); + while (*types) ; + va_end(ap); +} + +@end + diff --git a/clang/test/Rewriter/weak_byref_objects.m b/clang/test/Rewriter/weak_byref_objects.m new file mode 100644 index 0000000..1b9efbe --- /dev/null +++ b/clang/test/Rewriter/weak_byref_objects.m @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fblocks -triple i386-apple-darwin9 -fobjc-gc -rewrite-objc -fobjc-fragile-abi %s -o - + +#define nil 0 +int main() { + __weak __block id foo = nil; + __block id foo2 = nil; + id foo3 = nil; + + void (^myblock)() = ^{ + foo = nil; + foo2 = nil; + [foo3 bar]; + id foo4 = foo3; + }; +} |