diff options
Diffstat (limited to 'test/FrontendObjC')
20 files changed, 485 insertions, 0 deletions
diff --git a/test/FrontendObjC/2007-04-03-ObjcEH.m b/test/FrontendObjC/2007-04-03-ObjcEH.m new file mode 100644 index 0000000..353323d --- /dev/null +++ b/test/FrontendObjC/2007-04-03-ObjcEH.m @@ -0,0 +1,29 @@ +// RUN: %llvmgcc -c %s -o /dev/null + +@interface B +-(int)bar; +@end + +@interface A +-(void) Foo:(int) state; +@end + +@implementation A +- (void) Foo:(int) state { + + int wasResponded = 0; + @try { + if (state) { + B * b = 0; + @try { } + @finally { + wasResponded = ![b bar]; + } + } + } + @finally { + } +} +@end + + diff --git a/test/FrontendObjC/2007-05-02-Strong.m b/test/FrontendObjC/2007-05-02-Strong.m new file mode 100644 index 0000000..3778fd2 --- /dev/null +++ b/test/FrontendObjC/2007-05-02-Strong.m @@ -0,0 +1,23 @@ +// RUN: %llvmgcc -c %s -fobjc-gc -o /dev/null +typedef int NSInteger; +typedef struct _NSRect { + int origin; + int size; +} NSRect; + +__attribute__((objc_gc(strong))) NSRect *_cachedRectArray; +extern const NSRect NSZeroRect; +@interface A{ +} +-(void)bar:(NSInteger *)rectCount; +@end + +@implementation A + +-(void)bar:(NSInteger *)rectCount { + NSRect appendRect = NSZeroRect; + + _cachedRectArray[*rectCount - 1] = NSZeroRect; +} + +@end diff --git a/test/FrontendObjC/2007-09-25-EH.m b/test/FrontendObjC/2007-09-25-EH.m new file mode 100644 index 0000000..5fa9cbb --- /dev/null +++ b/test/FrontendObjC/2007-09-25-EH.m @@ -0,0 +1,27 @@ +// RUN: %llvmgcc -c -w -m64 -mmacosx-version-min=10.5 %s -o /dev/null +// XFAIL: * +// XTARGET: darwin +@class NSDictionary, DSoBuffer, DSoDirectory, NSMutableArray; +@interface NSException {} +@end +@interface DSoNode { + DSoDirectory *mDirectory; +} +@end +@implementation DSoNode +- (void) _findRecordsOfTypes { + DSoBuffer *dbData; + void *recInfo; + NSMutableArray *results; + @try { + dsGetRecordEntry([dbData dsDataBuffer], (void**)&recInfo); + @try { + [results addObject:37]; + } @finally { + dsDeallocRecordEntry([mDirectory dsDirRef], recInfo); + } + } @catch(NSException * exception) { + } +} + + diff --git a/test/FrontendObjC/2007-10-17-SJLJExceptions.m b/test/FrontendObjC/2007-10-17-SJLJExceptions.m new file mode 100644 index 0000000..970207e --- /dev/null +++ b/test/FrontendObjC/2007-10-17-SJLJExceptions.m @@ -0,0 +1,24 @@ +// RUN: %llvmgcc -m32 -x objective-c %s -pipe -std=gnu99 -O2 -fexceptions -S -o - | not grep Unwind_Resume +#import <stdio.h> + +@interface Foo { + char c; + short s; + int i; + long l; + float f; + double d; +} +-(Foo*)retain; +@end + +struct Foo *bork(Foo *FooArray) { + struct Foo *result = 0; + @try { + result = [FooArray retain]; + } @catch(id any) { + printf("hello world\n"); + } + + return result; +} diff --git a/test/FrontendObjC/2007-10-18-ProDescriptor.m b/test/FrontendObjC/2007-10-18-ProDescriptor.m new file mode 100644 index 0000000..e87a43f --- /dev/null +++ b/test/FrontendObjC/2007-10-18-ProDescriptor.m @@ -0,0 +1,19 @@ +// RUN: %llvmgcc -x objective-c -c %s -o /dev/null +@protocol O +@end +@interface O < O > { +} +@end +struct A { +}; +@protocol AB +- (unsigned) ver; +@end +@interface AGy:O < AB > { +} +@end +@implementation AGy +- (unsigned) ver { +} +@end + diff --git a/test/FrontendObjC/2007-10-23-GC-WriteBarrier.m b/test/FrontendObjC/2007-10-23-GC-WriteBarrier.m new file mode 100644 index 0000000..866c330 --- /dev/null +++ b/test/FrontendObjC/2007-10-23-GC-WriteBarrier.m @@ -0,0 +1,9 @@ +// RUN: %llvmgcc -x objective-c -c %s -o /dev/null -fobjc-gc +// rdar://5541393 + +typedef unsigned int NSUInteger; +__attribute__((objc_gc(strong))) float *_scores; + +void foo(int i, float f) { + _scores[i] = f; +} diff --git a/test/FrontendObjC/2008-10-3-EhValue.m b/test/FrontendObjC/2008-10-3-EhValue.m new file mode 100644 index 0000000..a4c0cae --- /dev/null +++ b/test/FrontendObjC/2008-10-3-EhValue.m @@ -0,0 +1,50 @@ +// RUN: %llvmgcc -w -x objective-c -c %s -o /dev/null + +@interface Object { +@public + Class isa; +} ++initialize; ++alloc; ++new; ++free; +-free; ++(Class)class; +-(Class)class; +-init; +-superclass; +-(const char *)name; +@end + +@interface Frob: Object +@end + +@implementation Frob: Object +@end + +static Frob* _connection = ((void *)0); + +extern void abort(void); + +void test (Object* sendPort) +{ + int cleanupPorts = 1; + Frob* receivePort = ((void *)0); + + @try { + receivePort = (Frob *) -1; + _connection = (Frob *) -1; + receivePort = ((void *)0); + sendPort = ((void *)0); + cleanupPorts = 0; + @throw [Object new]; + } + @catch(Frob *obj) { + if(!(0)) abort(); + } + @catch(id exc) { + if(!(!receivePort)) abort(); + if(!(!sendPort)) abort(); + if(!(!cleanupPorts)) abort(); + } +} diff --git a/test/FrontendObjC/2008-11-12-Metadata.m b/test/FrontendObjC/2008-11-12-Metadata.m new file mode 100644 index 0000000..7e9f028 --- /dev/null +++ b/test/FrontendObjC/2008-11-12-Metadata.m @@ -0,0 +1,14 @@ +// RUN: %llvmgcc -x objective-c -m64 -c %s -o /dev/null + +@interface A +@end +@protocol P +@end +@interface B : A <P> +{ +} +@end +@implementation B +- (void)test { +} +@end diff --git a/test/FrontendObjC/2008-11-24-ConstCFStrings.m b/test/FrontendObjC/2008-11-24-ConstCFStrings.m new file mode 100644 index 0000000..976adc4 --- /dev/null +++ b/test/FrontendObjC/2008-11-24-ConstCFStrings.m @@ -0,0 +1,11 @@ +// RUN: %llvmgcc -x objective-c -m64 -S %s -o - | grep {L_unnamed_cfstring_} + +@class NSString; + +@interface A +- (void)bork:(NSString*)msg; +@end + +void func(A *a) { + [a bork:@"Hello world!"]; +} diff --git a/test/FrontendObjC/2008-11-25-Blocks.m b/test/FrontendObjC/2008-11-25-Blocks.m new file mode 100644 index 0000000..258d70a --- /dev/null +++ b/test/FrontendObjC/2008-11-25-Blocks.m @@ -0,0 +1,17 @@ +// RUN: %llvmgcc -c %s -o /dev/null +// rdar://6394879 + +@interface bork +- (id)B:(void (^)())blk; +- (void)C; +@end +@implementation bork +- (id)B:(void (^)())blk { + __attribute__((__blocks__(byref))) bork* new = ((void *)0); + blk(); +} +- (void)C { + __attribute__((__blocks__(byref))) id var; + [self B:^() {}]; +} +@end diff --git a/test/FrontendObjC/2009-01-26-WriteBarrier-2.m b/test/FrontendObjC/2009-01-26-WriteBarrier-2.m new file mode 100644 index 0000000..32833a8 --- /dev/null +++ b/test/FrontendObjC/2009-01-26-WriteBarrier-2.m @@ -0,0 +1,14 @@ +// RUN: %llvmgcc -x objective-c -S %s -fobjc-gc -o - | grep objc_assign_strongCast +// rdar://5541393 + +typedef struct { + void (^ivarBlock)(void); +} StructWithBlock_t; + +int main(char *argc, char *argv[]) { + StructWithBlock_t *swbp = (StructWithBlock_t *)malloc(sizeof(StructWithBlock_t*)); + __block int i = 10; + // assigning a Block into an struct slot should elicit a write-barrier under GC + swbp->ivarBlock = ^ { ++i; }; + return 0; +} diff --git a/test/FrontendObjC/2009-02-05-VolatileProp.m b/test/FrontendObjC/2009-02-05-VolatileProp.m new file mode 100644 index 0000000..461f92b --- /dev/null +++ b/test/FrontendObjC/2009-02-05-VolatileProp.m @@ -0,0 +1,11 @@ +/* RUN: %llvmgcc -w -x objective-c -c %s -o /dev/null -pedantic-errors + rdar://6551276 */ + +void foo(const unsigned short *); +void bar() { + unsigned short *s[3]; + int i; + @try { } @catch (id anException) { } + foo(2+s[i]); +} + diff --git a/test/FrontendObjC/2009-04-14-AsmSection.m b/test/FrontendObjC/2009-04-14-AsmSection.m new file mode 100644 index 0000000..de2cef0 --- /dev/null +++ b/test/FrontendObjC/2009-04-14-AsmSection.m @@ -0,0 +1,9 @@ +// RUN: %llvmgcc -S %s -fobjc-abi-version=2 -emit-llvm -o %t +// RUN: grep {OBJC_CLASS_\\\$_A.*section.*__DATA, __objc_data.*align} %t +// XTARGET: darwin + +@interface A +@end + +@implementation A +@end diff --git a/test/FrontendObjC/2009-04-27-bitfield-vs-ivar.m b/test/FrontendObjC/2009-04-27-bitfield-vs-ivar.m new file mode 100644 index 0000000..cada843 --- /dev/null +++ b/test/FrontendObjC/2009-04-27-bitfield-vs-ivar.m @@ -0,0 +1,44 @@ +// RUN: %llvmgcc -S -x objective-c -m64 -fobjc-abi-version=2 %s -o %t +// RUN: grep {OBJC_CLASS_RO_\\\$_I4} %t | grep {i32 0, i32 1, i32 2, i32 0} +// RUN: grep {OBJC_CLASS_RO_\\\$_I2} %t | grep {i32 0, i32 1, i32 1, i32 0} +// RUN: grep {OBJC_CLASS_RO_\\\$_I5} %t | grep {i32 0, i32 0, i32 0, i32 0} +// XTARGET: darwin + +// Test instance variable sizing when base class ends in bitfield +@interface I3 { + unsigned int _iv2 :1; +} +@end + +@interface I4 : I3 { + char _iv4; +} +@end + +// Test case with no instance variables in derived class +@interface I1 { + unsigned int _iv2 :1; +} +@end + +@interface I2 : I1 { +} +@end + +// Test case with no instance variables anywhere +@interface I6 { +} +@end + +@interface I5 : I6 { +} +@end + +@implementation I4 +@end + +@implementation I2 +@end + +@implementation I5 +@end diff --git a/test/FrontendObjC/2009-04-28-bitfield-vs-vbc.m b/test/FrontendObjC/2009-04-28-bitfield-vs-vbc.m new file mode 100644 index 0000000..8306fcc --- /dev/null +++ b/test/FrontendObjC/2009-04-28-bitfield-vs-vbc.m @@ -0,0 +1,127 @@ +// RUN: %llvmgcc -S -x objective-c -m32 %s -o %t +// This used to crash, 6831493. +#include <stdlib.h> + +struct s0 { + double x; +}; + +@interface I2 { + struct s0 _iv1; +} +@end + +@interface I3 : I2 { + unsigned int _iv2 :1; + unsigned : 0; + unsigned int _iv3 : 3; +} +@end + +@interface I4 : I3 { + char _iv4; +} +@end + +@interface I5 : I4 { + char _iv5; + int _iv6; + int _iv7; +} + +@property int P1; +@end + +@implementation I2 +@end + +@implementation I3 +@end + +@implementation I4 +@end + +@interface I5 () +@property int P2; +@end + +#if 0 +int g2 = sizeof(I2); +int g3 = sizeof(I3); +int g4 = sizeof(I4); +int g5_0 = sizeof(I5); +#endif + +@implementation I5 +#ifdef __x86_64 +@synthesize P1 = _MadeUpName; +@synthesize P2 = _AnotherMadeUpName; +#else +@synthesize P1 = _iv6; +@synthesize P2 = _iv7; +#endif +@end + +#if 0 +int g5_1 = sizeof(I5); +#endif + +@interface T0_I0 { + double iv_A_0; + char iv_A_1; +} +@end + +@interface T0_I1 : T0_I0 { + char iv_B_0; +} +@end + +@interface T0_I2 : T0_I1 { + char iv_C_0; +} +@end + +#if 0 +int g6 = sizeof(T0_I0); +int g7 = sizeof(T0_I1); +int g8 = sizeof(T0_I2); +#endif + +@implementation T0_I0 @end +@implementation T0_I1 @end +@implementation T0_I2 @end + +void f0(I2*i2,I3*i3,I4*i4,I5*i5,T0_I0*t0_i0,T0_I1*t0_i1,T0_I2*t0_i2) { +} + +// Thomas Wang's ui32 hash. +unsigned hash_ui32_to_ui32(unsigned a) { + a = (a ^ 61) ^ (a >> 16); + a = a + (a << 3); + a = a ^ (a >> 4); + a = a * 0x27d4eb2d; + a = a ^ (a >> 15); + return a; +} + +unsigned char hash_ui32_to_ui8(unsigned ui) { + ui = hash_ui32_to_ui32(ui); + ui ^= ui>>8; + ui ^= ui>>8; + ui ^= ui>>8; + return (unsigned char) ui; +} + +void *init() { + unsigned i, N = 1024; + unsigned char *p = malloc(N); + for (i=0; i != N; ++i) + p[i] = hash_ui32_to_ui8(i); + return p; +} + +int main(){ + void *p = init(); + f0(p,p,p,p,p,p,p); +} diff --git a/test/FrontendObjC/2009-08-05-utf16.m b/test/FrontendObjC/2009-08-05-utf16.m new file mode 100644 index 0000000..2964ecf --- /dev/null +++ b/test/FrontendObjC/2009-08-05-utf16.m @@ -0,0 +1,5 @@ +/* RUN: %llvmgcc -w -x objective-c -S %s -o - | grep {__utf16_string_1} | grep {internal constant} | grep {12 x i8} + rdar://7095855 rdar://7115749 */ + +void *P = @"iPod™"; + diff --git a/test/FrontendObjC/2009-08-17-DebugInfo.m b/test/FrontendObjC/2009-08-17-DebugInfo.m new file mode 100644 index 0000000..2c72e95 --- /dev/null +++ b/test/FrontendObjC/2009-08-17-DebugInfo.m @@ -0,0 +1,28 @@ +// This is a regression test on debug info to make sure that we can set a +// breakpoint on a objective message. +// RUN: %llvmgcc -S -O0 -g %s -o - | llc -o %t.s -O0 +// RUN: %compile_c %t.s -o %t.o +// RUN: %link %t.o -o %t.exe -framework Foundation +// RUN: echo {break randomFunc\n} > %t.in +// RUN: gdb -q -batch -n -x %t.in %t.exe | tee %t.out | \ +// RUN: grep {Breakpoint 1 at 0x.*: file 2009-08-17-DebugInfo.m, line 21} +// XTARGET: darwin +@interface MyClass +{ + int my; +} ++ init; +- randomFunc; +@end + +@implementation MyClass ++ init { +} +- randomFunc { my = 42; } +@end + +int main() { + id o = [MyClass init]; + [o randomFunc]; + return 0; +} diff --git a/test/FrontendObjC/2009-11-30-Objc-ID.m b/test/FrontendObjC/2009-11-30-Objc-ID.m new file mode 100644 index 0000000..787bf72 --- /dev/null +++ b/test/FrontendObjC/2009-11-30-Objc-ID.m @@ -0,0 +1,14 @@ +// RUN: %llvmgcc -S -O0 -g %s -o - | \ +// RUN: llc --disable-fp-elim -o %t.s -O0 +// RUN: grep id %t.s | grep DW_AT_name +@interface A +-(id) blah; +@end + +@implementation A +-(id)blah { + int i = 1; + i++; + return i; +} +@end diff --git a/test/FrontendObjC/2010-02-01-utf16-with-null.m b/test/FrontendObjC/2010-02-01-utf16-with-null.m new file mode 100644 index 0000000..86e4637 --- /dev/null +++ b/test/FrontendObjC/2010-02-01-utf16-with-null.m @@ -0,0 +1,5 @@ +/* RUN: %llvmgcc -w -x objective-c -S %s -o - | not grep {__ustring} + rdar://7589850 */ + +void *P = @"good\0bye"; + diff --git a/test/FrontendObjC/dg.exp b/test/FrontendObjC/dg.exp new file mode 100644 index 0000000..18f73a7 --- /dev/null +++ b/test/FrontendObjC/dg.exp @@ -0,0 +1,5 @@ +load_lib llvm.exp + +if [ llvm_gcc_supports objc ] then { + RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{m}]] +} |