From 5826c8d29eb8182a03ba533bdaed122ada974521 Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Tue, 11 Jan 2011 10:14:48 +0000 Subject: [PATCH] next-mapping.h: Add copyright header. gcc/testsuite: * objc-obj-c++-shared/next-mapping.h: Add copyright header. Split type definitions and NSConstantString class into... * objc-obj-c++-shared/objc-test-suite-types.h: New. * objc-obj-c++-shared/nsconstantstring-class.h: New. * objc-obj-c++-shared/nsconstantstring-class-impl.h: New. * objc-obj-c++-shared/nsconstantstring-class-impl.m: New. * objc-obj-c++-shared/nsconstantstring-class-impl.mm: New. * objc-obj-c++-shared/next-abi.h: Add copyright header, minor update to comments. * objc-obj-c++-shared/objc-test-suite-next-encode-assist.h: Adjust encode defines for newer NeXT system headers. * obj-c++.dg/template-4.mm: Adjust to use nsconstantstring headers. * obj-c++.dg/torture/strings/string1.mm: Likewise. * objc.dg/foreach-5.m: Likewise. * objc.dg/foreach-2.m: Likewise. * objc.dg/foreach-4.m: Likewise. * objc.dg/torture/strings/string1.m: Likewise. * objc.dg/torture/strings/string2.m: Likewise. * objc.dg/torture/strings/string3.m: Likewise. * objc.dg/torture/strings/string4.m: Likewise. * obj-c++.dg/torture/strings/const-str-3.mm: Adjust to use type header and stand alone. * obj-c++.dg/strings/strings-2.mm: Likewise. * objc.dg/torture/strings/const-str-3.m: Likewise. * objc.dg/strings/strings-2.m: Likewise. * objc.dg/strings/const-str-12b.m: Likewise. From-SVN: r168653 --- gcc/testsuite/ChangeLog | 29 +++ gcc/testsuite/obj-c++.dg/strings/strings-2.mm | 19 +- gcc/testsuite/obj-c++.dg/template-4.mm | 10 +- .../obj-c++.dg/torture/strings/const-str-3.mm | 29 ++- .../obj-c++.dg/torture/strings/string1.mm | 4 +- gcc/testsuite/objc-obj-c++-shared/next-abi.h | 25 ++- .../objc-obj-c++-shared/next-mapping.h | 186 +++++++----------- .../nsconstantstring-class-impl.h | 61 ++++++ .../nsconstantstring-class-impl.m | 3 + .../nsconstantstring-class-impl.mm | 3 + .../nsconstantstring-class.h | 51 +++++ .../objc-test-suite-next-encode-assist.h | 28 +-- .../objc-test-suite-types.h | 80 ++++++++ gcc/testsuite/objc.dg/foreach-2.m | 4 +- gcc/testsuite/objc.dg/foreach-4.m | 4 +- gcc/testsuite/objc.dg/foreach-5.m | 4 +- gcc/testsuite/objc.dg/strings/const-str-12b.m | 10 +- gcc/testsuite/objc.dg/strings/strings-2.m | 20 +- .../objc.dg/torture/strings/const-str-3.m | 25 +-- .../objc.dg/torture/strings/string1.m | 9 +- .../objc.dg/torture/strings/string2.m | 9 +- .../objc.dg/torture/strings/string3.m | 8 +- .../objc.dg/torture/strings/string4.m | 8 +- 23 files changed, 406 insertions(+), 223 deletions(-) create mode 100644 gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.h create mode 100644 gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.m create mode 100644 gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.mm create mode 100644 gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class.h create mode 100644 gcc/testsuite/objc-obj-c++-shared/objc-test-suite-types.h diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ec811bc03808..22041467a2fa 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,32 @@ +2011-01-11 Iain Sandoe + + * objc-obj-c++-shared/next-mapping.h: Add copyright header. + Split type definitions and NSConstantString class into... + * objc-obj-c++-shared/objc-test-suite-types.h: New. + * objc-obj-c++-shared/nsconstantstring-class.h: New. + * objc-obj-c++-shared/nsconstantstring-class-impl.h: New. + * objc-obj-c++-shared/nsconstantstring-class-impl.m: New. + * objc-obj-c++-shared/nsconstantstring-class-impl.mm: New. + * objc-obj-c++-shared/next-abi.h: Add copyright header, minor update + to comments. + * objc-obj-c++-shared/objc-test-suite-next-encode-assist.h: Adjust + encode defines for newer NeXT system headers. + * obj-c++.dg/template-4.mm: Adjust to use nsconstantstring headers. + * obj-c++.dg/torture/strings/string1.mm: Likewise. + * objc.dg/foreach-5.m: Likewise. + * objc.dg/foreach-2.m: Likewise. + * objc.dg/foreach-4.m: Likewise. + * objc.dg/torture/strings/string1.m: Likewise. + * objc.dg/torture/strings/string2.m: Likewise. + * objc.dg/torture/strings/string3.m: Likewise. + * objc.dg/torture/strings/string4.m: Likewise. + * obj-c++.dg/torture/strings/const-str-3.mm: Adjust to use type + header and stand alone. + * obj-c++.dg/strings/strings-2.mm: Likewise. + * objc.dg/torture/strings/const-str-3.m: Likewise. + * objc.dg/strings/strings-2.m: Likewise. + * objc.dg/strings/const-str-12b.m: Likewise. + 2011-01-12 Richard Guenther PR middle-end/32511 diff --git a/gcc/testsuite/obj-c++.dg/strings/strings-2.mm b/gcc/testsuite/obj-c++.dg/strings/strings-2.mm index 09d7a7f1f320..403cf7d3b456 100644 --- a/gcc/testsuite/obj-c++.dg/strings/strings-2.mm +++ b/gcc/testsuite/obj-c++.dg/strings/strings-2.mm @@ -5,24 +5,24 @@ /* { dg-options "-fconstant-string-class=MyTestString" } */ /* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyTestString" { 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/objc-test-suite-types.h" #include /* For abort() */ -@interface MyTestString : Object +@interface MyTestString { + void *dummy_class_ptr; char *string; unsigned int len; } ++ initialize; /* All strings should contain the C string 'test'. Call -check to test that this is true. */ - (void) check; @end @implementation MyTestString ++ initialize {return self;} - (void) check { if (len != 4 || string[0] != 't' || string[1] != 'e' @@ -31,13 +31,7 @@ } @end -#ifdef __NEXT_RUNTIME__ -# ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _MyTestStringClassReference; -# else -struct objc_class _MyTestStringClassReference; -# endif -#endif +TNS_STRING_REF_T _MyTestStringClassReference; /* Only used by NeXT. */ int main (void) { @@ -59,6 +53,7 @@ int main (void) } #ifdef __NEXT_RUNTIME__ +#include /* The MyTestString metaclass will need to be initialized before we can send messages to strings. */ diff --git a/gcc/testsuite/obj-c++.dg/template-4.mm b/gcc/testsuite/obj-c++.dg/template-4.mm index 4d96a47a35af..af3145f055a6 100644 --- a/gcc/testsuite/obj-c++.dg/template-4.mm +++ b/gcc/testsuite/obj-c++.dg/template-4.mm @@ -3,17 +3,21 @@ /* { 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" } */ +/* { dg-additional-sources "../objc-obj-c++-shared/Object1.mm ../objc-obj-c++-shared/nsconstantstring-class-impl.mm" } */ -#include "../objc-obj-c++-shared/Object1.h" -#include "../objc-obj-c++-shared/next-mapping.h" #include #include +#include #ifndef __NEXT_RUNTIME__ #include +#else +#include "../objc-obj-c++-shared/nsconstantstring-class.h" #endif +#include "../objc-obj-c++-shared/Object1.h" +#include "../objc-obj-c++-shared/next-mapping.h" + #define CHECK_IF(expr) if(!(expr)) abort() template class TestT diff --git a/gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm index edcbef0396e6..461d97b19473 100644 --- a/gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm +++ b/gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm @@ -6,32 +6,26 @@ /* { 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" +#include "../../../objc-obj-c++-shared/objc-test-suite-types.h" + #include #include -#include -#include -#ifndef __NEXT_RUNTIME__ -#include -#endif +#include -@interface Foo: Object { +@interface Foo { + void *dummy_class_ref; char *cString; unsigned int len; } ++ initialize; - (char *)customString; @end -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _FooClassReference; -#else -struct objc_class _FooClassReference; -#endif +TNS_STRING_REF_T _FooClassReference; /* Only used by NeXT. */ -@implementation Foo : Object +@implementation Foo ++ initialize {return self;} - (char *)customString { return cString; } @@ -45,11 +39,14 @@ int main () { abort(); printf("Strings are being uniqued properly\n"); +#ifdef __NEXT_RUNTIME__ /* 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)); + memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference)); +#endif + if (strcmp ([string customString], "bla")) { abort (); } diff --git a/gcc/testsuite/obj-c++.dg/torture/strings/string1.mm b/gcc/testsuite/obj-c++.dg/torture/strings/string1.mm index df315fb87849..deacf43b34b8 100644 --- a/gcc/testsuite/obj-c++.dg/torture/strings/string1.mm +++ b/gcc/testsuite/obj-c++.dg/torture/strings/string1.mm @@ -3,7 +3,7 @@ /* { 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" } */ +/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.mm ../../../objc-obj-c++-shared/nsconstantstring-class-impl.mm" } */ #include "../../../objc-obj-c++-shared/Object1.h" #include "../../../objc-obj-c++-shared/next-mapping.h" @@ -13,6 +13,8 @@ #ifndef __NEXT_RUNTIME__ #include +#else +#include "../../../objc-obj-c++-shared/nsconstantstring-class.h" #endif int main(int argc, char **args) diff --git a/gcc/testsuite/objc-obj-c++-shared/next-abi.h b/gcc/testsuite/objc-obj-c++-shared/next-abi.h index 3ab9804e5104..0ffa0fcba176 100644 --- a/gcc/testsuite/objc-obj-c++-shared/next-abi.h +++ b/gcc/testsuite/objc-obj-c++-shared/next-abi.h @@ -1,3 +1,23 @@ +/* Check which version of the API and ABI are appropriate for the target. + Copyright (C) 2010, 2011 Free Software Foundation, Inc. + + Contributed by Iain Sandoe + +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 +. */ #ifndef _OBJC_NEXT_ABI_H_ #define _OBJC_NEXT_ABI_H_ @@ -6,9 +26,8 @@ */ /* By default we do nothing - therefore ifdef NEXT_OBJC_USE_NEW_INTERFACE - * is reliable for detecting - * (a) versions of the compiler that are transitional to the new next ABI - * (b) versions of the target that require the new ABI. + * is reliable for detecting versions of the target that require either + * API=2, or both API & ABI = 2 (m64 code). * * This applies for versions of OSX >= 10.5 (darwin9). * diff --git a/gcc/testsuite/objc-obj-c++-shared/next-mapping.h b/gcc/testsuite/objc-obj-c++-shared/next-mapping.h index 3b141c67a67d..d2ae8e9e6797 100644 --- a/gcc/testsuite/objc-obj-c++-shared/next-mapping.h +++ b/gcc/testsuite/objc-obj-c++-shared/next-mapping.h @@ -1,42 +1,79 @@ +/* Compatibility header between runtimes and APIs. + Copyright (C) 2010, 2011 Free Software Foundation, Inc. + + Original Authors: Ziemowit Laski + David Ayers + + re-work for ObjC2 by Iain Sandoe + +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 +. */ + #ifndef _OBJC_NEXT_MAPPING_H_ #define _OBJC_NEXT_MAPPING_H_ -/* This file "renames" various ObjC GNU runtime entry points - (and fakes the existence of several others) - if the NeXT runtime is being used. */ -/* Authors: Ziemowit Laski */ -/* David Ayers */ -/* Darwin 64bit/OBJC2 modifications Iain Sandoe */ +/* This file provides a two-way mapping of API names for the original + GNU & NeXT APIs. + + It is being expanded to provide mapping (where possible) between between the + older API and API-2. +*/ + +#include "objc-test-suite-types.h" #ifndef __NEXT_RUNTIME__ -#define CLASSPTRFIELD(x) (x)->class_pointer +# define CLASSFIELD class_pointer +# define CLASSPTRFIELD(x) (x)->class_pointer +# define SUPERCLASS superClass +# define OBJC_GETCLASS objc_get_class -#else -/* Includes next-abi.h to set NEXT_OBJC_USE_NEW_INTERFACE etc.*/ -#ifndef _OBJC_OBJECT1_H_ -#include "Object1.h" -#endif -#include -#include -#include -#include +# ifdef __objc_api_INCLUDE_GNU +# define class_createInstance(C, S) class_create_instance(C) +# endif +# define method_get_types(M) (M)->method_types -/* Force a definition of nil that is compatible with GNU runtime. */ -#undef nil -#define nil ((id)0) +#else /* NeXT */ -#define objc_get_class(C) objc_getClass(C) -#define objc_get_meta_class(C) objc_getMetaClass(C) -#define class_get_class_method(C, S) class_getClassMethod(C, S) -#define class_get_instance_method(C, S) class_getInstanceMethod(C, S) -#define sel_get_name(S) sel_getName(S) -#define class_create_instance(C) class_createInstance(C, 0) -#define class_get_class_name(C) object_getClassName(C) +/* Include next-abi.h to set NEXT_OBJC_USE_NEW_INTERFACE etc.*/ +# include "next-abi.h" -#define CLASSPTRFIELD(x) (x)->isa +# ifdef NEXT_OBJC_USE_NEW_INTERFACE + /* API=2. */ +# include +# else + /* API=0. */ +# include +# endif + +# define CLASSPTRFIELD(x) (x)->isa +# define SUPERCLASS superclass +# define OBJC_GETCLASS objc_getClass + +# define objc_get_class(C) objc_getClass(C) +# define objc_get_meta_class(C) objc_getMetaClass(C) +# define class_get_class_method(C, S) class_getClassMethod(C, S) +# define class_get_instance_method(C, S) class_getInstanceMethod(C, S) +# define sel_get_name(S) sel_getName(S) +# define class_create_instance(C) class_createInstance(C, 0) +# define class_get_class_name(C) object_getClassName(C) +# define objc_lookup_class(N) objc_lookUpClass(N) + +# ifdef NEXT_OBJC_USE_NEW_INTERFACE -#ifdef NEXT_OBJC_USE_NEW_INTERFACE # define object_class_name(O) (object_getClassName(O)) # define object_get_class(O) (object_getClass((id)O)) # define object_get_super_class(O) class_get_super_class(object_get_class(O)) @@ -51,7 +88,8 @@ # define class_is_meta_class(C) (class_isMetaClass((Class)C) ? YES: NO) # define class_is_class(C) (class_is_meta_class(C) == NO) -#else +# else /* OLD API */ + # define object_class_name(O) (O->name) # define object_get_super_class(O) class_get_super_class(*(struct objc_class **)O) # define object_get_class(O) (*(struct objc_class **)O) @@ -64,94 +102,8 @@ # define class_get_super_class(C) (((struct objc_class *)C)->super_class) # define class_is_meta_class(C) (CLS_GETINFO((struct objc_class *)C, CLS_META)? YES: NO) # define class_is_class(C) (CLS_GETINFO((struct objc_class *)C, CLS_CLASS)? YES: NO) -#endif -#define objc_lookup_class(N) objc_lookUpClass(N) +# endif /* NEXT_OBJC_USE_NEW_INTERFACE */ -/* You need either an empty +initialize method or an empty -forward:: method. - The NeXT runtime unconditionally sends +initialize to classes when they are - first used, and unconditionally tries to forward methods that the class - doesn't understand (including +initialize). If you have neither +initialize - nor -forward::, the runtime complains. - - The simplest workaround is to add - - + initialize { return self; } - - to every root class @implementation. */ - -#ifndef NULL -#define NULL 0 -#endif - - -/* A small, portable NSConstantString implementation for use with the NeXT - runtime. - - On full-fledged Mac OS X systems, NSConstantString is provided - as part of the Foundation framework. However, on bare Darwin systems, - Foundation is not included, and hence there is no NSConstantString - implementation to link against. - - This code is derived from the GNU runtime's NXConstantString implementation. -*/ - -/* This definition cut out of with the OBJC2 deprecation - messages removed. -*/ -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class { - Class isa; -#if NEXT_OBJC_ABI_VERSION < 2 - Class super_class ; - const char *name ; - long version ; - long info ; - long instance_size ; - struct anon *ivars ; /* objc_ivar_list */ - struct anon1 **methodLists ; /* objc_method_list */ - struct objc_cache *cache ; - struct objc_protocol_list *protocols ; -#endif -} _NSConstantStringClassReference ; -#else -struct objc_class _NSConstantStringClassReference ; -#endif - -@interface NSConstantString : Object -{ - char *c_string; - unsigned int len; -} - --(const char *) cString; --(unsigned int) length; - -@end - -@implementation NSConstantString - --(const char *) cString -{ - return (c_string); -} - --(unsigned int) length -{ - return (len); -} - -@end - -/* The NSConstantString metaclass will need to be initialized before we can - send messages to strings. */ - -void objc_constant_string_init (void) __attribute__((constructor)); -void objc_constant_string_init (void) { - memcpy (&_NSConstantStringClassReference, - objc_getClass ("NSConstantString"), - sizeof (_NSConstantStringClassReference)); -} - -#endif /*__NEXT_RUNTIME__ */ +# endif /*__NEXT_RUNTIME__ */ #endif /* _OBJC_NEXT_MAPPING_H_ */ \ No newline at end of file diff --git a/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.h b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.h new file mode 100644 index 000000000000..0068b4a2ae4e --- /dev/null +++ b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.h @@ -0,0 +1,61 @@ +/* A small NSConstantString implementation for use with the NeXT runtime. + Copyright (C) 2011 Free Software Foundation, Inc. + + Contributed by Iain Sandoe + +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 +. */ + +#ifdef __NEXT_RUNTIME__ + +#include "nsconstantstring-class.h" +#include + +/* On full-fledged Mac OS X systems, NSConstantString is provided + as part of the Foundation framework. However, on bare Darwin systems, + Foundation is not included, and hence there is no NSConstantString + implementation to link against. + + This code is derived from the GNU runtime's NXConstantString implementation. +*/ + +@implementation NSConstantString +/* NeXT requires this or forward: */ ++initialize { return self; } + +-(const char *) cString +{ + return (c_string); +} + +-(unsigned int) length +{ + return (len); +} +@end + +TNS_STRING_REF_T _NSConstantStringClassReference; + +/* The NSConstantString metaclass will need to be initialized before we can + send messages to strings. */ + +void objc_constant_string_init (void) __attribute__((constructor)); +void objc_constant_string_init (void) { + memcpy (&_NSConstantStringClassReference, + objc_getClass ("NSConstantString"), + sizeof (_NSConstantStringClassReference)); +} +#endif diff --git a/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.m b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.m new file mode 100644 index 000000000000..cd9c7dd8fa5d --- /dev/null +++ b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.m @@ -0,0 +1,3 @@ +/* Allow code to be shared between the FEs but avoid issues with + C++-only flags. */ +#include "nsconstantstring-class-impl.h" diff --git a/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.mm b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.mm new file mode 100644 index 000000000000..cd9c7dd8fa5d --- /dev/null +++ b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.mm @@ -0,0 +1,3 @@ +/* Allow code to be shared between the FEs but avoid issues with + C++-only flags. */ +#include "nsconstantstring-class-impl.h" diff --git a/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class.h b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class.h new file mode 100644 index 000000000000..485e39e6f085 --- /dev/null +++ b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class.h @@ -0,0 +1,51 @@ +/* A small NSConstantString implementation for use with the NeXT runtime. + Copyright (C) 2011 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 +. */ + +#ifndef _test_suite_nsconstantstring_class_h_ +#define _test_suite_nsconstantstring_class_h_ +#ifdef __NEXT_RUNTIME__ + +/* On full-fledged Mac OS X systems, NSConstantString is provided + as part of the Foundation framework. However, on bare Darwin systems, + Foundation is not included, and hence there is no NSConstantString + implementation to link against. + + This code is derived from the GNU runtime's NXConstantString implementation. +*/ + +#include "objc-test-suite-types.h" + +extern TNS_STRING_REF_T _NSConstantStringClassReference; + +@interface NSConstantString +{ + Class isa; + char *c_string; + unsigned int len; +} + ++ (id) initialize; + +- (const char *) cString; +- (unsigned int) length; + +@end + +#endif /* __NEXT_RUNTIME__ */ +#endif /* _test_suite_nsconstantstring_class_h_ */ diff --git a/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-next-encode-assist.h b/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-next-encode-assist.h index 0a0f93c376a2..af02b278a2e4 100644 --- a/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-next-encode-assist.h +++ b/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-next-encode-assist.h @@ -10,6 +10,13 @@ typedef void * PMETH; #else #include typedef struct objc_method * PMETH; + +/* Missing from old NeXT objc headers... */ +#define _C_LNG_LNG 'q' +#define _C_ULNG_LNG 'Q' +#define _C_ATOM '%' +#define _C_BOOL 'B' + #endif /* The NeXT headers do not define NULL. */ @@ -17,24 +24,6 @@ typedef struct objc_method * PMETH; #define NULL 0 #endif -/* The NeXT runtimes do not include these functions (at least not through - any public API). They are required for the objc/execute/bf-* and bycopy-3. */ - -/* Not sure why the following are missing from NeXT objc headers... */ - -#ifndef _C_LNG_LNG -#define _C_LNG_LNG 'q' -#endif -#ifndef _C_ULNG_LNG -#define _C_ULNG_LNG 'Q' -#endif -#ifndef _C_ATOM -#define _C_ATOM '%' -#endif -#ifndef _C_BOOL -#define _C_BOOL 'B' -#endif - #define _C_CONST 'r' #define _C_IN 'n' #define _C_INOUT 'N' @@ -53,7 +42,8 @@ typedef struct objc_method * PMETH; #define _F_ONEWAY 0x10 #define _F_GCINVISIBLE 0x20 -/* Functions available in the GNU runtime, emulated here for testing with NeXT. */ +/* The NeXT runtimes do not include these functions (at least not through + any public API). They are required for the objc/execute/bf-* and bycopy-3. */ struct objc_struct_layout { diff --git a/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-types.h b/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-types.h new file mode 100644 index 000000000000..ab502d467608 --- /dev/null +++ b/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-types.h @@ -0,0 +1,80 @@ +/* Define test-suite types to minimize conditional test-case source. + Copyright (C) 2011 Free Software Foundation, Inc. + Contributed by Iain Sandoe + +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 +. */ + +#ifndef _OBJC_TEST_SUITE_TYPES_H_ +#define _OBJC_TEST_SUITE_TYPES_H_ + +#ifdef __cplusplus +#define ProtoBool bool +#else +#define ProtoBool _Bool +#endif + +#ifndef __NEXT_RUNTIME__ + +#define METHOD Method_t +#define IVAR_T struct objc_ivar + +/* dummy const string class ref. */ +typedef void * TNS_STRING_REF_T; + +#else /* NeXT */ + +#include "next-abi.h" +#ifdef NEXT_OBJC_USE_NEW_INTERFACE +#include +#else +#include +#endif + +/* Force a definition of nil that is compatible with GNU runtime. */ +#undef nil +#define nil ((id)0) + +#ifndef NULL +#define NULL 0 +#endif + +#define METHOD Method + +/* Where there are equivalent interfaces between APIs we substitute + a macro or typedef. */ +#ifdef NEXT_OBJC_USE_NEW_INTERFACE +typedef void * PMETH; +#define IVAR_T Ivar +#else +typedef struct objc_method * PMETH; +#define IVAR_T struct objc_ivar +#endif + +#ifdef __OBJC2__ +/* Const String Class ref. */ +typedef Class TNS_STRING_REF_T; +#else +/* Const String Class ref. */ +/* We need objc_class - but we don't need endless reminders that it's deprecated. */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +typedef struct objc_class TNS_STRING_REF_T; +#pragma GCC diagnostic pop +#endif + +#endif /*__NEXT_RUNTIME__ */ +#endif /* _OBJC_TEST_SUITE_TYPES_H_ */ \ No newline at end of file diff --git a/gcc/testsuite/objc.dg/foreach-2.m b/gcc/testsuite/objc.dg/foreach-2.m index 80e9e708e171..a319a4bc7165 100644 --- a/gcc/testsuite/objc.dg/foreach-2.m +++ b/gcc/testsuite/objc.dg/foreach-2.m @@ -5,12 +5,14 @@ /* { dg-skip-if "No NeXT fast enum. pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ /* { 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" } */ +/* { dg-additional-sources "../objc-obj-c++-shared/Object1.m ../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ #include "../objc-obj-c++-shared/Object1.h" #include "../objc-obj-c++-shared/next-mapping.h" #ifndef __NEXT_RUNTIME__ #include +#else +#include "../objc-obj-c++-shared/nsconstantstring-class.h" #endif extern int printf (const char *, ...); diff --git a/gcc/testsuite/objc.dg/foreach-4.m b/gcc/testsuite/objc.dg/foreach-4.m index ed5dda01a603..13b9b0bb9de0 100644 --- a/gcc/testsuite/objc.dg/foreach-4.m +++ b/gcc/testsuite/objc.dg/foreach-4.m @@ -5,12 +5,14 @@ /* { dg-skip-if "No NeXT fast enum. pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ /* { 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" } */ +/* { dg-additional-sources "../objc-obj-c++-shared/Object1.m ../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ #import "../objc-obj-c++-shared/Object1.h" #import "../objc-obj-c++-shared/next-mapping.h" #ifndef __NEXT_RUNTIME__ #include +#else +#include "../objc-obj-c++-shared/nsconstantstring-class.h" #endif extern int printf (const char *, ...); diff --git a/gcc/testsuite/objc.dg/foreach-5.m b/gcc/testsuite/objc.dg/foreach-5.m index 7bcabee5367f..c715b2d822d3 100644 --- a/gcc/testsuite/objc.dg/foreach-5.m +++ b/gcc/testsuite/objc.dg/foreach-5.m @@ -5,12 +5,14 @@ /* { dg-skip-if "No NeXT fast enum. pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ /* { 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" } */ +/* { dg-additional-sources "../objc-obj-c++-shared/Object1.m ../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ #import "../objc-obj-c++-shared/Object1.h" #import "../objc-obj-c++-shared/next-mapping.h" #ifndef __NEXT_RUNTIME__ #include +#else +#include "../objc-obj-c++-shared/nsconstantstring-class.h" #endif extern int printf (const char *, ...); diff --git a/gcc/testsuite/objc.dg/strings/const-str-12b.m b/gcc/testsuite/objc.dg/strings/const-str-12b.m index cad481e15a01..430ab5db2d60 100644 --- a/gcc/testsuite/objc.dg/strings/const-str-12b.m +++ b/gcc/testsuite/objc.dg/strings/const-str-12b.m @@ -5,8 +5,8 @@ /* { 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 +#include "../../objc-obj-c++-shared/objc-test-suite-types.h" @interface Foo: Object { char *cString; @@ -19,11 +19,7 @@ + (Foo *) getString: (int) which; @end -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _FooClassReference; -#else -struct objc_class _FooClassReference; -#endif +TNS_STRING_REF_T _FooClassReference; /* Only used by NeXT. */ @implementation Bar + (Foo *) getString: (int) which { diff --git a/gcc/testsuite/objc.dg/strings/strings-2.m b/gcc/testsuite/objc.dg/strings/strings-2.m index 29d9375bf7b1..b07ac0f78421 100644 --- a/gcc/testsuite/objc.dg/strings/strings-2.m +++ b/gcc/testsuite/objc.dg/strings/strings-2.m @@ -5,24 +5,25 @@ /* { dg-options "-fconstant-string-class=MyTestString" } */ /* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyTestString" { target *-*-darwin* } } */ -/* { 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 "../../objc-obj-c++-shared/objc-test-suite-types.h" #include /* For abort() */ -@interface MyTestString : Object +@interface MyTestString { + void *dummy_class_ptr; char *string; unsigned int len; } ++ initialize; /* All strings should contain the C string 'test'. Call -check to test that this is true. */ - (void) check; @end @implementation MyTestString ++ initialize {return self;} + - (void) check { if (len != 4 || string[0] != 't' || string[1] != 'e' @@ -31,13 +32,7 @@ } @end -#ifdef __NEXT_RUNTIME__ -# ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _MyTestStringClassReference; -# else -struct objc_class _MyTestStringClassReference; -# endif -#endif +TNS_STRING_REF_T _MyTestStringClassReference; /* Only used by NeXT. */ int main (void) { @@ -61,6 +56,7 @@ int main (void) #ifdef __NEXT_RUNTIME__ /* The MyTestString metaclass will need to be initialized before we can send messages to strings. */ +#include void testsuite_mytest_string_init (void) __attribute__((constructor)); void testsuite_mytest_string_init (void) { diff --git a/gcc/testsuite/objc.dg/torture/strings/const-str-3.m b/gcc/testsuite/objc.dg/torture/strings/const-str-3.m index ca2df5a89ec7..0eb2d6a01e06 100644 --- a/gcc/testsuite/objc.dg/torture/strings/const-str-3.m +++ b/gcc/testsuite/objc.dg/torture/strings/const-str-3.m @@ -4,28 +4,27 @@ /* { 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" } */ -#include "../../../objc-obj-c++-shared/Object1.h" -#include "../../../objc-obj-c++-shared/next-mapping.h" +#include "../../../objc-obj-c++-shared/objc-test-suite-types.h" + #include #include #include -@interface Foo: Object { +@interface Foo { + void *dummy_class_ref; char *cString; unsigned int len; } ++ initialize; - (char *)customString; @end -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _FooClassReference; -#else -struct objc_class _FooClassReference; -#endif +TNS_STRING_REF_T _FooClassReference; /* Only used by NeXT. */ + +@implementation Foo ++ initialize {return self;} -@implementation Foo : Object - (char *)customString { return cString; } @@ -39,11 +38,13 @@ int main () { abort(); printf("Strings are being uniqued properly\n"); +#ifdef __NEXT_RUNTIME__ /* 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. */ + is already a message. */ - memcpy(&_FooClassReference, objc_get_class("Foo"), sizeof(_FooClassReference)); + memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference)); +#endif if (strcmp ([string customString], "bla")) { abort (); } diff --git a/gcc/testsuite/objc.dg/torture/strings/string1.m b/gcc/testsuite/objc.dg/torture/strings/string1.m index 76d3c9b0756d..455b5f1bff14 100644 --- a/gcc/testsuite/objc.dg/torture/strings/string1.m +++ b/gcc/testsuite/objc.dg/torture/strings/string1.m @@ -1,18 +1,17 @@ /* Based on a test case contributed by Nicola Pero. */ /* { dg-do run } */ -/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ +/* { dg-options "-mno-constant-cfstrings -Wno-deprecated-declarations" { 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" +/* { dg-additional-sources "../../../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ #include #include #ifndef __NEXT_RUNTIME__ #include +#else +#include "../../../objc-obj-c++-shared/nsconstantstring-class.h" #endif int main(int argc, void **args) diff --git a/gcc/testsuite/objc.dg/torture/strings/string2.m b/gcc/testsuite/objc.dg/torture/strings/string2.m index 90e4db1e33cf..030ba602db50 100644 --- a/gcc/testsuite/objc.dg/torture/strings/string2.m +++ b/gcc/testsuite/objc.dg/torture/strings/string2.m @@ -1,18 +1,17 @@ /* Based on a test case contributed by Nicola Pero. */ /* { dg-do run } */ -/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ +/* { dg-options "-mno-constant-cfstrings -Wno-deprecated-declarations" { 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" +/* { dg-additional-sources "../../../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ #include #include #ifndef __NEXT_RUNTIME__ #include +#else +#include "../../../objc-obj-c++-shared/nsconstantstring-class.h" #endif int main(int argc, void **args) diff --git a/gcc/testsuite/objc.dg/torture/strings/string3.m b/gcc/testsuite/objc.dg/torture/strings/string3.m index ca08fed8d00e..b08dfb242b33 100644 --- a/gcc/testsuite/objc.dg/torture/strings/string3.m +++ b/gcc/testsuite/objc.dg/torture/strings/string3.m @@ -1,17 +1,17 @@ /* Based on a test case contributed by Nicola Pero. */ /* { dg-do run } */ -/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ +/* { dg-options "-mno-constant-cfstrings -Wno-deprecated-declarations" { target *-*-darwin* } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ -/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */ +/* { dg-additional-sources "../../../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ -#include "../../../objc-obj-c++-shared/Object1.h" -#import "../../../objc-obj-c++-shared/next-mapping.h" #include #include #ifndef __NEXT_RUNTIME__ #include +#else +#include "../../../objc-obj-c++-shared/nsconstantstring-class.h" #endif #define STRING "this is a string" diff --git a/gcc/testsuite/objc.dg/torture/strings/string4.m b/gcc/testsuite/objc.dg/torture/strings/string4.m index caa877e4de71..425ccc080ea4 100644 --- a/gcc/testsuite/objc.dg/torture/strings/string4.m +++ b/gcc/testsuite/objc.dg/torture/strings/string4.m @@ -1,17 +1,17 @@ /* Based on a test case contributed by Nicola Pero. */ /* { dg-do run } */ -/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ +/* { dg-options "-mno-constant-cfstrings -Wno-deprecated-declarations" { target *-*-darwin* } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ -/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */ +/* { dg-additional-sources "../../../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ -#include "../../../objc-obj-c++-shared/Object1.h" -#import "../../../objc-obj-c++-shared/next-mapping.h" #include #include #ifndef __NEXT_RUNTIME__ #include +#else +#include "../../../objc-obj-c++-shared/nsconstantstring-class.h" #endif int main(int argc, void **args)