summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriains <iains@138bc75d-0d04-0410-961f-82ee72b054a4>2010-10-22 10:30:29 +0000
committeriains <iains@138bc75d-0d04-0410-961f-82ee72b054a4>2010-10-22 10:30:29 +0000
commit0c93aabd51a8b406ec3d7a77ab5df54961c565e8 (patch)
tree916b049eac8cff20aa58e64aa7d6469d396a6c68
parentd4238e8bcce578381de9480d78a651830a8f9754 (diff)
downloadgcc-0c93aabd51a8b406ec3d7a77ab5df54961c565e8.tar.gz
CFStrings for Darwin
gcc/testsuite: Based on the CFString implementation in FSF apple/trunk branch. * lib/objc-dg.exp (objc-dg-runtest): Merge flags and additional flags so that the latter can be used in dg-skip and dg-xfail clauses. * lib/obj-c++-dg.exp (obj-c++-dg-runtest): Likewise. * obj-c++.dg/template-4.mm: Don't use CFStrings on Darwin. Update test to use dg-additional-files for Object1. * obj-c++.dg/const-str-7.mm: Don't use CFStrings on Darwin. Update test to use dg-additional-files for Object1, move to torture/strings/. * obj-c++.dg/const-str-4.mm: Likewise. * obj-c++.dg/const-str-3.mm: Likewise. * obj-c++.dg/const-str-8.mm: Likewise. * obj-c++.dg/const-str-9.mm: Likewise. * obj-c++.dg/const-str-10.mm: Likewise. * obj-c++.dg/const-str-10.mm: Likewise. * obj-c++.dg/const-str-1.mm: Don't use CFStrings on Darwin. Update test to use dg-additional-files for Object1, move to strings/. * obj-c++.dg/const-str-2.mm: Likewise. * obj-c++.dg/const-str-5.mm: Likewise. * obj-c++.dg/const-str-6.mm: Likewise. * obj-c++.dg/const-str-12.mm: Likewise. * obj-c++.dg/strings/strings.exp: New. * obj-c++.dg/strings/const-cfstring-2.mm: New. * obj-c++.dg/strings/const-cfstring-5.mm: New. * obj-c++.dg/torture/strings/strings.exp: New. * obj-c++.dg/torture/strings/string1.mm: New. * obj-c++.dg/torture/strings/const-cfstring-1.mm: New. * obj-c++.dg/torture/strings/const-cfstring-3.mm: New. * obj-c++.dg/torture/strings/const-cfstring-4.mm: New. * objc/execute/string1.m: Don't use CFStrings on Darwin. Update test to use dg-additional-files for Object1, move to objc.dg/torture/strings/. * objc/execute/string2.m: Likewise. * objc/execute/string3.m: Likewise. * objc/execute/string3.m: Likewise. * objc.dg/foreach-2.m: Don't use CFStrings on Darwin. * objc.dg/foreach-4.m: Likewise. * objc.dg/foreach-5.m: Likewise. * objc.dg/const-str-3.m: Don't use CFStrings on Darwin. Update test to use dg-additional-files for Object1, move to objc.dg/torture/strings/. * objc.dg/const-str-4.m: Likewise. * objc.dg/const-str-7.m: Likewise. * objc.dg/const-str-8.m: Likewise. * objc.dg/const-str-9.m: Likewise. * objc.dg/const-str-10.m: Likewise. * objc.dg/const-str-11.m: Likewise. * objc.dg/const-str-1.m: Don't use CFStrings on Darwin. Update test to use dg-additional-files for Object1, move to objc.dg/strings/. * objc.dg/const-str-2.m: Likewise. * objc.dg/const-str-5.m: Likewise. * objc.dg/const-str-6.m: Likewise. * objc.dg/const-str-12.m: Likewise. * objc.dg/const-str-12b.m: Likewise. * objc.dg/strings/strings.exp: New. * objc.dg/strings/const-cfstring-2.m: New. * objc.dg/strings/const-cfstring-5.m: New. * objc.dg/torture/strings/strings.exp: New. * objc.dg/torture/strings/const-cfstring-1.m: New. * objc.dg/torture/strings/const-cfstring-3.m: New. * objc.dg/torture/strings/const-cfstring-4.m: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@165821 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/testsuite/ChangeLog63
-rw-r--r--gcc/testsuite/lib/obj-c++-dg.exp43
-rw-r--r--gcc/testsuite/lib/objc-dg.exp41
-rw-r--r--gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm27
-rw-r--r--gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm26
-rw-r--r--gcc/testsuite/obj-c++.dg/strings/const-str-1.mm (renamed from gcc/testsuite/obj-c++.dg/const-str-1.mm)1
-rw-r--r--gcc/testsuite/obj-c++.dg/strings/const-str-12.mm (renamed from gcc/testsuite/obj-c++.dg/const-str-12.mm)8
-rw-r--r--gcc/testsuite/obj-c++.dg/strings/const-str-2.mm (renamed from gcc/testsuite/obj-c++.dg/const-str-2.mm)1
-rw-r--r--gcc/testsuite/obj-c++.dg/strings/const-str-5.mm (renamed from gcc/testsuite/obj-c++.dg/const-str-5.mm)3
-rw-r--r--gcc/testsuite/obj-c++.dg/strings/const-str-6.mm (renamed from gcc/testsuite/obj-c++.dg/const-str-6.mm)3
-rw-r--r--gcc/testsuite/obj-c++.dg/strings/strings.exp45
-rw-r--r--gcc/testsuite/obj-c++.dg/template-4.mm4
-rw-r--r--gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-1.mm59
-rw-r--r--gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-3.mm27
-rw-r--r--gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-4.mm21
-rw-r--r--gcc/testsuite/obj-c++.dg/torture/strings/const-str-10.mm (renamed from gcc/testsuite/obj-c++.dg/const-str-10.mm)3
-rw-r--r--gcc/testsuite/obj-c++.dg/torture/strings/const-str-11.mm (renamed from gcc/testsuite/obj-c++.dg/const-str-11.mm)9
-rw-r--r--gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm (renamed from gcc/testsuite/obj-c++.dg/const-str-3.mm)10
-rw-r--r--gcc/testsuite/obj-c++.dg/torture/strings/const-str-4.mm (renamed from gcc/testsuite/obj-c++.dg/const-str-4.mm)4
-rw-r--r--gcc/testsuite/obj-c++.dg/torture/strings/const-str-7.mm (renamed from gcc/testsuite/obj-c++.dg/const-str-7.mm)11
-rw-r--r--gcc/testsuite/obj-c++.dg/torture/strings/const-str-8.mm (renamed from gcc/testsuite/obj-c++.dg/const-str-8.mm)8
-rw-r--r--gcc/testsuite/obj-c++.dg/torture/strings/const-str-9.mm (renamed from gcc/testsuite/obj-c++.dg/const-str-9.mm)3
-rw-r--r--gcc/testsuite/obj-c++.dg/torture/strings/string1.mm23
-rw-r--r--gcc/testsuite/obj-c++.dg/torture/strings/strings.exp34
-rw-r--r--gcc/testsuite/objc.dg/foreach-2.m5
-rw-r--r--gcc/testsuite/objc.dg/foreach-4.m1
-rw-r--r--gcc/testsuite/objc.dg/foreach-5.m1
-rw-r--r--gcc/testsuite/objc.dg/strings/const-cfstring-2.m27
-rw-r--r--gcc/testsuite/objc.dg/strings/const-cfstring-5.m26
-rw-r--r--gcc/testsuite/objc.dg/strings/const-str-1.m (renamed from gcc/testsuite/objc.dg/const-str-1.m)1
-rw-r--r--gcc/testsuite/objc.dg/strings/const-str-12.m (renamed from gcc/testsuite/objc.dg/const-str-12.m)0
-rw-r--r--gcc/testsuite/objc.dg/strings/const-str-12b.m (renamed from gcc/testsuite/objc.dg/const-str-12b.m)7
-rw-r--r--gcc/testsuite/objc.dg/strings/const-str-2.m (renamed from gcc/testsuite/objc.dg/const-str-2.m)3
-rw-r--r--gcc/testsuite/objc.dg/strings/const-str-5.m (renamed from gcc/testsuite/objc.dg/const-str-5.m)3
-rw-r--r--gcc/testsuite/objc.dg/strings/const-str-6.m (renamed from gcc/testsuite/objc.dg/const-str-6.m)3
-rw-r--r--gcc/testsuite/objc.dg/strings/strings.exp46
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/const-cfstring-1.m59
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/const-cfstring-3.m27
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/const-cfstring-4.m21
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/const-str-10.m (renamed from gcc/testsuite/objc.dg/const-str-10.m)3
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/const-str-11.m (renamed from gcc/testsuite/objc.dg/const-str-11.m)3
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/const-str-3.m (renamed from gcc/testsuite/objc.dg/const-str-3.m)10
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/const-str-4.m (renamed from gcc/testsuite/objc.dg/const-str-4.m)3
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/const-str-7.m (renamed from gcc/testsuite/objc.dg/const-str-7.m)14
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/const-str-8.m (renamed from gcc/testsuite/objc.dg/const-str-8.m)14
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/const-str-9.m (renamed from gcc/testsuite/objc.dg/const-str-9.m)3
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/string1.m23
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/string2.m24
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/string3.m24
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/string4.m22
-rw-r--r--gcc/testsuite/objc.dg/torture/strings/strings.exp34
-rw-r--r--gcc/testsuite/objc/execute/string1.m16
-rw-r--r--gcc/testsuite/objc/execute/string2.m17
-rw-r--r--gcc/testsuite/objc/execute/string3.m18
-rw-r--r--gcc/testsuite/objc/execute/string4.m16
55 files changed, 822 insertions, 129 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 99b0b755c99..b279dc3a002 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,66 @@
+2010-10-21 Iain Sandoe <iains@gcc.gnu.org>
+
+ Based on the CFString implementation in FSF apple/trunk branch.
+
+ * lib/objc-dg.exp (objc-dg-runtest): Merge flags and additional flags
+ so that the latter can be used in dg-skip and dg-xfail clauses.
+ * lib/obj-c++-dg.exp (obj-c++-dg-runtest): Likewise.
+ * obj-c++.dg/template-4.mm: Don't use CFStrings on Darwin. Update test
+ to use dg-additional-files for Object1.
+ * obj-c++.dg/const-str-7.mm: Don't use CFStrings on Darwin. Update test
+ to use dg-additional-files for Object1, move to torture/strings/.
+ * obj-c++.dg/const-str-4.mm: Likewise.
+ * obj-c++.dg/const-str-3.mm: Likewise.
+ * obj-c++.dg/const-str-8.mm: Likewise.
+ * obj-c++.dg/const-str-9.mm: Likewise.
+ * obj-c++.dg/const-str-10.mm: Likewise.
+ * obj-c++.dg/const-str-10.mm: Likewise.
+ * obj-c++.dg/const-str-1.mm: Don't use CFStrings on Darwin. Update test
+ to use dg-additional-files for Object1, move to strings/.
+ * obj-c++.dg/const-str-2.mm: Likewise.
+ * obj-c++.dg/const-str-5.mm: Likewise.
+ * obj-c++.dg/const-str-6.mm: Likewise.
+ * obj-c++.dg/const-str-12.mm: Likewise.
+ * obj-c++.dg/strings/strings.exp: New.
+ * obj-c++.dg/strings/const-cfstring-2.mm: New.
+ * obj-c++.dg/strings/const-cfstring-5.mm: New.
+ * obj-c++.dg/torture/strings/strings.exp: New.
+ * obj-c++.dg/torture/strings/string1.mm: New.
+ * obj-c++.dg/torture/strings/const-cfstring-1.mm: New.
+ * obj-c++.dg/torture/strings/const-cfstring-3.mm: New.
+ * obj-c++.dg/torture/strings/const-cfstring-4.mm: New.
+
+ * objc/execute/string1.m: Don't use CFStrings on Darwin. Update test
+ to use dg-additional-files for Object1, move to objc.dg/torture/strings/.
+ * objc/execute/string2.m: Likewise.
+ * objc/execute/string3.m: Likewise.
+ * objc/execute/string3.m: Likewise.
+ * objc.dg/foreach-2.m: Don't use CFStrings on Darwin.
+ * objc.dg/foreach-4.m: Likewise.
+ * objc.dg/foreach-5.m: Likewise.
+ * objc.dg/const-str-3.m: Don't use CFStrings on Darwin. Update test
+ to use dg-additional-files for Object1, move to objc.dg/torture/strings/.
+ * objc.dg/const-str-4.m: Likewise.
+ * objc.dg/const-str-7.m: Likewise.
+ * objc.dg/const-str-8.m: Likewise.
+ * objc.dg/const-str-9.m: Likewise.
+ * objc.dg/const-str-10.m: Likewise.
+ * objc.dg/const-str-11.m: Likewise.
+ * objc.dg/const-str-1.m: Don't use CFStrings on Darwin. Update test
+ to use dg-additional-files for Object1, move to objc.dg/strings/.
+ * objc.dg/const-str-2.m: Likewise.
+ * objc.dg/const-str-5.m: Likewise.
+ * objc.dg/const-str-6.m: Likewise.
+ * objc.dg/const-str-12.m: Likewise.
+ * objc.dg/const-str-12b.m: Likewise.
+ * objc.dg/strings/strings.exp: New.
+ * objc.dg/strings/const-cfstring-2.m: New.
+ * objc.dg/strings/const-cfstring-5.m: New.
+ * objc.dg/torture/strings/strings.exp: New.
+ * objc.dg/torture/strings/const-cfstring-1.m: New.
+ * objc.dg/torture/strings/const-cfstring-3.m: New.
+ * objc.dg/torture/strings/const-cfstring-4.m: New.
+
2010-10-22 Marcus Shawcroft <marcus.shawcroft@arm.com>
* gcc.target/arm/synchronize.c: Permit dmb or mcr in assembler scan.
diff --git a/gcc/testsuite/lib/obj-c++-dg.exp b/gcc/testsuite/lib/obj-c++-dg.exp
index dbdeaa2006e..13263aeff47 100644
--- a/gcc/testsuite/lib/obj-c++-dg.exp
+++ b/gcc/testsuite/lib/obj-c++-dg.exp
@@ -30,5 +30,44 @@ proc obj-c++-dg-prune { system text } {
# Modified dg-runtest that can cycle through a list of optimization options
# as c-torture does.
proc obj-c++-dg-runtest { testcases default-extra-flags } {
- return [gcc-dg-runtest $testcases ${default-extra-flags}]
-}
+ global runtests
+
+ # Some callers set torture options themselves; don't override those.
+ set existing_torture_options [torture-options-exist]
+ if { $existing_torture_options == 0 } {
+ global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
+ torture-init
+ set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
+ }
+ dump-torture-options
+
+ foreach test $testcases {
+ global torture_with_loops torture_without_loops
+ # If we're only testing specific files and this isn't one of
+ # them, skip it.
+ if ![runtest_file_p $runtests $test] {
+ continue
+ }
+
+ # Look for a loop within the source code - if we don't find one,
+ # don't pass -funroll[-all]-loops.
+ if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
+ set option_list $torture_with_loops
+ } else {
+ set option_list $torture_without_loops
+ }
+
+ set nshort [file tail [file dirname $test]]/[file tail $test]
+
+ foreach flags $option_list {
+ # combine flags so that dg-skip & xfail will see the extras.
+ set combined_flags "$flags ${default-extra-flags}"
+ verbose "Testing $nshort, $combined_flags" 1
+ dg-test $test $combined_flags ""
+ }
+ }
+
+ if { $existing_torture_options == 0 } {
+ torture-finish
+ }
+} \ No newline at end of file
diff --git a/gcc/testsuite/lib/objc-dg.exp b/gcc/testsuite/lib/objc-dg.exp
index 066b47bea34..54e8b2d6ff3 100644
--- a/gcc/testsuite/lib/objc-dg.exp
+++ b/gcc/testsuite/lib/objc-dg.exp
@@ -31,5 +31,44 @@ proc objc-dg-prune { system text } {
# Modified dg-runtest that can cycle through a list of optimization options
# as c-torture does.
proc objc-dg-runtest { testcases default-extra-flags } {
- return [gcc-dg-runtest $testcases ${default-extra-flags}]
+ global runtests
+
+ # Some callers set torture options themselves; don't override those.
+ set existing_torture_options [torture-options-exist]
+ if { $existing_torture_options == 0 } {
+ global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
+ torture-init
+ set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
+ }
+ dump-torture-options
+
+ foreach test $testcases {
+ global torture_with_loops torture_without_loops
+ # If we're only testing specific files and this isn't one of
+ # them, skip it.
+ if ![runtest_file_p $runtests $test] {
+ continue
+ }
+
+ # Look for a loop within the source code - if we don't find one,
+ # don't pass -funroll[-all]-loops.
+ if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
+ set option_list $torture_with_loops
+ } else {
+ set option_list $torture_without_loops
+ }
+
+ set nshort [file tail [file dirname $test]]/[file tail $test]
+
+ foreach flags $option_list {
+ # combine flags so that dg-skip & xfail will see the extras.
+ set combined_flags "$flags ${default-extra-flags}"
+ verbose "Testing $nshort, $combined_flags" 1
+ dg-test $test $combined_flags ""
+ }
+ }
+
+ if { $existing_torture_options == 0 } {
+ torture-finish
+ }
}
diff --git a/gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm b/gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm
new file mode 100644
index 00000000000..14ae68c6c50
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm
@@ -0,0 +1,27 @@
+/* Test the -Wnonportable-cfstrings option, which should give
+ warnings if non-ASCII characters are embedded in constant
+ CFStrings. This will only work on MacOS X 10.2 and later. */
+/* Developed by Ziemowit Laski <zlaski@apple.com>. */
+
+/* So far, CFString is darwin-only. */
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mconstant-cfstrings -Wnonportable-cfstrings" } */
+
+#import <Foundation/NSString.h>
+#import <CoreFoundation/CFString.h>
+
+#ifndef __CONSTANT_CFSTRINGS__
+#error The -fconstant-cfstrings option is not functioning properly
+#endif
+
+void foo(void) {
+ NSString *s1 = @"Compile-time string literal";
+ CFStringRef s2 = CFSTR("Compile-time string literal");
+ NSString *s3 = @"Non-ASCII literal - \222"; /* { dg-warning "non-ASCII character in CFString literal" } */
+ CFStringRef s4 = CFSTR("\222 - Non-ASCII literal"); /* { dg-warning "non-ASCII character in CFString literal" } */
+ CFStringRef s5 = CFSTR("Non-ASCII (\222) literal"); /* { dg-warning "non-ASCII character in CFString literal" } */
+ NSString *s6 = @"\0Embedded NUL"; /* { dg-warning "embedded NUL in CFString literal" } */
+ CFStringRef s7 = CFSTR("Embedded \0NUL"); /* { dg-warning "embedded NUL in CFString literal" } */
+ CFStringRef s8 = CFSTR("Embedded NUL\0"); /* { dg-warning "embedded NUL in CFString literal" } */
+}
diff --git a/gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm b/gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm
new file mode 100644
index 00000000000..13cb7895779
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm
@@ -0,0 +1,26 @@
+/* Test if constant CFStrings may be passed back as ObjC strings. */
+/* Author: Ziemowit Laski */
+
+/* So far, CFString is darwin-only. */
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+#include <objc/Object.h>
+
+@interface Foo: Object {
+ char *cString;
+ unsigned int len;
+}
++ (Foo *)description;
+@end
+
+@interface Bar: Object
++ (Foo *) getString: (int) which;
+@end
+
+@implementation Bar
++ (Foo *) getString: (int) which {
+ return which? [Foo description]: @"Hello";
+}
+@end
diff --git a/gcc/testsuite/obj-c++.dg/const-str-1.mm b/gcc/testsuite/obj-c++.dg/strings/const-str-1.mm
index 156a92e1194..754c99bf1ae 100644
--- a/gcc/testsuite/obj-c++.dg/const-str-1.mm
+++ b/gcc/testsuite/obj-c++.dg/strings/const-str-1.mm
@@ -1,5 +1,6 @@
/* Test errors for constant strings. */
/* { dg-do compile } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
#ifdef __cplusplus
extern void baz(...);
diff --git a/gcc/testsuite/obj-c++.dg/const-str-12.mm b/gcc/testsuite/obj-c++.dg/strings/const-str-12.mm
index b92b50bcb09..921d055659c 100644
--- a/gcc/testsuite/obj-c++.dg/const-str-12.mm
+++ b/gcc/testsuite/obj-c++.dg/strings/const-str-12.mm
@@ -1,11 +1,11 @@
/* Test if ObjC types play nice in conditional expressions. */
/* Author: Ziemowit Laski */
-/* { dg-options "-fconstant-string-class=Foo" } */
/* { dg-do compile } */
+/* { dg-options "-fconstant-string-class=Foo" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */
-#include "../objc-obj-c++-shared/Object1.h"
-#import "../objc-obj-c++-shared/next-mapping.h"
+#include "../../objc-obj-c++-shared/Object1.h"
@interface Foo: Object {
char *cString;
@@ -19,7 +19,7 @@
@end
#ifdef NEXT_OBJC_USE_NEW_INTERFACE
-struct fudge_objc_class _FooClassReference;
+Class _FooClassReference;
#else
struct objc_class _FooClassReference;
#endif
diff --git a/gcc/testsuite/obj-c++.dg/const-str-2.mm b/gcc/testsuite/obj-c++.dg/strings/const-str-2.mm
index c406665c576..e9e2fc93db2 100644
--- a/gcc/testsuite/obj-c++.dg/const-str-2.mm
+++ b/gcc/testsuite/obj-c++.dg/strings/const-str-2.mm
@@ -1,6 +1,7 @@
/* Test the -fconstant-string-class flag error. */
/* { dg-do compile } */
/* { dg-options "-fconstant-string-class=" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=" { target *-*-darwin* } } */
{ dg-error "no class name specified|missing argument" "" { target *-*-* } 0 }
diff --git a/gcc/testsuite/obj-c++.dg/const-str-5.mm b/gcc/testsuite/obj-c++.dg/strings/const-str-5.mm
index 479b4fd089e..8c12a0c11d3 100644
--- a/gcc/testsuite/obj-c++.dg/const-str-5.mm
+++ b/gcc/testsuite/obj-c++.dg/strings/const-str-5.mm
@@ -1,8 +1,9 @@
/* Positive test case for constant string layout. */
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */
-/* { dg-options "-fconstant-string-class=MyConstantString" } */
/* { dg-do compile } */
+/* { dg-options "-fconstant-string-class=MyConstantString" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyConstantString" { target *-*-darwin* } } */
@interface MyBase {
const char *p;
diff --git a/gcc/testsuite/obj-c++.dg/const-str-6.mm b/gcc/testsuite/obj-c++.dg/strings/const-str-6.mm
index 3233083bf48..69954d9f422 100644
--- a/gcc/testsuite/obj-c++.dg/const-str-6.mm
+++ b/gcc/testsuite/obj-c++.dg/strings/const-str-6.mm
@@ -1,8 +1,9 @@
/* Negative test case for constant string layout. */
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */
-/* { dg-options "-fconstant-string-class=MyConstantString" } */
/* { dg-do compile } */
+/* { dg-options "-fconstant-string-class=MyConstantString" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyConstantString" { target *-*-darwin* } } */
@interface MyBase {
char p;
diff --git a/gcc/testsuite/obj-c++.dg/strings/strings.exp b/gcc/testsuite/obj-c++.dg/strings/strings.exp
new file mode 100644
index 00000000000..82cd925bb23
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/strings/strings.exp
@@ -0,0 +1,45 @@
+# String tests that only need to run at default optimization.
+
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# Load support procs.
+load_lib obj-c++-dg.exp
+
+# If a testcase doesn't have special options, use these.
+global DEFAULT_OBJCXXFLAGS
+if ![info exists DEFAULT_OBJCXXFLAGS] then {
+ set DEFAULT_OBJCXXFLAGS " -ansi -pedantic-errors -Wno-long-long"
+}
+
+# Initialize `dg'.
+dg-init
+
+# Gather a list of all tests.
+set tests [lsort [glob -nocomplain $srcdir/$subdir/*.mm]]
+
+# Main loop.
+dg-runtest $tests "-fgnu-runtime" $DEFAULT_OBJCXXFLAGS
+
+# darwin targets can also run code with the NeXT runtime.
+if [istarget "*-*-darwin*" ] {
+ dg-runtest $tests "-fnext-runtime" $DEFAULT_OBJCXXFLAGS
+}
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/obj-c++.dg/template-4.mm b/gcc/testsuite/obj-c++.dg/template-4.mm
index fa1132d9072..4d96a47a35a 100644
--- a/gcc/testsuite/obj-c++.dg/template-4.mm
+++ b/gcc/testsuite/obj-c++.dg/template-4.mm
@@ -2,6 +2,9 @@
/* { dg-do run } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
+/* { dg-additional-sources "../objc-obj-c++-shared/Object1.mm" } */
+
#include "../objc-obj-c++-shared/Object1.h"
#include "../objc-obj-c++-shared/next-mapping.h"
#include <stdarg.h>
@@ -76,4 +79,3 @@ int main(void) {
CHECK_IF(abc(a1, a2) * t.k == 35);
return 0;
}
-#include "../objc-obj-c++-shared/Object1-implementation.h"
diff --git a/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-1.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-1.mm
new file mode 100644
index 00000000000..a11b5266f40
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-1.mm
@@ -0,0 +1,59 @@
+/* Test the -fconstant-cfstrings option for constructing
+ compile-time immutable CFStrings, and their interoperation
+ with both Cocoa and CoreFoundation. This will only work
+ on MacOS X 10.1.2 and later. */
+/* Developed by Ziemowit Laski <zlaski@apple.com>. */
+
+/* So far, CFString is darwin-only. */
+/* { dg-do run { target *-*-darwin* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-options "-mconstant-cfstrings -framework Cocoa" } */
+
+#import <Foundation/NSString.h>
+#import <CoreFoundation/CFString.h>
+#include <stdlib.h>
+
+void printOut(NSString *str) {
+ NSLog(@"The value of str is: %@", str);
+}
+
+CFStringRef s0a = CFSTR("Compile-time string literal");
+CFStringRef s0b = CFSTR("Compile-time string literal");
+
+void checkNSRange(NSRange r) {
+ if (r.location != 6 || r.length != 5) {
+ printOut(@"Range check failed");
+ abort();
+ }
+}
+
+void checkCFRange(CFRange r) {
+ if (r.location != 6 || r.length != 5) {
+ printOut(@"Range check failed");
+ abort();
+ }
+}
+
+int main(void) {
+ const NSString *s1 = @"Compile-time string literal";
+ CFStringRef s2 = CFSTR("Compile-time string literal");
+
+ checkNSRange([@"Hello World" rangeOfString:@"World"]);
+ checkNSRange([(id)CFSTR("Hello World") rangeOfString:@"World"]);
+ checkNSRange([@"Hello World" rangeOfString:(id)CFSTR("World")]);
+ checkNSRange([(id)CFSTR("Hello World") rangeOfString:(id)CFSTR("World")]);
+
+ checkCFRange(CFStringFind((CFStringRef)@"Hello World", (CFStringRef)@"World", 0));
+ checkCFRange(CFStringFind(CFSTR("Hello World"), (CFStringRef)@"World", 0));
+ checkCFRange(CFStringFind((CFStringRef)@"Hello World", CFSTR("World"), 0));
+ checkCFRange(CFStringFind(CFSTR("Hello World"), CFSTR("World"), 0));
+
+ /* Check for string uniquing. */
+ if (s0a != s0b || s0a != s2 || s1 != (id)s2) {
+ NSLog(@"String uniquing failed");
+ abort ();
+ }
+
+ return 0;
+}
diff --git a/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-3.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-3.mm
new file mode 100644
index 00000000000..4a61429886b
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-3.mm
@@ -0,0 +1,27 @@
+/* Test for assigning compile-time constant-string objects to static variables. */
+/* Contributed by Ziemowit Laski <zlaski@apple.com> */
+
+/* So far, CFString is darwin-only. */
+/* { dg-do run { target *-*-darwin* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mconstant-cfstrings -framework Foundation" } */
+
+#include <stdlib.h>
+
+typedef const struct __CFString * CFStringRef;
+static CFStringRef appKey = (CFStringRef) @"com.apple.soundpref";
+
+static int CFPreferencesSynchronize (CFStringRef ref) {
+ return ref == appKey;
+}
+
+static void PrefsSynchronize()
+{
+ if(!CFPreferencesSynchronize(appKey))
+ abort();
+}
+
+int main(void) {
+ PrefsSynchronize();
+ return 0;
+}
diff --git a/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-4.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-4.mm
new file mode 100644
index 00000000000..1155db5f83f
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-4.mm
@@ -0,0 +1,21 @@
+/* Test if constant CFStrings get placed in the correct section and that the
+ layout of the object is correct for both m32 and m64. */
+/* Contributed by Ziemowit Laski <zlaski@apple.com> */
+
+/* So far, CFString is darwin-only. */
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+typedef const struct __CFString * CFStringRef;
+static CFStringRef appKey = (CFStringRef) @"com.apple.soundpref";
+
+void *foo (void)
+{
+ void *a = (void *)appKey;
+ return a;
+}
+
+/* { dg-final { scan-assembler ".section __DATA, __cfstring" } } */
+/* { dg-final { scan-assembler ".long\t___CFConstantStringClassReference\n\t.long\t1992\n\t.long\t.*\n\t.long\t19\n" { target { *-*-darwin* && { ! lp64 } } } } } */
+/* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t19\n" { target { *-*-darwin* && { lp64 } } } } } */
diff --git a/gcc/testsuite/obj-c++.dg/const-str-10.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-10.mm
index 693b6be6e84..f61a47481c6 100644
--- a/gcc/testsuite/obj-c++.dg/const-str-10.mm
+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-10.mm
@@ -4,8 +4,9 @@
/* { dg-do compile } */
/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
-#include "../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/Object1.h"
@interface NSString: Object
@end
diff --git a/gcc/testsuite/obj-c++.dg/const-str-11.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-11.mm
index ea9371091b8..4abab369a20 100644
--- a/gcc/testsuite/obj-c++.dg/const-str-11.mm
+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-11.mm
@@ -5,8 +5,9 @@
/* { dg-do compile } */
/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */
/* { dg-options "-fconstant-string-class=XStr" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=XStr" { target *-*-darwin* } } */
-#include "../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/Object1.h"
@interface XString: Object {
@protected
@@ -20,10 +21,10 @@
}
@end
-#ifndef NEXT_OBJC_USE_NEW_INTERFACE
-extern struct objc_class _XStrClassReference;
-#else
+#ifdef NEXT_OBJC_USE_NEW_INTERFACE
extern Class _XStrClassReference;
+#else
+extern struct objc_class _XStrClassReference;
#endif
const XStr *appKey = @"MyApp";
diff --git a/gcc/testsuite/obj-c++.dg/const-str-3.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm
index 5ea8e229fbe..edcbef0396e 100644
--- a/gcc/testsuite/obj-c++.dg/const-str-3.mm
+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm
@@ -2,12 +2,14 @@
runtime. */
/* Developed by Markus Hitter <mah@jump-ing.de>. */
-/* { dg-options "-fconstant-string-class=Foo" } */
/* { dg-do run { target *-*-darwin* } } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-options "-fconstant-string-class=Foo" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */
+/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.mm" } */
-#import "../objc-obj-c++-shared/Object1.h"
-#import "../objc-obj-c++-shared/next-mapping.h"
+#import "../../../objc-obj-c++-shared/Object1.h"
+#import "../../../objc-obj-c++-shared/next-mapping.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
@@ -55,4 +57,4 @@ int main () {
printf([@"This is a working constant string object\n" customString]);
return 0;
}
-#include "../objc-obj-c++-shared/Object1-implementation.h"
+
diff --git a/gcc/testsuite/obj-c++.dg/const-str-4.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-4.mm
index 09d24ad4cb7..c2cadd3df96 100644
--- a/gcc/testsuite/obj-c++.dg/const-str-4.mm
+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-4.mm
@@ -1,7 +1,9 @@
/* Ensure that the preprocessor handles ObjC string constants gracefully. */
/* Author: Ziemowit Laski <zlaski@apple.com> */
-/* { dg-options "-fconstant-string-class=MyString" } */
+
/* { dg-do run { target *-*-darwin* } } */
+/* { dg-options "-fconstant-string-class=MyString" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyString" { target *-*-darwin* } } */
#include <stdlib.h>
diff --git a/gcc/testsuite/obj-c++.dg/const-str-7.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-7.mm
index fc423bde3bb..d58cb91a7bb 100644
--- a/gcc/testsuite/obj-c++.dg/const-str-7.mm
+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-7.mm
@@ -2,12 +2,12 @@
scopes. */
/* Developed by Andrew Pinski <pinskia@physics.uc.edu> */
-/* { dg-options "-fconstant-string-class=Foo" } */
/* { dg-do run } */
-/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-options "-fconstant-string-class=Foo" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */
+/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.mm" } */
-#include "../objc-obj-c++-shared/Object1.h"
-#include "../objc-obj-c++-shared/next-mapping.h"
+#include "../../../objc-obj-c++-shared/Object1.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -21,7 +21,7 @@
@end
#ifdef NEXT_OBJC_USE_NEW_INTERFACE
-struct fudge_objc_class _FooClassReference;
+Class _FooClassReference;
#else
struct objc_class _FooClassReference;
#endif
@@ -44,4 +44,3 @@ int main () {
}
return 0;
}
-#include "../objc-obj-c++-shared/Object1-implementation.h"
diff --git a/gcc/testsuite/obj-c++.dg/const-str-8.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-8.mm
index 67473417f29..17997b62842 100644
--- a/gcc/testsuite/obj-c++.dg/const-str-8.mm
+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-8.mm
@@ -1,10 +1,12 @@
/* Test for assigning compile-time constant-string objects to static variables. */
/* Contributed by Ziemowit Laski <zlaski@apple.com> */
-/* { dg-options "-fconstant-string-class=Foo" } */
/* { dg-do run { target *-*-darwin* } } */
+/* { dg-options "-fconstant-string-class=Foo" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */
+/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.mm" } */
-#include "../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/Object1.h"
#include <stdlib.h>
@interface Foo: Object {
@@ -40,5 +42,3 @@ int main () {
PrefsSynchronize();
return 0;
}
-
-#include "../objc-obj-c++-shared/Object1-implementation.h"
diff --git a/gcc/testsuite/obj-c++.dg/const-str-9.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-9.mm
index bca916a1609..7c99f6b5d36 100644
--- a/gcc/testsuite/obj-c++.dg/const-str-9.mm
+++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-9.mm
@@ -3,8 +3,9 @@
/* { dg-do compile } */
/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
-#include "../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/Object1.h"
@interface NSConstantString: Object {
char *cString;
diff --git a/gcc/testsuite/obj-c++.dg/torture/strings/string1.mm b/gcc/testsuite/obj-c++.dg/torture/strings/string1.mm
new file mode 100644
index 00000000000..df315fb8784
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/torture/strings/string1.mm
@@ -0,0 +1,23 @@
+/* Based on a test case contributed by Nicola Pero. */
+
+/* { dg-do run } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.mm" } */
+
+#include "../../../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/next-mapping.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+#ifndef __NEXT_RUNTIME__
+#include <objc/NXConstStr.h>
+#endif
+
+int main(int argc, char **args)
+{
+ if (strcmp ([@"this is a string" cString], "this is a string"))
+ abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/obj-c++.dg/torture/strings/strings.exp b/gcc/testsuite/obj-c++.dg/torture/strings/strings.exp
new file mode 100644
index 00000000000..180401c3b76
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/torture/strings/strings.exp
@@ -0,0 +1,34 @@
+# String tests that should be run at all optimization levels.
+
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+load_lib obj-c++-dg.exp
+
+dg-init
+# Gather a list of all tests.
+set tests [lsort [glob -nocomplain $srcdir/$subdir/*.mm]]
+
+obj-c++-dg-runtest $tests "-fgnu-runtime"
+
+# Darwin targets can also run code with the NeXT runtime.
+if [istarget "*-*-darwin*" ] {
+ obj-c++-dg-runtest $tests "-fnext-runtime"
+}
+
+dg-finish
diff --git a/gcc/testsuite/objc.dg/foreach-2.m b/gcc/testsuite/objc.dg/foreach-2.m
index 1e9c515f600..e44222311a7 100644
--- a/gcc/testsuite/objc.dg/foreach-2.m
+++ b/gcc/testsuite/objc.dg/foreach-2.m
@@ -3,10 +3,11 @@
*/
/* { dg-do run } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
/* { dg-additional-sources "../objc-obj-c++-shared/Object1.m" } */
-#import "../objc-obj-c++-shared/Object1.h"
-#import "../objc-obj-c++-shared/next-mapping.h"
+#include "../objc-obj-c++-shared/Object1.h"
+#include "../objc-obj-c++-shared/next-mapping.h"
#ifndef __NEXT_RUNTIME__
#include <objc/NXConstStr.h>
#endif
diff --git a/gcc/testsuite/objc.dg/foreach-4.m b/gcc/testsuite/objc.dg/foreach-4.m
index b6cfe2c0c65..55484d7dd5a 100644
--- a/gcc/testsuite/objc.dg/foreach-4.m
+++ b/gcc/testsuite/objc.dg/foreach-4.m
@@ -3,6 +3,7 @@
*/
/* { dg-do run } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
/* { dg-additional-sources "../objc-obj-c++-shared/Object1.m" } */
#import "../objc-obj-c++-shared/Object1.h"
diff --git a/gcc/testsuite/objc.dg/foreach-5.m b/gcc/testsuite/objc.dg/foreach-5.m
index f6d34f41399..ae06d670257 100644
--- a/gcc/testsuite/objc.dg/foreach-5.m
+++ b/gcc/testsuite/objc.dg/foreach-5.m
@@ -3,6 +3,7 @@
*/
/* { dg-do run } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
/* { dg-additional-sources "../objc-obj-c++-shared/Object1.m" } */
#import "../objc-obj-c++-shared/Object1.h"
diff --git a/gcc/testsuite/objc.dg/strings/const-cfstring-2.m b/gcc/testsuite/objc.dg/strings/const-cfstring-2.m
new file mode 100644
index 00000000000..14ae68c6c50
--- /dev/null
+++ b/gcc/testsuite/objc.dg/strings/const-cfstring-2.m
@@ -0,0 +1,27 @@
+/* Test the -Wnonportable-cfstrings option, which should give
+ warnings if non-ASCII characters are embedded in constant
+ CFStrings. This will only work on MacOS X 10.2 and later. */
+/* Developed by Ziemowit Laski <zlaski@apple.com>. */
+
+/* So far, CFString is darwin-only. */
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mconstant-cfstrings -Wnonportable-cfstrings" } */
+
+#import <Foundation/NSString.h>
+#import <CoreFoundation/CFString.h>
+
+#ifndef __CONSTANT_CFSTRINGS__
+#error The -fconstant-cfstrings option is not functioning properly
+#endif
+
+void foo(void) {
+ NSString *s1 = @"Compile-time string literal";
+ CFStringRef s2 = CFSTR("Compile-time string literal");
+ NSString *s3 = @"Non-ASCII literal - \222"; /* { dg-warning "non-ASCII character in CFString literal" } */
+ CFStringRef s4 = CFSTR("\222 - Non-ASCII literal"); /* { dg-warning "non-ASCII character in CFString literal" } */
+ CFStringRef s5 = CFSTR("Non-ASCII (\222) literal"); /* { dg-warning "non-ASCII character in CFString literal" } */
+ NSString *s6 = @"\0Embedded NUL"; /* { dg-warning "embedded NUL in CFString literal" } */
+ CFStringRef s7 = CFSTR("Embedded \0NUL"); /* { dg-warning "embedded NUL in CFString literal" } */
+ CFStringRef s8 = CFSTR("Embedded NUL\0"); /* { dg-warning "embedded NUL in CFString literal" } */
+}
diff --git a/gcc/testsuite/objc.dg/strings/const-cfstring-5.m b/gcc/testsuite/objc.dg/strings/const-cfstring-5.m
new file mode 100644
index 00000000000..13cb7895779
--- /dev/null
+++ b/gcc/testsuite/objc.dg/strings/const-cfstring-5.m
@@ -0,0 +1,26 @@
+/* Test if constant CFStrings may be passed back as ObjC strings. */
+/* Author: Ziemowit Laski */
+
+/* So far, CFString is darwin-only. */
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+#include <objc/Object.h>
+
+@interface Foo: Object {
+ char *cString;
+ unsigned int len;
+}
++ (Foo *)description;
+@end
+
+@interface Bar: Object
++ (Foo *) getString: (int) which;
+@end
+
+@implementation Bar
++ (Foo *) getString: (int) which {
+ return which? [Foo description]: @"Hello";
+}
+@end
diff --git a/gcc/testsuite/objc.dg/const-str-1.m b/gcc/testsuite/objc.dg/strings/const-str-1.m
index 156a92e1194..754c99bf1ae 100644
--- a/gcc/testsuite/objc.dg/const-str-1.m
+++ b/gcc/testsuite/objc.dg/strings/const-str-1.m
@@ -1,5 +1,6 @@
/* Test errors for constant strings. */
/* { dg-do compile } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
#ifdef __cplusplus
extern void baz(...);
diff --git a/gcc/testsuite/objc.dg/const-str-12.m b/gcc/testsuite/objc.dg/strings/const-str-12.m
index 93059018647..93059018647 100644
--- a/gcc/testsuite/objc.dg/const-str-12.m
+++ b/gcc/testsuite/objc.dg/strings/const-str-12.m
diff --git a/gcc/testsuite/objc.dg/const-str-12b.m b/gcc/testsuite/objc.dg/strings/const-str-12b.m
index b92b50bcb09..cad481e15a0 100644
--- a/gcc/testsuite/objc.dg/const-str-12b.m
+++ b/gcc/testsuite/objc.dg/strings/const-str-12b.m
@@ -1,11 +1,12 @@
/* Test if ObjC types play nice in conditional expressions. */
/* Author: Ziemowit Laski */
-/* { dg-options "-fconstant-string-class=Foo" } */
/* { dg-do compile } */
+/* { dg-options "-fconstant-string-class=Foo" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */
-#include "../objc-obj-c++-shared/Object1.h"
-#import "../objc-obj-c++-shared/next-mapping.h"
+#include "../../objc-obj-c++-shared/Object1.h"
+#import "../../objc-obj-c++-shared/next-mapping.h"
@interface Foo: Object {
char *cString;
diff --git a/gcc/testsuite/objc.dg/const-str-2.m b/gcc/testsuite/objc.dg/strings/const-str-2.m
index c406665c576..49ab0630433 100644
--- a/gcc/testsuite/objc.dg/const-str-2.m
+++ b/gcc/testsuite/objc.dg/strings/const-str-2.m
@@ -1,6 +1,7 @@
/* Test the -fconstant-string-class flag error. */
/* { dg-do compile } */
-/* { dg-options "-fconstant-string-class=" } */
+/* { dg-options "-fconstant-string-class=" { target *-*-* } } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=" { target *-*-darwin* } } */
{ dg-error "no class name specified|missing argument" "" { target *-*-* } 0 }
diff --git a/gcc/testsuite/objc.dg/const-str-5.m b/gcc/testsuite/objc.dg/strings/const-str-5.m
index 186edcfceb2..42071767adb 100644
--- a/gcc/testsuite/objc.dg/const-str-5.m
+++ b/gcc/testsuite/objc.dg/strings/const-str-5.m
@@ -1,8 +1,9 @@
/* Positive test case for constant string layout. */
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */
-/* { dg-options "-fconstant-string-class=MyConstantString" } */
/* { dg-do compile } */
+/* { dg-options "-fconstant-string-class=MyConstantString" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyConstantString" { target *-*-darwin* } } */
@interface MyBase {
const char *p;
diff --git a/gcc/testsuite/objc.dg/const-str-6.m b/gcc/testsuite/objc.dg/strings/const-str-6.m
index a7cbbf7141a..fca7643af37 100644
--- a/gcc/testsuite/objc.dg/const-str-6.m
+++ b/gcc/testsuite/objc.dg/strings/const-str-6.m
@@ -1,8 +1,9 @@
/* Negative test case for constant string layout. */
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */
-/* { dg-options "-fconstant-string-class=MyConstantString" } */
/* { dg-do compile } */
+/* { dg-options "-fconstant-string-class=MyConstantString" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyConstantString" { target *-*-darwin* } } */
@interface MyBase {
char p;
diff --git a/gcc/testsuite/objc.dg/strings/strings.exp b/gcc/testsuite/objc.dg/strings/strings.exp
new file mode 100644
index 00000000000..823c2871a57
--- /dev/null
+++ b/gcc/testsuite/objc.dg/strings/strings.exp
@@ -0,0 +1,46 @@
+# String tests that only need to run at default optimization.
+
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# Load support procs.
+
+load_lib objc-dg.exp
+
+# If a testcase doesn't have special options, use these.
+global DEFAULT_CFLAGS
+if ![info exists DEFAULT_CFLAGS] then {
+ set DEFAULT_CFLAGS ""
+}
+
+# Initialize `dg'.
+dg-init
+
+# Gather a list of all tests.
+set tests [lsort [glob -nocomplain $srcdir/$subdir/*.m]]
+
+# Main loop.
+dg-runtest $tests "-fgnu-runtime" $DEFAULT_CFLAGS
+
+# darwin targets can also run code with the NeXT runtime.
+if [istarget "*-*-darwin*" ] {
+ dg-runtest $tests "-fnext-runtime" $DEFAULT_CFLAGS
+}
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/objc.dg/torture/strings/const-cfstring-1.m b/gcc/testsuite/objc.dg/torture/strings/const-cfstring-1.m
new file mode 100644
index 00000000000..a11b5266f40
--- /dev/null
+++ b/gcc/testsuite/objc.dg/torture/strings/const-cfstring-1.m
@@ -0,0 +1,59 @@
+/* Test the -fconstant-cfstrings option for constructing
+ compile-time immutable CFStrings, and their interoperation
+ with both Cocoa and CoreFoundation. This will only work
+ on MacOS X 10.1.2 and later. */
+/* Developed by Ziemowit Laski <zlaski@apple.com>. */
+
+/* So far, CFString is darwin-only. */
+/* { dg-do run { target *-*-darwin* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-options "-mconstant-cfstrings -framework Cocoa" } */
+
+#import <Foundation/NSString.h>
+#import <CoreFoundation/CFString.h>
+#include <stdlib.h>
+
+void printOut(NSString *str) {
+ NSLog(@"The value of str is: %@", str);
+}
+
+CFStringRef s0a = CFSTR("Compile-time string literal");
+CFStringRef s0b = CFSTR("Compile-time string literal");
+
+void checkNSRange(NSRange r) {
+ if (r.location != 6 || r.length != 5) {
+ printOut(@"Range check failed");
+ abort();
+ }
+}
+
+void checkCFRange(CFRange r) {
+ if (r.location != 6 || r.length != 5) {
+ printOut(@"Range check failed");
+ abort();
+ }
+}
+
+int main(void) {
+ const NSString *s1 = @"Compile-time string literal";
+ CFStringRef s2 = CFSTR("Compile-time string literal");
+
+ checkNSRange([@"Hello World" rangeOfString:@"World"]);
+ checkNSRange([(id)CFSTR("Hello World") rangeOfString:@"World"]);
+ checkNSRange([@"Hello World" rangeOfString:(id)CFSTR("World")]);
+ checkNSRange([(id)CFSTR("Hello World") rangeOfString:(id)CFSTR("World")]);
+
+ checkCFRange(CFStringFind((CFStringRef)@"Hello World", (CFStringRef)@"World", 0));
+ checkCFRange(CFStringFind(CFSTR("Hello World"), (CFStringRef)@"World", 0));
+ checkCFRange(CFStringFind((CFStringRef)@"Hello World", CFSTR("World"), 0));
+ checkCFRange(CFStringFind(CFSTR("Hello World"), CFSTR("World"), 0));
+
+ /* Check for string uniquing. */
+ if (s0a != s0b || s0a != s2 || s1 != (id)s2) {
+ NSLog(@"String uniquing failed");
+ abort ();
+ }
+
+ return 0;
+}
diff --git a/gcc/testsuite/objc.dg/torture/strings/const-cfstring-3.m b/gcc/testsuite/objc.dg/torture/strings/const-cfstring-3.m
new file mode 100644
index 00000000000..4a61429886b
--- /dev/null
+++ b/gcc/testsuite/objc.dg/torture/strings/const-cfstring-3.m
@@ -0,0 +1,27 @@
+/* Test for assigning compile-time constant-string objects to static variables. */
+/* Contributed by Ziemowit Laski <zlaski@apple.com> */
+
+/* So far, CFString is darwin-only. */
+/* { dg-do run { target *-*-darwin* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mconstant-cfstrings -framework Foundation" } */
+
+#include <stdlib.h>
+
+typedef const struct __CFString * CFStringRef;
+static CFStringRef appKey = (CFStringRef) @"com.apple.soundpref";
+
+static int CFPreferencesSynchronize (CFStringRef ref) {
+ return ref == appKey;
+}
+
+static void PrefsSynchronize()
+{
+ if(!CFPreferencesSynchronize(appKey))
+ abort();
+}
+
+int main(void) {
+ PrefsSynchronize();
+ return 0;
+}
diff --git a/gcc/testsuite/objc.dg/torture/strings/const-cfstring-4.m b/gcc/testsuite/objc.dg/torture/strings/const-cfstring-4.m
new file mode 100644
index 00000000000..1155db5f83f
--- /dev/null
+++ b/gcc/testsuite/objc.dg/torture/strings/const-cfstring-4.m
@@ -0,0 +1,21 @@
+/* Test if constant CFStrings get placed in the correct section and that the
+ layout of the object is correct for both m32 and m64. */
+/* Contributed by Ziemowit Laski <zlaski@apple.com> */
+
+/* So far, CFString is darwin-only. */
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+typedef const struct __CFString * CFStringRef;
+static CFStringRef appKey = (CFStringRef) @"com.apple.soundpref";
+
+void *foo (void)
+{
+ void *a = (void *)appKey;
+ return a;
+}
+
+/* { dg-final { scan-assembler ".section __DATA, __cfstring" } } */
+/* { dg-final { scan-assembler ".long\t___CFConstantStringClassReference\n\t.long\t1992\n\t.long\t.*\n\t.long\t19\n" { target { *-*-darwin* && { ! lp64 } } } } } */
+/* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t19\n" { target { *-*-darwin* && { lp64 } } } } } */
diff --git a/gcc/testsuite/objc.dg/const-str-10.m b/gcc/testsuite/objc.dg/torture/strings/const-str-10.m
index 7f59a63f93b..c170f389dfb 100644
--- a/gcc/testsuite/objc.dg/const-str-10.m
+++ b/gcc/testsuite/objc.dg/torture/strings/const-str-10.m
@@ -4,8 +4,9 @@
/* { dg-do compile { target { *-*-darwin* } } } */
/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
-#include "../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/Object1.h"
@interface NSString: Object
@end
diff --git a/gcc/testsuite/objc.dg/const-str-11.m b/gcc/testsuite/objc.dg/torture/strings/const-str-11.m
index ae3c3303f6f..9f3705ef211 100644
--- a/gcc/testsuite/objc.dg/const-str-11.m
+++ b/gcc/testsuite/objc.dg/torture/strings/const-str-11.m
@@ -5,8 +5,9 @@
/* { dg-do compile { target *-*-darwin* } } */
/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */
/* { dg-options "-fconstant-string-class=XStr" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=XStr" { target *-*-darwin* } } */
-#include "../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/Object1.h"
@interface XString: Object {
@protected
diff --git a/gcc/testsuite/objc.dg/const-str-3.m b/gcc/testsuite/objc.dg/torture/strings/const-str-3.m
index 26e72808e7c..ca2df5a89ec 100644
--- a/gcc/testsuite/objc.dg/const-str-3.m
+++ b/gcc/testsuite/objc.dg/torture/strings/const-str-3.m
@@ -1,11 +1,13 @@
/* Test the -fconstant-string-class=Foo option under the NeXT runtime. */
/* Developed by Markus Hitter <mah@jump-ing.de>. */
/* { dg-do run } */
-/* { dg-options "-fconstant-string-class=Foo" } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-options "-fconstant-string-class=Foo" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */
+/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */
-#import "../objc-obj-c++-shared/Object1.h"
-#import "../objc-obj-c++-shared/next-mapping.h"
+#include "../../../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/next-mapping.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -49,5 +51,3 @@ int main () {
printf([@"This is a working constant string object\n" customString]);
return 0;
}
-
-#include "../objc-obj-c++-shared/Object1-implementation.h"
diff --git a/gcc/testsuite/objc.dg/const-str-4.m b/gcc/testsuite/objc.dg/torture/strings/const-str-4.m
index 9582a32554f..446b075da95 100644
--- a/gcc/testsuite/objc.dg/const-str-4.m
+++ b/gcc/testsuite/objc.dg/torture/strings/const-str-4.m
@@ -1,7 +1,8 @@
/* Ensure that the preprocessor handles ObjC string constants gracefully. */
/* Author: Ziemowit Laski <zlaski@apple.com> */
-/* { dg-options "-fconstant-string-class=MyString " } */
/* { dg-do run } */
+/* { dg-options "-fconstant-string-class=MyString " } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyString " { target *-*-darwin* } } */
extern void abort(void);
diff --git a/gcc/testsuite/objc.dg/const-str-7.m b/gcc/testsuite/objc.dg/torture/strings/const-str-7.m
index 24c5dd3ed82..7221e28d48b 100644
--- a/gcc/testsuite/objc.dg/const-str-7.m
+++ b/gcc/testsuite/objc.dg/torture/strings/const-str-7.m
@@ -1,9 +1,11 @@
/* Test to make sure that the const objc strings are the same across scopes. */
/* Developed by Andrew Pinski <pinskia@physics.uc.edu> */
-/* { dg-options "-fconstant-string-class=Foo " } */
/* { dg-do run } */
+/* { dg-options "-fconstant-string-class=Foo " } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */
+/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */
-#include "../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/Object1.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -15,10 +17,10 @@
- (char *)customString;
@end
-#ifndef NEXT_OBJC_USE_NEW_INTERFACE
-struct objc_class _FooClassReference;
-#else
+#ifdef NEXT_OBJC_USE_NEW_INTERFACE
Class _FooClassReference;
+#else
+struct objc_class _FooClassReference;
#endif
@implementation Foo : Object
@@ -38,5 +40,3 @@ int main () {
}
return 0;
}
-
-#include "../objc-obj-c++-shared/Object1-implementation.h"
diff --git a/gcc/testsuite/objc.dg/const-str-8.m b/gcc/testsuite/objc.dg/torture/strings/const-str-8.m
index a7da0e10276..c5bacaf437f 100644
--- a/gcc/testsuite/objc.dg/const-str-8.m
+++ b/gcc/testsuite/objc.dg/torture/strings/const-str-8.m
@@ -1,9 +1,11 @@
/* Test for assigning compile-time constant-string objects to static variables. */
/* Contributed by Ziemowit Laski <zlaski@apple.com> */
-/* { dg-options "-fconstant-string-class=Foo" } */
/* { dg-do run } */
+/* { dg-options "-fconstant-string-class=Foo" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */
+/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */
-#include "../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/Object1.h"
#include <stdlib.h>
@interface Foo: Object {
@@ -12,10 +14,10 @@
}
@end
-#ifndef NEXT_OBJC_USE_NEW_INTERFACE
-struct objc_class _FooClassReference;
-#else
+#ifdef NEXT_OBJC_USE_NEW_INTERFACE
Class _FooClassReference;
+#else
+struct objc_class _FooClassReference;
#endif
@implementation Foo : Object
@@ -39,5 +41,3 @@ int main () {
PrefsSynchronize();
return 0;
}
-
-#include "../objc-obj-c++-shared/Object1-implementation.h"
diff --git a/gcc/testsuite/objc.dg/const-str-9.m b/gcc/testsuite/objc.dg/torture/strings/const-str-9.m
index 86521c2cead..ddbe93dde09 100644
--- a/gcc/testsuite/objc.dg/const-str-9.m
+++ b/gcc/testsuite/objc.dg/torture/strings/const-str-9.m
@@ -3,8 +3,9 @@
/* { dg-do compile } */
/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
-#include "../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/Object1.h"
@interface NSConstantString: Object {
char *cString;
diff --git a/gcc/testsuite/objc.dg/torture/strings/string1.m b/gcc/testsuite/objc.dg/torture/strings/string1.m
new file mode 100644
index 00000000000..76d3c9b0756
--- /dev/null
+++ b/gcc/testsuite/objc.dg/torture/strings/string1.m
@@ -0,0 +1,23 @@
+/* Based on a test case contributed by Nicola Pero. */
+
+/* { dg-do run } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */
+
+#include "../../../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/next-mapping.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+#ifndef __NEXT_RUNTIME__
+#include <objc/NXConstStr.h>
+#endif
+
+int main(int argc, void **args)
+{
+ if (strcmp ([@"this is a string" cString], "this is a string"))
+ abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/objc.dg/torture/strings/string2.m b/gcc/testsuite/objc.dg/torture/strings/string2.m
new file mode 100644
index 00000000000..90e4db1e33c
--- /dev/null
+++ b/gcc/testsuite/objc.dg/torture/strings/string2.m
@@ -0,0 +1,24 @@
+/* Based on a test case contributed by Nicola Pero. */
+
+/* { dg-do run } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */
+
+#include "../../../objc-obj-c++-shared/Object1.h"
+#include "../../../objc-obj-c++-shared/next-mapping.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+#ifndef __NEXT_RUNTIME__
+#include <objc/NXConstStr.h>
+#endif
+
+int main(int argc, void **args)
+{
+ if (strcmp ([@"this " @"is " @"a " @"string" cString],
+ "this " "is " "a " "string"))
+ abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/objc.dg/torture/strings/string3.m b/gcc/testsuite/objc.dg/torture/strings/string3.m
new file mode 100644
index 00000000000..ca08fed8d00
--- /dev/null
+++ b/gcc/testsuite/objc.dg/torture/strings/string3.m
@@ -0,0 +1,24 @@
+/* Based on a test case contributed by Nicola Pero. */
+
+/* { dg-do run } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */
+
+#include "../../../objc-obj-c++-shared/Object1.h"
+#import "../../../objc-obj-c++-shared/next-mapping.h"
+#include <string.h>
+#include <stdlib.h>
+
+#ifndef __NEXT_RUNTIME__
+#include <objc/NXConstStr.h>
+#endif
+
+#define STRING "this is a string"
+
+int main (int argc, void **args)
+{
+ if (strcmp ([@STRING cString], STRING))
+ abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/objc.dg/torture/strings/string4.m b/gcc/testsuite/objc.dg/torture/strings/string4.m
new file mode 100644
index 00000000000..caa877e4de7
--- /dev/null
+++ b/gcc/testsuite/objc.dg/torture/strings/string4.m
@@ -0,0 +1,22 @@
+/* Based on a test case contributed by Nicola Pero. */
+
+/* { dg-do run } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */
+
+#include "../../../objc-obj-c++-shared/Object1.h"
+#import "../../../objc-obj-c++-shared/next-mapping.h"
+#include <string.h>
+#include <stdlib.h>
+
+#ifndef __NEXT_RUNTIME__
+#include <objc/NXConstStr.h>
+#endif
+
+int main(int argc, void **args)
+{
+ if ([@"this is a string" length] != strlen ("this is a string"))
+ abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/objc.dg/torture/strings/strings.exp b/gcc/testsuite/objc.dg/torture/strings/strings.exp
new file mode 100644
index 00000000000..e309186136d
--- /dev/null
+++ b/gcc/testsuite/objc.dg/torture/strings/strings.exp
@@ -0,0 +1,34 @@
+# String tests that should be run at all optimization levels.
+
+# Copyright (C) 2010 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+load_lib objc-dg.exp
+load_lib target-supports-dg.exp
+
+dg-init
+
+# Gather a list of all tests.
+set tests [lsort [glob -nocomplain $srcdir/$subdir/*.m]]
+
+objc-dg-runtest $tests "-fgnu-runtime"
+
+# Darwin targets also test with the NeXT runtime.
+if [istarget "*-*-darwin*" ] {
+ objc-dg-runtest $tests "-fnext-runtime"
+}
+
+dg-finish
diff --git a/gcc/testsuite/objc/execute/string1.m b/gcc/testsuite/objc/execute/string1.m
deleted file mode 100644
index acc486ab21f..00000000000
--- a/gcc/testsuite/objc/execute/string1.m
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Based on a test case contributed by Nicola Pero. */
-
-#import "../../objc-obj-c++-shared/next-mapping.h"
-#include <string.h>
-#include <stdlib.h>
-
-#ifndef __NEXT_RUNTIME__
-#include <objc/NXConstStr.h>
-#endif
-
-int main(int argc, void **args)
-{
- if (strcmp ([@"this is a string" cString], "this is a string"))
- abort ();
- return 0;
-}
diff --git a/gcc/testsuite/objc/execute/string2.m b/gcc/testsuite/objc/execute/string2.m
deleted file mode 100644
index 32e70616916..00000000000
--- a/gcc/testsuite/objc/execute/string2.m
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Based on a test case contributed by Nicola Pero. */
-
-#import "../../objc-obj-c++-shared/next-mapping.h"
-#include <string.h>
-#include <stdlib.h>
-
-#ifndef __NEXT_RUNTIME__
-#include <objc/NXConstStr.h>
-#endif
-
-int main(int argc, void **args)
-{
- if (strcmp ([@"this " @"is " @"a " @"string" cString],
- "this " "is " "a " "string"))
- abort ();
- return 0;
-}
diff --git a/gcc/testsuite/objc/execute/string3.m b/gcc/testsuite/objc/execute/string3.m
deleted file mode 100644
index 2595a09c19a..00000000000
--- a/gcc/testsuite/objc/execute/string3.m
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Based on a test case contributed by Nicola Pero. */
-
-#import "../../objc-obj-c++-shared/next-mapping.h"
-#include <string.h>
-#include <stdlib.h>
-
-#ifndef __NEXT_RUNTIME__
-#include <objc/NXConstStr.h>
-#endif
-
-#define STRING "this is a string"
-
-int main (int argc, void **args)
-{
- if (strcmp ([@STRING cString], STRING))
- abort ();
- return 0;
-}
diff --git a/gcc/testsuite/objc/execute/string4.m b/gcc/testsuite/objc/execute/string4.m
deleted file mode 100644
index a7bcf431d52..00000000000
--- a/gcc/testsuite/objc/execute/string4.m
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Based on a test case contributed by Nicola Pero. */
-
-#import "../../objc-obj-c++-shared/next-mapping.h"
-#include <string.h>
-#include <stdlib.h>
-
-#ifndef __NEXT_RUNTIME__
-#include <objc/NXConstStr.h>
-#endif
-
-int main(int argc, void **args)
-{
- if ([@"this is a string" length] != strlen ("this is a string"))
- abort ();
- return 0;
-}