Debian Codegraph @

gcc/testsuite/objc.dg/torture/strings/const-str-3.m

raw
1 /* Test the -fconstant-string-class=Foo option under the NeXT runtime. */
2 /* Developed by Markus Hitter <[email protected]>. */
3 /* { dg-do run } */
4 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 /* { dg-options "-fconstant-string-class=Foo" } */
6 /* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */
7
8 #include "../../../objc-obj-c++-shared/objc-test-suite-types.h"
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 @interface Foo {
15 void *dummy_class_ref;
16 char *cString;
17 unsigned int len;
18 }
19 + initialize;
20 - (char *)customString;
21 @end
22
23 TNS_STRING_REF_T _FooClassReference; /* Only used by NeXT. */
24
25 @implementation Foo
26 + initialize {return self;}
27
28 - (char *)customString {
29 return cString;
30 }
31 @end
32
33 int main () {
34 Foo *string = @"bla";
35 Foo *string2 = @"bla";
36
37 if(string != string2)
38 abort();
39 printf("Strings are being uniqued properly\n");
40
41 #ifdef __NEXT_RUNTIME__
42 /* This memcpy has to be done before the first message is sent to a
43 constant string object. Can't be moved to +initialize since _that_
44 is already a message. */
45
46 memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference));
47 #endif
48 if (strcmp ([string customString], "bla")) {
49 abort ();
50 }
51
52 printf([@"This is a working constant string object\n" customString]);
53 return 0;
54 }