From patchwork Tue Oct 19 08:51:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 68281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 86A40B6EF0 for ; Tue, 19 Oct 2010 19:52:00 +1100 (EST) Received: (qmail 10384 invoked by alias); 19 Oct 2010 08:51:57 -0000 Received: (qmail 10357 invoked by uid 22791); 19 Oct 2010 08:51:48 -0000 X-SWARE-Spam-Status: No, hits=-0.5 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_NONE, TW_BJ, TW_CP X-Spam-Check-By: sourceware.org Received: from c2beaomr10.btconnect.com (HELO mail.btconnect.com) (213.123.26.188) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 19 Oct 2010 08:51:32 +0000 Received: from host81-138-1-83.in-addr.btopenworld.com (EHLO thor.office) ([81.138.1.83]) by c2beaomr10.btconnect.com with ESMTP id AHY81812; Tue, 19 Oct 2010 09:51:26 +0100 (BST) Message-Id: <80303E3F-03FB-48C2-ABC1-75C9884BB785@sandoe-acoustics.co.uk> From: IainS To: GCC Patches Mime-Version: 1.0 (Apple Message framework v936) Subject: [Patch, Darwin, c*, ObjC* 2/2] Implement Darwin CFStrings. Date: Tue, 19 Oct 2010 09:51:22 +0100 Cc: Mike Stump , Nicola Pero X-Mirapoint-IP-Reputation: reputation=Fair-1, source=Queried, refid=tid=0001.0A0B0301.4CBD5C0A.01EC, actions=tag X-Junkmail-Signature-Raw: score=unknown, refid=str=0001.0A0B0209.4CBD5C0F.01EA, ss=1, fgs=0, ip=0.0.0.0, so=2010-07-22 22:03:31, dmn=2009-09-10 00:05:08, mode=single engine X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org since the facility defaults "on" for Darwin all the test-suite string tests (and a few others that use const strings) had to be changed. tedious - but I took the opportunity to update as I went. checked on {powerpc,i686}-darwin9, x86_64-darwin10, i686-darwin8, x86_64-unknown-linux, and a cross to cris-elf will apply once part 1 is approved. cheers Iain gcc/testsuite: * 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. Index: gcc/testsuite/lib/objc-dg.exp =================================================================== --- gcc/testsuite/lib/objc-dg.exp (revision 165662) +++ gcc/testsuite/lib/objc-dg.exp (working copy) @@ -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 + } } Index: gcc/testsuite/lib/obj-c++-dg.exp =================================================================== --- gcc/testsuite/lib/obj-c++-dg.exp (revision 165662) +++ gcc/testsuite/lib/obj-c++-dg.exp (working copy) @@ -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: gcc/testsuite/obj-c++.dg/template-4.mm =================================================================== --- gcc/testsuite/obj-c++.dg/template-4.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/template-4.mm (working copy) @@ -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 @@ -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" Index: gcc/testsuite/obj-c++.dg/const-str-7.mm =================================================================== --- gcc/testsuite/obj-c++.dg/const-str-7.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/const-str-7.mm (working copy) @@ -1,47 +0,0 @@ -/* Test to make sure that the const objc strings are the same across - scopes. */ -/* Developed by Andrew Pinski */ - -/* { dg-options "-fconstant-string-class=Foo" } */ -/* { dg-do run } */ -/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ - -#include "../objc-obj-c++-shared/Object1.h" -#include "../objc-obj-c++-shared/next-mapping.h" -#include -#include -#include -#include - -@interface Foo: Object { - char *cString; - unsigned int len; -} -- (char *)customString; -@end - -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _FooClassReference; -#else -struct objc_class _FooClassReference; -#endif - -@implementation Foo : Object -- (char *)customString { - return cString; -} -@end - - -int main () { - Foo *string = @"bla"; - { - Foo *string2 = @"bla"; - - if(string != string2) - abort(); - printf("Strings are being uniqued properly\n"); - } - return 0; -} -#include "../objc-obj-c++-shared/Object1-implementation.h" Index: gcc/testsuite/obj-c++.dg/const-str-12.mm =================================================================== --- gcc/testsuite/obj-c++.dg/const-str-12.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/const-str-12.mm (working copy) @@ -1,31 +0,0 @@ -/* Test if ObjC types play nice in conditional expressions. */ -/* Author: Ziemowit Laski */ - -/* { dg-options "-fconstant-string-class=Foo" } */ -/* { dg-do compile } */ - -#include "../objc-obj-c++-shared/Object1.h" -#import "../objc-obj-c++-shared/next-mapping.h" - -@interface Foo: Object { - char *cString; - unsigned int len; -} -+ (id)description; -@end - -@interface Bar: Object -+ (Foo *) getString: (int) which; -@end - -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _FooClassReference; -#else -struct objc_class _FooClassReference; -#endif - -@implementation Bar -+ (Foo *) getString: (int) which { - return which? [Foo description]: @"Hello"; -} -@end Index: gcc/testsuite/obj-c++.dg/const-str-2.mm =================================================================== --- gcc/testsuite/obj-c++.dg/const-str-2.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/const-str-2.mm (working copy) @@ -1,7 +0,0 @@ -/* Test the -fconstant-string-class flag error. */ -/* { dg-do compile } */ -/* { dg-options "-fconstant-string-class=" } */ - -{ dg-error "no class name specified|missing argument" "" { target *-*-* } 0 } - -void foo () {} Index: gcc/testsuite/obj-c++.dg/const-str-5.mm =================================================================== --- gcc/testsuite/obj-c++.dg/const-str-5.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/const-str-5.mm (working copy) @@ -1,27 +0,0 @@ -/* Positive test case for constant string layout. */ -/* Contributed by Ziemowit Laski . */ - -/* { dg-options "-fconstant-string-class=MyConstantString" } */ -/* { dg-do compile } */ - -@interface MyBase { - const char *p; -} -@end - -@interface MyConstantString: MyBase { - union equiv_u { - void *u; - unsigned char *c; - } _contents; - unsigned int _count; -} -@end - -/* The NeXT runtime initializes the 'isa' pointer of string constants at - compile time. */ -#ifdef __NEXT_RUNTIME__ -extern void *_MyConstantStringClassReference; -#endif - -MyConstantString *str = @"Hello"; Index: gcc/testsuite/obj-c++.dg/const-str-10.mm =================================================================== --- gcc/testsuite/obj-c++.dg/const-str-10.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/const-str-10.mm (working copy) @@ -1,33 +0,0 @@ -/* Test if ObjC constant string layout is checked properly, regardless of how - constant string classes get derived. */ -/* Contributed by Ziemowit Laski */ - -/* { dg-do compile } */ -/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */ - -#include "../objc-obj-c++-shared/Object1.h" - -@interface NSString: Object -@end - -@interface NSSimpleCString : NSString { -@protected - char *bytes; - unsigned int numBytes; -} -@end - -@interface NSConstantString : NSSimpleCString -@end - -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -Class _NSConstantStringClassReference; -#else -extern struct objc_class _NSConstantStringClassReference; -#endif - -const NSConstantString *appKey = @"MyApp"; - -/* { dg-final { scan-assembler ".section __OBJC, __cstring_object" } } */ -/* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" { target { *-*-darwin* && { ! lp64 } } } } } */ -/* { dg-final { scan-assembler ".quad\t__NSConstantStringClassReference\n\t.quad\t.*\n\t.long\t5\n\t.space 4\n\t.data" { target { *-*-darwin* && { lp64 } } } } } */ Index: gcc/testsuite/obj-c++.dg/torture/strings/string1.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/string1.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/torture/strings/string1.mm (revision 0) @@ -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 +#include + +#ifndef __NEXT_RUNTIME__ +#include +#endif + +int main(int argc, char **args) +{ + if (strcmp ([@"this is a string" cString], "this is a string")) + abort (); + return 0; +} Index: gcc/testsuite/obj-c++.dg/torture/strings/const-str-10.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/const-str-10.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/torture/strings/const-str-10.mm (working copy) @@ -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 Index: gcc/testsuite/obj-c++.dg/torture/strings/const-str-11.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/const-str-11.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/torture/strings/const-str-11.mm (working copy) @@ -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 +#ifdef NEXT_OBJC_USE_NEW_INTERFACE +extern Class _XStrClassReference; +#else extern struct objc_class _XStrClassReference; -#else -extern Class _XStrClassReference; #endif const XStr *appKey = @"MyApp"; Index: gcc/testsuite/obj-c++.dg/torture/strings/strings.exp =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/strings.exp (revision 0) +++ gcc/testsuite/obj-c++.dg/torture/strings/strings.exp (revision 0) @@ -0,0 +1,34 @@ +# This harness is for tests that should be run at all optimisation 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 +# . + +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: gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm (working copy) @@ -2,12 +2,14 @@ runtime. */ /* Developed by Markus Hitter . */ -/* { 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 #include #include @@ -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" + Index: gcc/testsuite/obj-c++.dg/torture/strings/const-str-4.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/const-str-4.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/torture/strings/const-str-4.mm (working copy) @@ -1,7 +1,9 @@ /* Ensure that the preprocessor handles ObjC string constants gracefully. */ /* Author: Ziemowit Laski */ + +/* { dg-do run { target *-*-darwin* } } */ /* { dg-options "-fconstant-string-class=MyString" } */ -/* { dg-do run { target *-*-darwin* } } */ +/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyString" { target *-*-darwin* } } */ #include Index: gcc/testsuite/obj-c++.dg/torture/strings/const-str-7.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/const-str-7.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/torture/strings/const-str-7.mm (working copy) @@ -2,12 +2,12 @@ scopes. */ /* Developed by Andrew Pinski */ -/* { 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 #include #include @@ -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" Index: gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-1.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-1.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-1.mm (revision 0) @@ -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 . */ + +/* 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 +#import +#include + +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; +} Index: gcc/testsuite/obj-c++.dg/torture/strings/const-str-8.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/const-str-8.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/torture/strings/const-str-8.mm (working copy) @@ -1,10 +1,12 @@ /* Test for assigning compile-time constant-string objects to static variables. */ /* Contributed by Ziemowit Laski */ +/* { dg-do run { target *-*-darwin* } } */ /* { dg-options "-fconstant-string-class=Foo" } */ -/* { dg-do run { target *-*-darwin* } } */ +/* { 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 @interface Foo: Object { @@ -40,5 +42,3 @@ int main () { PrefsSynchronize(); return 0; } - -#include "../objc-obj-c++-shared/Object1-implementation.h" Index: gcc/testsuite/obj-c++.dg/torture/strings/const-str-9.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/const-str-9.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/torture/strings/const-str-9.mm (working copy) @@ -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; Index: gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-3.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-3.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-3.mm (revision 0) @@ -0,0 +1,27 @@ +/* Test for assigning compile-time constant-string objects to static variables. */ +/* Contributed by Ziemowit Laski */ + +/* 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 + +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; +} Index: gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-4.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-4.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/torture/strings/const-cfstring-4.mm (revision 0) @@ -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 */ + +/* 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 } } } } } */ Index: gcc/testsuite/obj-c++.dg/const-str-8.mm =================================================================== --- gcc/testsuite/obj-c++.dg/const-str-8.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/const-str-8.mm (working copy) @@ -1,44 +0,0 @@ -/* Test for assigning compile-time constant-string objects to static variables. */ -/* Contributed by Ziemowit Laski */ - -/* { dg-options "-fconstant-string-class=Foo" } */ -/* { dg-do run { target *-*-darwin* } } */ - -#include "../objc-obj-c++-shared/Object1.h" -#include - -@interface Foo: Object { - char *cString; - unsigned int len; -} -@end - -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -Class _FooClassReference; -#else -struct objc_class _FooClassReference; -#endif - -@implementation Foo : Object -- (char *)customString { - return cString; -} -@end - -static const Foo *appKey = @"MyApp"; -static int CFPreferencesSynchronize (const Foo *ref) { - return ref == appKey; -} - -static void PrefsSynchronize(void) -{ - if(!CFPreferencesSynchronize(appKey)) - abort(); -} - -int main () { - PrefsSynchronize(); - return 0; -} - -#include "../objc-obj-c++-shared/Object1-implementation.h" Index: gcc/testsuite/obj-c++.dg/strings/const-str-1.mm =================================================================== --- gcc/testsuite/obj-c++.dg/strings/const-str-1.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/strings/const-str-1.mm (working copy) @@ -1,5 +1,6 @@ /* Test errors for constant strings. */ /* { dg-do compile } */ +/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ #ifdef __cplusplus extern void baz(...); Index: gcc/testsuite/obj-c++.dg/strings/const-str-2.mm =================================================================== --- gcc/testsuite/obj-c++.dg/strings/const-str-2.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/strings/const-str-2.mm (working copy) @@ -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 } Index: gcc/testsuite/obj-c++.dg/strings/strings.exp =================================================================== --- gcc/testsuite/obj-c++.dg/strings/strings.exp (revision 0) +++ gcc/testsuite/obj-c++.dg/strings/strings.exp (revision 0) @@ -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 +# . + +# 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: gcc/testsuite/obj-c++.dg/strings/const-str-12.mm =================================================================== --- gcc/testsuite/obj-c++.dg/strings/const-str-12.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/strings/const-str-12.mm (working copy) @@ -1,11 +1,11 @@ /* Test if ObjC types play nice in conditional expressions. */ /* Author: Ziemowit Laski */ +/* { dg-do compile } */ /* { dg-options "-fconstant-string-class=Foo" } */ -/* { dg-do compile } */ +/* { 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 Index: gcc/testsuite/obj-c++.dg/strings/const-str-5.mm =================================================================== --- gcc/testsuite/obj-c++.dg/strings/const-str-5.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/strings/const-str-5.mm (working copy) @@ -1,8 +1,9 @@ /* Positive test case for constant string layout. */ /* Contributed by Ziemowit Laski . */ +/* { dg-do compile } */ /* { dg-options "-fconstant-string-class=MyConstantString" } */ -/* { dg-do compile } */ +/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyConstantString" { target *-*-darwin* } } */ @interface MyBase { const char *p; Index: gcc/testsuite/obj-c++.dg/strings/const-str-6.mm =================================================================== --- gcc/testsuite/obj-c++.dg/strings/const-str-6.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/strings/const-str-6.mm (working copy) @@ -1,8 +1,9 @@ /* Negative test case for constant string layout. */ /* Contributed by Ziemowit Laski . */ +/* { dg-do compile } */ /* { dg-options "-fconstant-string-class=MyConstantString" } */ -/* { dg-do compile } */ +/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyConstantString" { target *-*-darwin* } } */ @interface MyBase { char p; Index: gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm =================================================================== --- gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm (revision 0) @@ -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 . */ + +/* 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 +#import + +#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" } */ +} Index: gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm =================================================================== --- gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm (revision 0) @@ -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 + +@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 Index: gcc/testsuite/obj-c++.dg/const-str-3.mm =================================================================== --- gcc/testsuite/obj-c++.dg/const-str-3.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/const-str-3.mm (working copy) @@ -1,58 +0,0 @@ -/* Test the -fconstant-string-class=Foo option under the NeXT - runtime. */ -/* Developed by Markus Hitter . */ - -/* { dg-options "-fconstant-string-class=Foo" } */ -/* { dg-do run { target *-*-darwin* } } */ -/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ - -#import "../objc-obj-c++-shared/Object1.h" -#import "../objc-obj-c++-shared/next-mapping.h" -#include -#include -#include -#include -#ifndef __NEXT_RUNTIME__ -#include -#endif - -@interface Foo: Object { - char *cString; - unsigned int len; -} -- (char *)customString; -@end - -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _FooClassReference; -#else -struct objc_class _FooClassReference; -#endif - -@implementation Foo : Object -- (char *)customString { - return cString; -} -@end - -int main () { - Foo *string = @"bla"; - Foo *string2 = @"bla"; - - if(string != string2) - abort(); - printf("Strings are being uniqued properly\n"); - - /* This memcpy has to be done before the first message is sent to a - constant string object. Can't be moved to +initialize since _that_ - is already a message. */ - - memcpy(&_FooClassReference, objc_get_class("Foo"), sizeof(_FooClassReference)); - if (strcmp ([string customString], "bla")) { - abort (); - } - - printf([@"This is a working constant string object\n" customString]); - return 0; -} -#include "../objc-obj-c++-shared/Object1-implementation.h" Index: gcc/testsuite/obj-c++.dg/const-str-6.mm =================================================================== --- gcc/testsuite/obj-c++.dg/const-str-6.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/const-str-6.mm (working copy) @@ -1,27 +0,0 @@ -/* Negative test case for constant string layout. */ -/* Contributed by Ziemowit Laski . */ - -/* { dg-options "-fconstant-string-class=MyConstantString" } */ -/* { dg-do compile } */ - -@interface MyBase { - char p; -} -@end - -@interface MyConstantString: MyBase { - union equiv_u { - void *u; - unsigned char *c; - } _contents; - char _count; -} -@end - -/* The NeXT runtime initializes the 'isa' pointer of string constants at - compile time. */ -#ifdef __NEXT_RUNTIME__ -extern void *_MyConstantStringClassReference; -#endif - -MyConstantString *str = @"Hello"; /* { dg-error "interface .MyConstantString. does not have valid constant string layout" } */ Index: gcc/testsuite/obj-c++.dg/const-str-11.mm =================================================================== --- gcc/testsuite/obj-c++.dg/const-str-11.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/const-str-11.mm (working copy) @@ -1,33 +0,0 @@ -/* Test if ObjC constant string layout is checked properly, regardless of how - constant string classes get derived. */ -/* Contributed by Ziemowit Laski */ - -/* { dg-do compile } */ -/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */ -/* { dg-options "-fconstant-string-class=XStr" } */ - -#include "../objc-obj-c++-shared/Object1.h" - -@interface XString: Object { -@protected - char *bytes; -} -@end - -@interface XStr : XString { -@public - unsigned int len; -} -@end - -#ifndef NEXT_OBJC_USE_NEW_INTERFACE -extern struct objc_class _XStrClassReference; -#else -extern Class _XStrClassReference; -#endif - -const XStr *appKey = @"MyApp"; - -/* { dg-final { scan-assembler ".section __OBJC, __cstring_object" } } */ -/* { dg-final { scan-assembler ".long\t__XStrClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" { target { *-*-darwin* && { ! lp64 } } } } } */ -/* { dg-final { scan-assembler ".quad\t__XStrClassReference\n\t.quad\t.*\n\t.long\t5\n\t.space 4\n\t.data" { target { *-*-darwin* && { lp64 } } } } } */ Index: gcc/testsuite/obj-c++.dg/const-str-1.mm =================================================================== --- gcc/testsuite/obj-c++.dg/const-str-1.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/const-str-1.mm (working copy) @@ -1,24 +0,0 @@ -/* Test errors for constant strings. */ -/* { dg-do compile } */ - -#ifdef __cplusplus -extern void baz(...); -#endif - -void foo() -{ - baz(@"hiya"); /* { dg-error "annot find interface declaration" } */ -} - -@interface NXConstantString -{ - void *isa; - char *str; - int len; -} -@end - -void bar() -{ - baz(@"howdah"); -} Index: gcc/testsuite/obj-c++.dg/const-str-9.mm =================================================================== --- gcc/testsuite/obj-c++.dg/const-str-9.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/const-str-9.mm (working copy) @@ -1,25 +0,0 @@ -/* Test if ObjC constant strings get placed in the correct section. */ -/* Contributed by Ziemowit Laski */ - -/* { dg-do compile } */ -/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */ - -#include "../objc-obj-c++-shared/Object1.h" - -@interface NSConstantString: Object { - char *cString; - unsigned int len; -} -@end - -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -Class _NSConstantStringClassReference; -#else -extern struct objc_class _NSConstantStringClassReference; -#endif - -const NSConstantString *appKey = @"MyApp"; - -/* { dg-final { scan-assembler ".section __OBJC, __cstring_object" } } */ -/* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" { target { *-*-darwin* && { ! lp64 } } }} } */ -/* { dg-final { scan-assembler ".quad\t__NSConstantStringClassReference\n\t.quad\t.*\n\t.long\t5\n\t.space 4\n\t.data" { target { *-*-darwin* && { lp64 } } } } } */ Index: gcc/testsuite/obj-c++.dg/const-str-4.mm =================================================================== --- gcc/testsuite/obj-c++.dg/const-str-4.mm (revision 165662) +++ gcc/testsuite/obj-c++.dg/const-str-4.mm (working copy) @@ -1,31 +0,0 @@ -/* Ensure that the preprocessor handles ObjC string constants gracefully. */ -/* Author: Ziemowit Laski */ -/* { dg-options "-fconstant-string-class=MyString" } */ -/* { dg-do run { target *-*-darwin* } } */ - -#include - -@interface MyString -{ - void *isa; - char *str; - int len; -} -@end - -#define kMyStringMacro1 "My String" -#define kMyStringMacro2 @"My String" - -void *_MyStringClassReference; - -@implementation MyString -@end - -int main(void) { - MyString* aString1 = @kMyStringMacro1; - MyString* aString2 = kMyStringMacro2; - if(aString1 != aString2) { - abort(); - } - return 0; -} Index: gcc/testsuite/objc/execute/string1.m =================================================================== --- gcc/testsuite/objc/execute/string1.m (revision 165662) +++ gcc/testsuite/objc/execute/string1.m (working copy) @@ -1,16 +0,0 @@ -/* Based on a test case contributed by Nicola Pero. */ - -#import "../../objc-obj-c++-shared/next-mapping.h" -#include -#include - -#ifndef __NEXT_RUNTIME__ -#include -#endif - -int main(int argc, void **args) -{ - if (strcmp ([@"this is a string" cString], "this is a string")) - abort (); - return 0; -} Index: gcc/testsuite/objc/execute/string3.m =================================================================== --- gcc/testsuite/objc/execute/string3.m (revision 165662) +++ gcc/testsuite/objc/execute/string3.m (working copy) @@ -1,18 +0,0 @@ -/* Based on a test case contributed by Nicola Pero. */ - -#import "../../objc-obj-c++-shared/next-mapping.h" -#include -#include - -#ifndef __NEXT_RUNTIME__ -#include -#endif - -#define STRING "this is a string" - -int main (int argc, void **args) -{ - if (strcmp ([@STRING cString], STRING)) - abort (); - return 0; -} Index: gcc/testsuite/objc/execute/string2.m =================================================================== --- gcc/testsuite/objc/execute/string2.m (revision 165662) +++ gcc/testsuite/objc/execute/string2.m (working copy) @@ -1,17 +0,0 @@ -/* Based on a test case contributed by Nicola Pero. */ - -#import "../../objc-obj-c++-shared/next-mapping.h" -#include -#include - -#ifndef __NEXT_RUNTIME__ -#include -#endif - -int main(int argc, void **args) -{ - if (strcmp ([@"this " @"is " @"a " @"string" cString], - "this " "is " "a " "string")) - abort (); - return 0; -} Index: gcc/testsuite/objc/execute/string4.m =================================================================== --- gcc/testsuite/objc/execute/string4.m (revision 165662) +++ gcc/testsuite/objc/execute/string4.m (working copy) @@ -1,16 +0,0 @@ -/* Based on a test case contributed by Nicola Pero. */ - -#import "../../objc-obj-c++-shared/next-mapping.h" -#include -#include - -#ifndef __NEXT_RUNTIME__ -#include -#endif - -int main(int argc, void **args) -{ - if ([@"this is a string" length] != strlen ("this is a string")) - abort (); - return 0; -} Index: gcc/testsuite/objc.dg/foreach-5.m =================================================================== --- gcc/testsuite/objc.dg/foreach-5.m (revision 165662) +++ gcc/testsuite/objc.dg/foreach-5.m (working copy) @@ -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: gcc/testsuite/objc.dg/const-str-3.m =================================================================== --- gcc/testsuite/objc.dg/const-str-3.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-3.m (working copy) @@ -1,53 +0,0 @@ -/* Test the -fconstant-string-class=Foo option under the NeXT runtime. */ -/* Developed by Markus Hitter . */ -/* { dg-do run } */ -/* { dg-options "-fconstant-string-class=Foo" } */ -/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ - -#import "../objc-obj-c++-shared/Object1.h" -#import "../objc-obj-c++-shared/next-mapping.h" -#include -#include -#include - -@interface Foo: Object { - char *cString; - unsigned int len; -} -- (char *)customString; -@end - -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _FooClassReference; -#else -struct objc_class _FooClassReference; -#endif - -@implementation Foo : Object -- (char *)customString { - return cString; -} -@end - -int main () { - Foo *string = @"bla"; - Foo *string2 = @"bla"; - - if(string != string2) - abort(); - printf("Strings are being uniqued properly\n"); - - /* This memcpy has to be done before the first message is sent to a - constant string object. Can't be moved to +initialize since _that_ - is already a message. */ - - memcpy(&_FooClassReference, objc_get_class("Foo"), sizeof(_FooClassReference)); - if (strcmp ([string customString], "bla")) { - abort (); - } - - printf([@"This is a working constant string object\n" customString]); - return 0; -} - -#include "../objc-obj-c++-shared/Object1-implementation.h" Index: gcc/testsuite/objc.dg/const-str-7.m =================================================================== --- gcc/testsuite/objc.dg/const-str-7.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-7.m (working copy) @@ -1,42 +0,0 @@ -/* Test to make sure that the const objc strings are the same across scopes. */ -/* Developed by Andrew Pinski */ -/* { dg-options "-fconstant-string-class=Foo " } */ -/* { dg-do run } */ - -#include "../objc-obj-c++-shared/Object1.h" -#include -#include -#include - -@interface Foo: Object { - char *cString; - unsigned int len; -} -- (char *)customString; -@end - -#ifndef NEXT_OBJC_USE_NEW_INTERFACE -struct objc_class _FooClassReference; -#else -Class _FooClassReference; -#endif - -@implementation Foo : Object -- (char *)customString { - return cString; -} -@end - -int main () { - Foo *string = @"bla"; - { - Foo *string2 = @"bla"; - - if(string != string2) - abort(); - printf("Strings are being uniqued properly\n"); - } - return 0; -} - -#include "../objc-obj-c++-shared/Object1-implementation.h" Index: gcc/testsuite/objc.dg/const-str-10.m =================================================================== --- gcc/testsuite/objc.dg/const-str-10.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-10.m (working copy) @@ -1,33 +0,0 @@ -/* Test if ObjC constant string layout is checked properly, regardless of how - constant string classes get derived. */ -/* Contributed by Ziemowit Laski */ - -/* { dg-do compile { target { *-*-darwin* } } } */ -/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */ - -#include "../objc-obj-c++-shared/Object1.h" - -@interface NSString: Object -@end - -@interface NSSimpleCString : NSString { -@protected - char *bytes; - unsigned int numBytes; -} -@end - -@interface NSConstantString : NSSimpleCString -@end - -#ifndef NEXT_OBJC_USE_NEW_INTERFACE -extern struct objc_class _NSConstantStringClassReference; -#else -extern Class _NSConstantStringClassReference; -#endif - -const NSConstantString *appKey = @"MyApp"; - -/* { dg-final { scan-assembler ".section __OBJC, __cstring_object" } } */ -/* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" { target { *-*-darwin* && { ! lp64 } } } } } */ -/* { dg-final { scan-assembler ".quad\t__NSConstantStringClassReference\n\t.quad\t.*\n\t.long\t5\n\t.space" { target { *-*-darwin* && { lp64 } } } } } */ Index: gcc/testsuite/objc.dg/const-str-12b.m =================================================================== --- gcc/testsuite/objc.dg/const-str-12b.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-12b.m (working copy) @@ -1,31 +0,0 @@ -/* Test if ObjC types play nice in conditional expressions. */ -/* Author: Ziemowit Laski */ - -/* { dg-options "-fconstant-string-class=Foo" } */ -/* { dg-do compile } */ - -#include "../objc-obj-c++-shared/Object1.h" -#import "../objc-obj-c++-shared/next-mapping.h" - -@interface Foo: Object { - char *cString; - unsigned int len; -} -+ (id)description; -@end - -@interface Bar: Object -+ (Foo *) getString: (int) which; -@end - -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _FooClassReference; -#else -struct objc_class _FooClassReference; -#endif - -@implementation Bar -+ (Foo *) getString: (int) which { - return which? [Foo description]: @"Hello"; -} -@end Index: gcc/testsuite/objc.dg/foreach-2.m =================================================================== --- gcc/testsuite/objc.dg/foreach-2.m (revision 165662) +++ gcc/testsuite/objc.dg/foreach-2.m (working copy) @@ -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 #endif Index: gcc/testsuite/objc.dg/const-str-4.m =================================================================== --- gcc/testsuite/objc.dg/const-str-4.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-4.m (working copy) @@ -1,31 +0,0 @@ -/* Ensure that the preprocessor handles ObjC string constants gracefully. */ -/* Author: Ziemowit Laski */ -/* { dg-options "-fconstant-string-class=MyString " } */ -/* { dg-do run } */ - -extern void abort(void); - -@interface MyString -{ - void *isa; - char *str; - int len; -} -@end - -#define kMyStringMacro1 "My String" -#define kMyStringMacro2 @"My String" - -void *_MyStringClassReference; - -@implementation MyString -@end - -int main(void) { - MyString* aString1 = @kMyStringMacro1; - MyString* aString2 = kMyStringMacro2; - if(aString1 != aString2) { - abort(); - } - return 0; -} Index: gcc/testsuite/objc.dg/const-str-8.m =================================================================== --- gcc/testsuite/objc.dg/const-str-8.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-8.m (working copy) @@ -1,43 +0,0 @@ -/* Test for assigning compile-time constant-string objects to static variables. */ -/* Contributed by Ziemowit Laski */ -/* { dg-options "-fconstant-string-class=Foo" } */ -/* { dg-do run } */ - -#include "../objc-obj-c++-shared/Object1.h" -#include - -@interface Foo: Object { - char *cString; - unsigned int len; -} -@end - -#ifndef NEXT_OBJC_USE_NEW_INTERFACE -struct objc_class _FooClassReference; -#else -Class _FooClassReference; -#endif - -@implementation Foo : Object -- (char *)customString { - return cString; -} -@end - -static const Foo *appKey = @"MyApp"; -static int CFPreferencesSynchronize (const Foo *ref) { - return ref == appKey; -} - -static void PrefsSynchronize(void) -{ - if(!CFPreferencesSynchronize(appKey)) - abort(); -} - -int main () { - PrefsSynchronize(); - return 0; -} - -#include "../objc-obj-c++-shared/Object1-implementation.h" Index: gcc/testsuite/objc.dg/torture/strings/string1.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/string1.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/string1.m (revision 0) @@ -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 +#include + +#ifndef __NEXT_RUNTIME__ +#include +#endif + +int main(int argc, void **args) +{ + if (strcmp ([@"this is a string" cString], "this is a string")) + abort (); + return 0; +} Index: gcc/testsuite/objc.dg/torture/strings/string2.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/string2.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/string2.m (revision 0) @@ -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 +#include + +#ifndef __NEXT_RUNTIME__ +#include +#endif + +int main(int argc, void **args) +{ + if (strcmp ([@"this " @"is " @"a " @"string" cString], + "this " "is " "a " "string")) + abort (); + return 0; +} Index: gcc/testsuite/objc.dg/torture/strings/string3.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/string3.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/string3.m (revision 0) @@ -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 +#include + +#ifndef __NEXT_RUNTIME__ +#include +#endif + +#define STRING "this is a string" + +int main (int argc, void **args) +{ + if (strcmp ([@STRING cString], STRING)) + abort (); + return 0; +} Index: gcc/testsuite/objc.dg/torture/strings/strings.exp =================================================================== --- gcc/testsuite/objc.dg/torture/strings/strings.exp (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/strings.exp (revision 0) @@ -0,0 +1,34 @@ +# String tests that should be run at all optimisation 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 +# . + +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 Index: gcc/testsuite/objc.dg/torture/strings/string4.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/string4.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/string4.m (revision 0) @@ -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 +#include + +#ifndef __NEXT_RUNTIME__ +#include +#endif + +int main(int argc, void **args) +{ + if ([@"this is a string" length] != strlen ("this is a string")) + abort (); + return 0; +} Index: gcc/testsuite/objc.dg/torture/strings/const-str-3.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/const-str-3.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/const-str-3.m (working copy) @@ -1,11 +1,13 @@ /* Test the -fconstant-string-class=Foo option under the NeXT runtime. */ /* Developed by Markus Hitter . */ /* { dg-do run } */ +/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ /* { dg-options "-fconstant-string-class=Foo" } */ -/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ +/* { 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 #include #include @@ -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" Index: gcc/testsuite/objc.dg/torture/strings/const-str-4.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/const-str-4.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/const-str-4.m (working copy) @@ -1,7 +1,8 @@ /* Ensure that the preprocessor handles ObjC string constants gracefully. */ /* Author: Ziemowit Laski */ +/* { dg-do run } */ /* { dg-options "-fconstant-string-class=MyString " } */ -/* { dg-do run } */ +/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyString " { target *-*-darwin* } } */ extern void abort(void); Index: gcc/testsuite/objc.dg/torture/strings/const-str-7.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/const-str-7.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/const-str-7.m (working copy) @@ -1,9 +1,11 @@ /* Test to make sure that the const objc strings are the same across scopes. */ /* Developed by Andrew Pinski */ +/* { dg-do run } */ /* { dg-options "-fconstant-string-class=Foo " } */ -/* { dg-do run } */ +/* { 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 #include #include @@ -15,10 +17,10 @@ - (char *)customString; @end -#ifndef NEXT_OBJC_USE_NEW_INTERFACE +#ifdef NEXT_OBJC_USE_NEW_INTERFACE +Class _FooClassReference; +#else struct objc_class _FooClassReference; -#else -Class _FooClassReference; #endif @implementation Foo : Object @@ -38,5 +40,3 @@ int main () { } return 0; } - -#include "../objc-obj-c++-shared/Object1-implementation.h" Index: gcc/testsuite/objc.dg/torture/strings/const-cfstring-1.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/const-cfstring-1.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/const-cfstring-1.m (revision 0) @@ -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 . */ + +/* 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 +#import +#include + +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; +} Index: gcc/testsuite/objc.dg/torture/strings/const-str-8.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/const-str-8.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/const-str-8.m (working copy) @@ -1,9 +1,11 @@ /* Test for assigning compile-time constant-string objects to static variables. */ /* Contributed by Ziemowit Laski */ +/* { dg-do run } */ /* { dg-options "-fconstant-string-class=Foo" } */ -/* { dg-do run } */ +/* { 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 @interface Foo: Object { @@ -12,10 +14,10 @@ } @end -#ifndef NEXT_OBJC_USE_NEW_INTERFACE +#ifdef NEXT_OBJC_USE_NEW_INTERFACE +Class _FooClassReference; +#else struct objc_class _FooClassReference; -#else -Class _FooClassReference; #endif @implementation Foo : Object @@ -39,5 +41,3 @@ int main () { PrefsSynchronize(); return 0; } - -#include "../objc-obj-c++-shared/Object1-implementation.h" Index: gcc/testsuite/objc.dg/torture/strings/const-str-9.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/const-str-9.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/const-str-9.m (working copy) @@ -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; Index: gcc/testsuite/objc.dg/torture/strings/const-cfstring-3.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/const-cfstring-3.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/const-cfstring-3.m (revision 0) @@ -0,0 +1,27 @@ +/* Test for assigning compile-time constant-string objects to static variables. */ +/* Contributed by Ziemowit Laski */ + +/* 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 + +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; +} Index: gcc/testsuite/objc.dg/torture/strings/const-cfstring-4.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/const-cfstring-4.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/const-cfstring-4.m (revision 0) @@ -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 */ + +/* 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 } } } } } */ Index: gcc/testsuite/objc.dg/torture/strings/const-str-10.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/const-str-10.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/const-str-10.m (working copy) @@ -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 Index: gcc/testsuite/objc.dg/torture/strings/const-str-11.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/const-str-11.m (revision 0) +++ gcc/testsuite/objc.dg/torture/strings/const-str-11.m (working copy) @@ -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 Index: gcc/testsuite/objc.dg/const-str-11.m =================================================================== --- gcc/testsuite/objc.dg/const-str-11.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-11.m (working copy) @@ -1,33 +0,0 @@ -/* Test if ObjC constant string layout is checked properly, regardless of how - constant string classes get derived. */ -/* Contributed by Ziemowit Laski */ - -/* { dg-do compile { target *-*-darwin* } } */ -/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */ -/* { dg-options "-fconstant-string-class=XStr" } */ - -#include "../objc-obj-c++-shared/Object1.h" - -@interface XString: Object { -@protected - char *bytes; -} -@end - -@interface XStr : XString { -@public - unsigned int len; -} -@end - -#ifndef NEXT_OBJC_USE_NEW_INTERFACE -extern struct objc_class _XStrClassReference; -#else -extern Class _XStrClassReference; -#endif - -const XStr *appKey = @"MyApp"; - -/* { dg-final { scan-assembler ".section __OBJC, __cstring_object" } } */ -/* { dg-final { scan-assembler ".long\t__XStrClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" { target { *-*-darwin* && { ! lp64 } } } } } */ -/* { dg-final { scan-assembler ".quad\t__XStrClassReference\n\t.quad\t.*\n\t.long\t5\n\t.space" { target { *-*-darwin* && { lp64 } } } } } */ Index: gcc/testsuite/objc.dg/strings/const-cfstring-5.m =================================================================== --- gcc/testsuite/objc.dg/strings/const-cfstring-5.m (revision 0) +++ gcc/testsuite/objc.dg/strings/const-cfstring-5.m (revision 0) @@ -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 + +@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 Index: gcc/testsuite/objc.dg/strings/strings.exp =================================================================== --- gcc/testsuite/objc.dg/strings/strings.exp (revision 0) +++ gcc/testsuite/objc.dg/strings/strings.exp (revision 0) @@ -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 +# . + +# 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 Index: gcc/testsuite/objc.dg/strings/const-str-1.m =================================================================== --- gcc/testsuite/objc.dg/strings/const-str-1.m (revision 0) +++ gcc/testsuite/objc.dg/strings/const-str-1.m (working copy) @@ -1,5 +1,6 @@ /* Test errors for constant strings. */ /* { dg-do compile } */ +/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ #ifdef __cplusplus extern void baz(...); Index: gcc/testsuite/objc.dg/strings/const-str-2.m =================================================================== --- gcc/testsuite/objc.dg/strings/const-str-2.m (revision 0) +++ gcc/testsuite/objc.dg/strings/const-str-2.m (working copy) @@ -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 } Index: gcc/testsuite/objc.dg/strings/const-str-5.m =================================================================== --- gcc/testsuite/objc.dg/strings/const-str-5.m (revision 0) +++ gcc/testsuite/objc.dg/strings/const-str-5.m (working copy) @@ -1,8 +1,9 @@ /* Positive test case for constant string layout. */ /* Contributed by Ziemowit Laski . */ +/* { dg-do compile } */ /* { dg-options "-fconstant-string-class=MyConstantString" } */ -/* { dg-do compile } */ +/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyConstantString" { target *-*-darwin* } } */ @interface MyBase { const char *p; Index: gcc/testsuite/objc.dg/strings/const-str-12b.m =================================================================== --- gcc/testsuite/objc.dg/strings/const-str-12b.m (revision 0) +++ gcc/testsuite/objc.dg/strings/const-str-12b.m (working copy) @@ -1,11 +1,12 @@ /* Test if ObjC types play nice in conditional expressions. */ /* Author: Ziemowit Laski */ +/* { dg-do compile } */ /* { dg-options "-fconstant-string-class=Foo" } */ -/* { dg-do compile } */ +/* { 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; Index: gcc/testsuite/objc.dg/strings/const-str-6.m =================================================================== --- gcc/testsuite/objc.dg/strings/const-str-6.m (revision 0) +++ gcc/testsuite/objc.dg/strings/const-str-6.m (working copy) @@ -1,8 +1,9 @@ /* Negative test case for constant string layout. */ /* Contributed by Ziemowit Laski . */ +/* { dg-do compile } */ /* { dg-options "-fconstant-string-class=MyConstantString" } */ -/* { dg-do compile } */ +/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyConstantString" { target *-*-darwin* } } */ @interface MyBase { char p; Index: gcc/testsuite/objc.dg/strings/const-cfstring-2.m =================================================================== --- gcc/testsuite/objc.dg/strings/const-cfstring-2.m (revision 0) +++ gcc/testsuite/objc.dg/strings/const-cfstring-2.m (revision 0) @@ -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 . */ + +/* 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 +#import + +#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" } */ +} Index: gcc/testsuite/objc.dg/const-str-1.m =================================================================== --- gcc/testsuite/objc.dg/const-str-1.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-1.m (working copy) @@ -1,24 +0,0 @@ -/* Test errors for constant strings. */ -/* { dg-do compile } */ - -#ifdef __cplusplus -extern void baz(...); -#endif - -void foo() -{ - baz(@"hiya"); /* { dg-error "annot find interface declaration" } */ -} - -@interface NXConstantString -{ - void *isa; - char *str; - int len; -} -@end - -void bar() -{ - baz(@"howdah"); -} Index: gcc/testsuite/objc.dg/const-str-5.m =================================================================== --- gcc/testsuite/objc.dg/const-str-5.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-5.m (working copy) @@ -1,27 +0,0 @@ -/* Positive test case for constant string layout. */ -/* Contributed by Ziemowit Laski . */ - -/* { dg-options "-fconstant-string-class=MyConstantString" } */ -/* { dg-do compile } */ - -@interface MyBase { - const char *p; -} -@end - -@interface MyConstantString: MyBase { - union { - void *u; - unsigned char *c; - } _contents; - unsigned int _count; -} -@end - -/* The NeXT runtime initializes the 'isa' pointer of string constants at - compile time. */ -#ifdef __NEXT_RUNTIME__ -extern void *_MyConstantStringClassReference; -#endif - -MyConstantString *str = @"Hello"; Index: gcc/testsuite/objc.dg/const-str-9.m =================================================================== --- gcc/testsuite/objc.dg/const-str-9.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-9.m (working copy) @@ -1,25 +0,0 @@ -/* Test if ObjC constant strings get placed in the correct section. */ -/* Contributed by Ziemowit Laski */ - -/* { dg-do compile } */ -/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */ - -#include "../objc-obj-c++-shared/Object1.h" - -@interface NSConstantString: Object { - char *cString; - unsigned int len; -} -@end - -#ifndef NEXT_OBJC_USE_NEW_INTERFACE -extern struct objc_class _NSConstantStringClassReference; -#else -Class _NSConstantStringClassReference; -#endif - -const NSConstantString *appKey = @"MyApp"; - -/* { dg-final { scan-assembler ".section __OBJC, __cstring_object" } } */ -/* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" { target { *-*-darwin* && { ! lp64 } } } } } */ -/* { dg-final { scan-assembler ".quad\t__NSConstantStringClassReference\n\t.quad\t.*\n\t.long\t5\n\t.space" { target { *-*-darwin* && { lp64 } } } } } */ Index: gcc/testsuite/objc.dg/const-str-12.m =================================================================== --- gcc/testsuite/objc.dg/const-str-12.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-12.m (working copy) @@ -1,16 +0,0 @@ -/* { dg-options "-Wall -funit-at-a-time" } */ -/* { dg-do compile } */ -/* PR objc/27438, make sure that the decl produced by the front-end - does not cause a warning to be produced. */ -/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */ - -@interface NXConstantString -{ - void *isa; - const char * const nxcsptr; - const unsigned int nxcslen; -} -@end -NXConstantString *a = @"NSInconsistentArchiveException"; /* { dg-bogus "defined but not used" } */ - - Index: gcc/testsuite/objc.dg/foreach-4.m =================================================================== --- gcc/testsuite/objc.dg/foreach-4.m (revision 165662) +++ gcc/testsuite/objc.dg/foreach-4.m (working copy) @@ -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: gcc/testsuite/objc.dg/const-str-2.m =================================================================== --- gcc/testsuite/objc.dg/const-str-2.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-2.m (working copy) @@ -1,7 +0,0 @@ -/* Test the -fconstant-string-class flag error. */ -/* { dg-do compile } */ -/* { dg-options "-fconstant-string-class=" } */ - -{ dg-error "no class name specified|missing argument" "" { target *-*-* } 0 } - -void foo () {} Index: gcc/testsuite/objc.dg/const-str-6.m =================================================================== --- gcc/testsuite/objc.dg/const-str-6.m (revision 165662) +++ gcc/testsuite/objc.dg/const-str-6.m (working copy) @@ -1,27 +0,0 @@ -/* Negative test case for constant string layout. */ -/* Contributed by Ziemowit Laski . */ - -/* { dg-options "-fconstant-string-class=MyConstantString" } */ -/* { dg-do compile } */ - -@interface MyBase { - char p; -} -@end - -@interface MyConstantString: MyBase { - union { - void *u; - unsigned char *c; - } _contents; - char _count; -} -@end - -/* The NeXT runtime initializes the 'isa' pointer of string constants at - compile time. */ -#ifdef __NEXT_RUNTIME__ -extern void *_MyConstantStringClassReference; -#endif - -MyConstantString *str = @"Hello"; /* { dg-error "interface .MyConstantString. does not have valid constant string layout" } */