+2005-06-21 Ziemowit Laski <zlaski@apple.com>
+
+ * obj-c++.dg/const-str-[1-9].mm: New tests.
+
2005-06-21 Paul Thomas <pault@gcc.gnu.org>
PR fortran/22010
--- /dev/null
+/* 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");
+}
--- /dev/null
+/* 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 () {}
--- /dev/null
+/* Test the -fconstant-string-class=Foo option under the NeXT
+ runtime. */
+/* Developed by Markus Hitter <mah@jump-ing.de>. */
+
+/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */
+/* { dg-do run { target *-*-darwin* } } */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+#include <objc/objc.h>
+#include <objc/Object.h>
+
+@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;
+}
--- /dev/null
+/* Ensure that the preprocessor handles ObjC string constants gracefully. */
+/* Author: Ziemowit Laski <zlaski@apple.com> */
+/* { 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;
+}
--- /dev/null
+/* Positive test case for constant string layout. */
+/* Contributed by Ziemowit Laski <zlaski@apple.com>. */
+
+/* { 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";
--- /dev/null
+/* Negative test case for constant string layout. */
+/* Contributed by Ziemowit Laski <zlaski@apple.com>. */
+
+/* { 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" } */
--- /dev/null
+/* Test to make sure that the const objc strings are the same across
+ scopes. */
+/* Developed by Andrew Pinski <pinskia@physics.uc.edu> */
+
+
+/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */
+/* { dg-do run { target *-*-darwin* } } */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+#include <objc/objc.h>
+#include <objc/Object.h>
+
+
+@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;
+}
+
--- /dev/null
+/* Test for assigning compile-time constant-string objects to static variables. */
+/* Contributed by Ziemowit Laski <zlaski@apple.com> */
+
+/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */
+/* { dg-do run { target *-*-darwin* } } */
+
+
+#include <stdlib.h>
+#include <objc/Object.h>
+
+@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;
+}
--- /dev/null
+/* Test if ObjC constant strings get placed in the correct section. */
+/* Contributed by Ziemowit Laski <zlaski@apple.com> */
+
+/* { dg-options "-fnext-runtime" } */
+/* { dg-do compile { target *-*-darwin* } } */
+
+#include <objc/Object.h>
+
+@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" } } */