From 01277dc46a55d9695702d0008ddcd9eb8e193fec Mon Sep 17 00:00:00 2001 From: Ziemowit Laski Date: Tue, 21 Jun 2005 21:13:46 +0000 Subject: [PATCH] const-str-[1-9].mm: New tests. [gcc/testsuite/ChangeLog] 2005-06-21 Ziemowit Laski * obj-c++.dg/const-str-[1-9].mm: New tests. From-SVN: r101237 --- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/obj-c++.dg/const-str-1.mm | 25 +++++++++++++ gcc/testsuite/obj-c++.dg/const-str-2.mm | 7 ++++ gcc/testsuite/obj-c++.dg/const-str-3.mm | 48 +++++++++++++++++++++++++ gcc/testsuite/obj-c++.dg/const-str-4.mm | 31 ++++++++++++++++ gcc/testsuite/obj-c++.dg/const-str-5.mm | 27 ++++++++++++++ gcc/testsuite/obj-c++.dg/const-str-6.mm | 27 ++++++++++++++ gcc/testsuite/obj-c++.dg/const-str-7.mm | 46 ++++++++++++++++++++++++ gcc/testsuite/obj-c++.dg/const-str-8.mm | 39 ++++++++++++++++++++ gcc/testsuite/obj-c++.dg/const-str-9.mm | 20 +++++++++++ 10 files changed, 274 insertions(+) create mode 100644 gcc/testsuite/obj-c++.dg/const-str-1.mm create mode 100644 gcc/testsuite/obj-c++.dg/const-str-2.mm create mode 100644 gcc/testsuite/obj-c++.dg/const-str-3.mm create mode 100644 gcc/testsuite/obj-c++.dg/const-str-4.mm create mode 100644 gcc/testsuite/obj-c++.dg/const-str-5.mm create mode 100644 gcc/testsuite/obj-c++.dg/const-str-6.mm create mode 100644 gcc/testsuite/obj-c++.dg/const-str-7.mm create mode 100644 gcc/testsuite/obj-c++.dg/const-str-8.mm create mode 100644 gcc/testsuite/obj-c++.dg/const-str-9.mm diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 293bb29dbba..bef45eba983 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-06-21 Ziemowit Laski + + * obj-c++.dg/const-str-[1-9].mm: New tests. + 2005-06-21 Paul Thomas PR fortran/22010 diff --git a/gcc/testsuite/obj-c++.dg/const-str-1.mm b/gcc/testsuite/obj-c++.dg/const-str-1.mm new file mode 100644 index 00000000000..e4cac2e57ec --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-1.mm @@ -0,0 +1,25 @@ +/* Test errors for constant strings. */ +/* { dg-do compile } */ +/* { dg-options "-fgnu-runtime" } */ + +#ifdef __cplusplus +extern void baz(...); +#endif + +void foo() +{ + baz(@"hiya"); /* { dg-error "annot find interface declaration" } */ +} + +@interface NXConstantString +{ + void *isa; + char *str; + int len; +} +@end + +void bar() +{ + baz(@"howdah"); +} diff --git a/gcc/testsuite/obj-c++.dg/const-str-2.mm b/gcc/testsuite/obj-c++.dg/const-str-2.mm new file mode 100644 index 00000000000..c406665c576 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-2.mm @@ -0,0 +1,7 @@ +/* Test the -fconstant-string-class flag error. */ +/* { dg-do compile } */ +/* { dg-options "-fconstant-string-class=" } */ + +{ dg-error "no class name specified|missing argument" "" { target *-*-* } 0 } + +void foo () {} diff --git a/gcc/testsuite/obj-c++.dg/const-str-3.mm b/gcc/testsuite/obj-c++.dg/const-str-3.mm new file mode 100644 index 00000000000..7d4f80863d2 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-3.mm @@ -0,0 +1,48 @@ +/* Test the -fconstant-string-class=Foo option under the NeXT + runtime. */ +/* Developed by Markus Hitter . */ + +/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */ +/* { dg-do run { target *-*-darwin* } } */ + +#include +#include +#include +#include +#include + +@interface Foo: Object { + char *cString; + unsigned int len; +} +- (char *)customString; +@end + +struct objc_class _FooClassReference; + +@implementation Foo : Object +- (char *)customString { + return cString; +} +@end + +int main () { + Foo *string = @"bla"; + Foo *string2 = @"bla"; + + if(string != string2) + abort(); + printf("Strings are being uniqued properly\n"); + + /* This memcpy has to be done before the first message is sent to a + constant string object. Can't be moved to +initialize since _that_ + is already a message. */ + + memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference)); + if (strcmp ([string customString], "bla")) { + abort (); + } + + printf([@"This is a working constant string object\n" customString]); + return 0; +} diff --git a/gcc/testsuite/obj-c++.dg/const-str-4.mm b/gcc/testsuite/obj-c++.dg/const-str-4.mm new file mode 100644 index 00000000000..df53c238a58 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-4.mm @@ -0,0 +1,31 @@ +/* Ensure that the preprocessor handles ObjC string constants gracefully. */ +/* Author: Ziemowit Laski */ +/* { dg-options "-fnext-runtime -fconstant-string-class=MyString -lobjc" } */ +/* { dg-do run { target *-*-darwin* } } */ + +extern "C" void abort(void); + +@interface MyString +{ + void *isa; + char *str; + int len; +} +@end + +#define kMyStringMacro1 "My String" +#define kMyStringMacro2 @"My String" + +void *_MyStringClassReference; + +@implementation MyString +@end + +int main(void) { + MyString* aString1 = @kMyStringMacro1; + MyString* aString2 = kMyStringMacro2; + if(aString1 != aString2) { + abort(); + } + return 0; +} diff --git a/gcc/testsuite/obj-c++.dg/const-str-5.mm b/gcc/testsuite/obj-c++.dg/const-str-5.mm new file mode 100644 index 00000000000..186edcfceb2 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-5.mm @@ -0,0 +1,27 @@ +/* Positive test case for constant string layout. */ +/* Contributed by Ziemowit Laski . */ + +/* { dg-options "-fconstant-string-class=MyConstantString" } */ +/* { dg-do compile } */ + +@interface MyBase { + const char *p; +} +@end + +@interface MyConstantString: MyBase { + union { + void *u; + unsigned char *c; + } _contents; + unsigned int _count; +} +@end + +/* The NeXT runtime initializes the 'isa' pointer of string constants at + compile time. */ +#ifdef __NEXT_RUNTIME__ +extern void *_MyConstantStringClassReference; +#endif + +MyConstantString *str = @"Hello"; diff --git a/gcc/testsuite/obj-c++.dg/const-str-6.mm b/gcc/testsuite/obj-c++.dg/const-str-6.mm new file mode 100644 index 00000000000..a7cbbf7141a --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-6.mm @@ -0,0 +1,27 @@ +/* Negative test case for constant string layout. */ +/* Contributed by Ziemowit Laski . */ + +/* { dg-options "-fconstant-string-class=MyConstantString" } */ +/* { dg-do compile } */ + +@interface MyBase { + char p; +} +@end + +@interface MyConstantString: MyBase { + union { + void *u; + unsigned char *c; + } _contents; + char _count; +} +@end + +/* The NeXT runtime initializes the 'isa' pointer of string constants at + compile time. */ +#ifdef __NEXT_RUNTIME__ +extern void *_MyConstantStringClassReference; +#endif + +MyConstantString *str = @"Hello"; /* { dg-error "interface .MyConstantString. does not have valid constant string layout" } */ diff --git a/gcc/testsuite/obj-c++.dg/const-str-7.mm b/gcc/testsuite/obj-c++.dg/const-str-7.mm new file mode 100644 index 00000000000..3691579381d --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-7.mm @@ -0,0 +1,46 @@ +/* Test to make sure that the const objc strings are the same across + scopes. */ +/* Developed by Andrew Pinski */ + + +/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */ +/* { dg-do run { target *-*-darwin* } } */ + + +#include +#include +#include +#include +#include + + +@interface Foo: Object { + char *cString; + unsigned int len; +} +- (char *)customString; +@end + +struct objc_class _FooClassReference; + + +@implementation Foo : Object +- (char *)customString { + return cString; +} +@end + + +int main () { + Foo *string = @"bla"; + { + Foo *string2 = @"bla"; + + + if(string != string2) + abort(); + printf("Strings are being uniqued properly\n"); + } + return 0; +} + diff --git a/gcc/testsuite/obj-c++.dg/const-str-8.mm b/gcc/testsuite/obj-c++.dg/const-str-8.mm new file mode 100644 index 00000000000..60abcbd52b1 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-8.mm @@ -0,0 +1,39 @@ +/* Test for assigning compile-time constant-string objects to static variables. */ +/* Contributed by Ziemowit Laski */ + +/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */ +/* { dg-do run { target *-*-darwin* } } */ + + +#include +#include + +@interface Foo: Object { + char *cString; + unsigned int len; +} +@end + +struct objc_class _FooClassReference; + +@implementation Foo : Object +- (char *)customString { + return cString; +} +@end + +static const Foo *appKey = @"MyApp"; +static int CFPreferencesSynchronize (const Foo *ref) { + return ref == appKey; +} + +static void PrefsSynchronize(void) +{ + if(!CFPreferencesSynchronize(appKey)) + abort(); +} + +int main () { + PrefsSynchronize(); + return 0; +} diff --git a/gcc/testsuite/obj-c++.dg/const-str-9.mm b/gcc/testsuite/obj-c++.dg/const-str-9.mm new file mode 100644 index 00000000000..97d49e9043c --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-9.mm @@ -0,0 +1,20 @@ +/* Test if ObjC constant strings get placed in the correct section. */ +/* Contributed by Ziemowit Laski */ + +/* { dg-options "-fnext-runtime" } */ +/* { dg-do compile { target *-*-darwin* } } */ + +#include + +@interface NSConstantString: Object { + char *cString; + unsigned int len; +} +@end + +extern struct objc_class _NSConstantStringClassReference; + +const NSConstantString *appKey = @"MyApp"; + +/* { dg-final { scan-assembler ".section __OBJC, __cstring_object" } } */ +/* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" } } */ -- 2.30.2