OSDN Git Service

PR optimization/14235
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / const-str-3.m
1 /* Test the -fconstant-string-class=Foo option under the NeXT
2    runtime.  */
3 /* Developed by Markus Hitter <mah@jump-ing.de>.  */
4
5 /* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */
6 /* { dg-do run { target *-*-darwin* } } */
7
8 #include <stdio.h>
9 #include <objc/objc.h>
10 #include <objc/Object.h>
11
12 @interface Foo: Object {
13   char *cString;
14   unsigned int len;
15 }
16 - (char *)customString;
17 @end
18
19 struct objc_class _FooClassReference;
20
21 @implementation Foo : Object
22 - (char *)customString {
23   return cString;
24 }
25 @end
26
27 int main () {
28   Foo *string = @"bla";
29   Foo *string2 = @"bla";
30
31   if(string != string2)
32     abort();
33   printf("Strings are being uniqued properly\n");
34
35   /* This memcpy has to be done before the first message is sent to a
36      constant string object. Can't be moved to +initialize since _that_
37      is already a message. */
38
39   memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference));
40   if (strcmp ([string customString], "bla")) {
41     abort ();
42   }
43
44   printf([@"This is a working constant string object\n" customString]);
45   return 0;
46 }