CFStrings for Darwin
authoriains <iains@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 22 Oct 2010 10:30:29 +0000 (10:30 +0000)
committeriains <iains@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 22 Oct 2010 10:30:29 +0000 (10:30 +0000)
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

55 files changed:
gcc/testsuite/ChangeLog
gcc/testsuite/lib/obj-c++-dg.exp
gcc/testsuite/lib/objc-dg.exp
gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/strings/const-str-1.mm [moved from gcc/testsuite/obj-c++.dg/const-str-1.mm with 81% similarity]
gcc/testsuite/obj-c++.dg/strings/const-str-12.mm [moved from gcc/testsuite/obj-c++.dg/const-str-12.mm with 75% similarity]
gcc/testsuite/obj-c++.dg/strings/const-str-2.mm [moved from gcc/testsuite/obj-c++.dg/const-str-2.mm with 69% similarity]
gcc/testsuite/obj-c++.dg/strings/const-str-5.mm [moved from gcc/testsuite/obj-c++.dg/const-str-5.mm with 84% similarity]
gcc/testsuite/obj-c++.dg/strings/const-str-6.mm [moved from gcc/testsuite/obj-c++.dg/const-str-6.mm with 85% similarity]
gcc/testsuite/obj-c++.dg/strings/strings.exp [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/template-4.mm
gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-1.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-3.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-4.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/torture/strings/const-str-10.mm [moved from gcc/testsuite/obj-c++.dg/const-str-10.mm with 89% similarity]
gcc/testsuite/obj-c++.dg/torture/strings/const-str-11.mm [moved from gcc/testsuite/obj-c++.dg/const-str-11.mm with 83% similarity]
gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm [moved from gcc/testsuite/obj-c++.dg/const-str-3.mm with 83% similarity]
gcc/testsuite/obj-c++.dg/torture/strings/const-str-4.mm [moved from gcc/testsuite/obj-c++.dg/const-str-4.mm with 85% similarity]
gcc/testsuite/obj-c++.dg/torture/strings/const-str-7.mm [moved from gcc/testsuite/obj-c++.dg/const-str-7.mm with 70% similarity]
gcc/testsuite/obj-c++.dg/torture/strings/const-str-8.mm [moved from gcc/testsuite/obj-c++.dg/const-str-8.mm with 77% similarity]
gcc/testsuite/obj-c++.dg/torture/strings/const-str-9.mm [moved from gcc/testsuite/obj-c++.dg/const-str-9.mm with 88% similarity]
gcc/testsuite/obj-c++.dg/torture/strings/string1.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/torture/strings/strings.exp [new file with mode: 0644]
gcc/testsuite/objc.dg/foreach-2.m
gcc/testsuite/objc.dg/foreach-4.m
gcc/testsuite/objc.dg/foreach-5.m
gcc/testsuite/objc.dg/strings/const-cfstring-2.m [new file with mode: 0644]
gcc/testsuite/objc.dg/strings/const-cfstring-5.m [new file with mode: 0644]
gcc/testsuite/objc.dg/strings/const-str-1.m [moved from gcc/testsuite/objc.dg/const-str-1.m with 81% similarity]
gcc/testsuite/objc.dg/strings/const-str-12.m [moved from gcc/testsuite/objc.dg/const-str-12.m with 100% similarity]
gcc/testsuite/objc.dg/strings/const-str-12b.m [moved from gcc/testsuite/objc.dg/const-str-12b.m with 74% similarity]
gcc/testsuite/objc.dg/strings/const-str-2.m [moved from gcc/testsuite/objc.dg/const-str-2.m with 51% similarity]
gcc/testsuite/objc.dg/strings/const-str-5.m [moved from gcc/testsuite/objc.dg/const-str-5.m with 84% similarity]
gcc/testsuite/objc.dg/strings/const-str-6.m [moved from gcc/testsuite/objc.dg/const-str-6.m with 85% similarity]
gcc/testsuite/objc.dg/strings/strings.exp [new file with mode: 0644]
gcc/testsuite/objc.dg/torture/strings/const-cfstring-1.m [new file with mode: 0644]
gcc/testsuite/objc.dg/torture/strings/const-cfstring-3.m [new file with mode: 0644]
gcc/testsuite/objc.dg/torture/strings/const-cfstring-4.m [new file with mode: 0644]
gcc/testsuite/objc.dg/torture/strings/const-str-10.m [moved from gcc/testsuite/objc.dg/const-str-10.m with 89% similarity]
gcc/testsuite/objc.dg/torture/strings/const-str-11.m [moved from gcc/testsuite/objc.dg/const-str-11.m with 86% similarity]
gcc/testsuite/objc.dg/torture/strings/const-str-3.m [moved from gcc/testsuite/objc.dg/const-str-3.m with 81% similarity]
gcc/testsuite/objc.dg/torture/strings/const-str-4.m [moved from gcc/testsuite/objc.dg/const-str-4.m with 84% similarity]
gcc/testsuite/objc.dg/torture/strings/const-str-7.m [moved from gcc/testsuite/objc.dg/const-str-7.m with 73% similarity]
gcc/testsuite/objc.dg/torture/strings/const-str-8.m [moved from gcc/testsuite/objc.dg/const-str-8.m with 73% similarity]
gcc/testsuite/objc.dg/torture/strings/const-str-9.m [moved from gcc/testsuite/objc.dg/const-str-9.m with 87% similarity]
gcc/testsuite/objc.dg/torture/strings/string1.m [new file with mode: 0644]
gcc/testsuite/objc.dg/torture/strings/string2.m [new file with mode: 0644]
gcc/testsuite/objc.dg/torture/strings/string3.m [new file with mode: 0644]
gcc/testsuite/objc.dg/torture/strings/string4.m [new file with mode: 0644]
gcc/testsuite/objc.dg/torture/strings/strings.exp [new file with mode: 0644]
gcc/testsuite/objc/execute/string1.m [deleted file]
gcc/testsuite/objc/execute/string2.m [deleted file]
gcc/testsuite/objc/execute/string3.m [deleted file]
gcc/testsuite/objc/execute/string4.m [deleted file]

index 99b0b75..b279dc3 100644 (file)
@@ -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.
index dbdeaa2..13263ae 100644 (file)
@@ -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
index 066b47b..54e8b2d 100644 (file)
@@ -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 (file)
index 0000000..14ae68c
--- /dev/null
@@ -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 (file)
index 0000000..13cb789
--- /dev/null
@@ -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
similarity index 81%
rename from gcc/testsuite/obj-c++.dg/const-str-1.mm
rename to gcc/testsuite/obj-c++.dg/strings/const-str-1.mm
index 156a92e..754c99b 100644 (file)
@@ -1,5 +1,6 @@
 /* Test errors for constant strings.  */
 /* { dg-do compile } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
 
 #ifdef __cplusplus
 extern void baz(...);
similarity index 75%
rename from gcc/testsuite/obj-c++.dg/const-str-12.mm
rename to gcc/testsuite/obj-c++.dg/strings/const-str-12.mm
index b92b50b..921d055 100644 (file)
@@ -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
similarity index 69%
rename from gcc/testsuite/obj-c++.dg/const-str-2.mm
rename to gcc/testsuite/obj-c++.dg/strings/const-str-2.mm
index c406665..e9e2fc9 100644 (file)
@@ -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 }
 
similarity index 84%
rename from gcc/testsuite/obj-c++.dg/const-str-5.mm
rename to gcc/testsuite/obj-c++.dg/strings/const-str-5.mm
index 479b4fd..8c12a0c 100644 (file)
@@ -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;
similarity index 85%
rename from gcc/testsuite/obj-c++.dg/const-str-6.mm
rename to gcc/testsuite/obj-c++.dg/strings/const-str-6.mm
index 3233083..69954d9 100644 (file)
@@ -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 (file)
index 0000000..82cd925
--- /dev/null
@@ -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
index fa1132d..4d96a47 100644 (file)
@@ -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 (file)
index 0000000..a11b526
--- /dev/null
@@ -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 (file)
index 0000000..4a61429
--- /dev/null
@@ -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 (file)
index 0000000..1155db5
--- /dev/null
@@ -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 } } } } } */
@@ -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
@@ -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
 }
 @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";
@@ -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"
+
@@ -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>
 
@@ -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"
@@ -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"
@@ -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 (file)
index 0000000..df315fb
--- /dev/null
@@ -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 (file)
index 0000000..180401c
--- /dev/null
@@ -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
index 1e9c515..e442223 100644 (file)
@@ -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
index b6cfe2c..55484d7 100644 (file)
@@ -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"
index f6d34f4..ae06d67 100644 (file)
@@ -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 (file)
index 0000000..14ae68c
--- /dev/null
@@ -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 (file)
index 0000000..13cb789
--- /dev/null
@@ -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
similarity index 81%
rename from gcc/testsuite/objc.dg/const-str-1.m
rename to gcc/testsuite/objc.dg/strings/const-str-1.m
index 156a92e..754c99b 100644 (file)
@@ -1,5 +1,6 @@
 /* Test errors for constant strings.  */
 /* { dg-do compile } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
 
 #ifdef __cplusplus
 extern void baz(...);
similarity index 74%
rename from gcc/testsuite/objc.dg/const-str-12b.m
rename to gcc/testsuite/objc.dg/strings/const-str-12b.m
index b92b50b..cad481e 100644 (file)
@@ -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;
similarity index 51%
rename from gcc/testsuite/objc.dg/const-str-2.m
rename to gcc/testsuite/objc.dg/strings/const-str-2.m
index c406665..49ab063 100644 (file)
@@ -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 }
 
similarity index 84%
rename from gcc/testsuite/objc.dg/const-str-5.m
rename to gcc/testsuite/objc.dg/strings/const-str-5.m
index 186edcf..4207176 100644 (file)
@@ -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;
similarity index 85%
rename from gcc/testsuite/objc.dg/const-str-6.m
rename to gcc/testsuite/objc.dg/strings/const-str-6.m
index a7cbbf7..fca7643 100644 (file)
@@ -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 (file)
index 0000000..823c287
--- /dev/null
@@ -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 (file)
index 0000000..a11b526
--- /dev/null
@@ -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 (file)
index 0000000..4a61429
--- /dev/null
@@ -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 (file)
index 0000000..1155db5
--- /dev/null
@@ -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 } } } } } */
similarity index 89%
rename from gcc/testsuite/objc.dg/const-str-10.m
rename to gcc/testsuite/objc.dg/torture/strings/const-str-10.m
index 7f59a63..c170f38 100644 (file)
@@ -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
similarity index 86%
rename from gcc/testsuite/objc.dg/const-str-11.m
rename to gcc/testsuite/objc.dg/torture/strings/const-str-11.m
index ae3c330..9f3705e 100644 (file)
@@ -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
similarity index 81%
rename from gcc/testsuite/objc.dg/const-str-3.m
rename to gcc/testsuite/objc.dg/torture/strings/const-str-3.m
index 26e7280..ca2df5a 100644 (file)
@@ -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"
similarity index 84%
rename from gcc/testsuite/objc.dg/const-str-4.m
rename to gcc/testsuite/objc.dg/torture/strings/const-str-4.m
index 9582a32..446b075 100644 (file)
@@ -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);
 
similarity index 73%
rename from gcc/testsuite/objc.dg/const-str-7.m
rename to gcc/testsuite/objc.dg/torture/strings/const-str-7.m
index 24c5dd3..7221e28 100644 (file)
@@ -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>
 - (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"
similarity index 73%
rename from gcc/testsuite/objc.dg/const-str-8.m
rename to gcc/testsuite/objc.dg/torture/strings/const-str-8.m
index a7da0e1..c5bacaf 100644 (file)
@@ -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 {
 }
 @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"
similarity index 87%
rename from gcc/testsuite/objc.dg/const-str-9.m
rename to gcc/testsuite/objc.dg/torture/strings/const-str-9.m
index 86521c2..ddbe93d 100644 (file)
@@ -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 (file)
index 0000000..76d3c9b
--- /dev/null
@@ -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 (file)
index 0000000..90e4db1
--- /dev/null
@@ -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 (file)
index 0000000..ca08fed
--- /dev/null
@@ -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 (file)
index 0000000..caa877e
--- /dev/null
@@ -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 (file)
index 0000000..e309186
--- /dev/null
@@ -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 (file)
index acc486a..0000000
+++ /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 (file)
index 32e7061..0000000
+++ /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 (file)
index 2595a09..0000000
+++ /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 (file)
index a7bcf43..0000000
+++ /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;
-}