diff options
author | iains <iains@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-01-11 10:14:48 +0000 |
---|---|---|
committer | iains <iains@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-01-11 10:14:48 +0000 |
commit | 21193cc2b59e9cbdace9ebb755f00086f8eeb7ba (patch) | |
tree | 5b775ac5ec0f8b64be5f92c27555c7ca090cd766 /gcc | |
parent | 0725e25c3c1c28f88a8fe92d2eac113857e6e407 (diff) | |
download | gcc-21193cc2b59e9cbdace9ebb755f00086f8eeb7ba.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@168653 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
23 files changed, 411 insertions, 228 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ec811bc0380..22041467a2f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,32 @@ +2011-01-11 Iain Sandoe <iains@gcc.gnu.org> + + * 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 <rguenther@suse.de> 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 09d7a7f1f32..403cf7d3b45 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 <stdlib.h> /* 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 <string.h> /* 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 4d96a47a35a..af3145f055a 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 <stdarg.h> #include <stdlib.h> +#include <string.h> #ifndef __NEXT_RUNTIME__ #include <objc/NXConstStr.h> +#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 ARR, class TYPE> 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 edcbef0396e..461d97b1947 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 <stdio.h> #include <stdlib.h> -#include <memory.h> -#include <objc/objc.h> -#ifndef __NEXT_RUNTIME__ -#include <objc/objc-api.h> -#endif +#include <string.h> -@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 df315fb8784..deacf43b34b 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 <objc/NXConstStr.h> +#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 3ab9804e510..0ffa0fcba17 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 <iains@gcc.gnu.org> + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ #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 3b141c67a67..d2ae8e9e679 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 <zlaski@apple.com> + David Ayers <d.ayers@inode.at> + + re-work for ObjC2 by Iain Sandoe <iains@gcc.gnu.org> + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + #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 <zlaski@apple.com> */ -/* David Ayers <d.ayers@inode.at> */ -/* 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 - -#else -/* Includes next-abi.h to set NEXT_OBJC_USE_NEW_INTERFACE etc.*/ -#ifndef _OBJC_OBJECT1_H_ -#include "Object1.h" -#endif -#include <objc/objc-class.h> -#include <ctype.h> -#include <stdlib.h> -#include <string.h> - -/* Force a definition of nil that is compatible with GNU runtime. */ -#undef nil -#define nil ((id)0) - -#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 CLASSPTRFIELD(x) (x)->isa - -#ifdef NEXT_OBJC_USE_NEW_INTERFACE +# define CLASSFIELD class_pointer +# define CLASSPTRFIELD(x) (x)->class_pointer +# define SUPERCLASS superClass +# define OBJC_GETCLASS objc_get_class + +# ifdef __objc_api_INCLUDE_GNU +# define class_createInstance(C, S) class_create_instance(C) +# endif +# define method_get_types(M) (M)->method_types + +#else /* NeXT */ + +/* Include next-abi.h to set NEXT_OBJC_USE_NEW_INTERFACE etc.*/ +# include "next-abi.h" + +# ifdef NEXT_OBJC_USE_NEW_INTERFACE + /* API=2. */ +# include <objc/runtime.h> +# else + /* API=0. */ +# include <objc/objc-class.h> +# 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 + # 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) - -/* 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. */ +# endif /* NEXT_OBJC_USE_NEW_INTERFACE */ -#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 <objc/Object.h> 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 00000000000..0068b4a2ae4 --- /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 <iains@gcc.gnu.org> + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#ifdef __NEXT_RUNTIME__ + +#include "nsconstantstring-class.h" +#include <string.h> + +/* 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 00000000000..cd9c7dd8fa5 --- /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 00000000000..cd9c7dd8fa5 --- /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 00000000000..485e39e6f08 --- /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 +<http://www.gnu.org/licenses/>. */ + +#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 0a0f93c376a..af02b278a2e 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,29 +10,18 @@ typedef void * PMETH; #else #include <objc/objc-runtime.h> typedef struct objc_method * PMETH; -#endif - -/* The NeXT headers do not define NULL. */ -#ifndef NULL -#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 +/* Missing from old NeXT objc headers... */ #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 + +/* The NeXT headers do not define NULL. */ +#ifndef NULL +#define NULL 0 #endif #define _C_CONST 'r' @@ -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 00000000000..ab502d46760 --- /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 +<http://www.gnu.org/licenses/>. */ + +#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 <objc/runtime.h> +#else +#include <objc/objc-runtime.h> +#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 80e9e708e17..a319a4bc716 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 <objc/NXConstStr.h> +#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 ed5dda01a60..13b9b0bb9de 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 <objc/NXConstStr.h> +#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 7bcabee5367..c715b2d822d 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 <objc/NXConstStr.h> +#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 cad481e15a0..430ab5db2d6 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 <objc/Object.h> +#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 29d9375bf7b..b07ac0f7842 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 <stdlib.h> /* 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 <string.h> 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 ca2df5a89ec..0eb2d6a01e0 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 <stdio.h> #include <stdlib.h> #include <string.h> -@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 76d3c9b0756..455b5f1bff1 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 <string.h> #include <stdlib.h> #ifndef __NEXT_RUNTIME__ #include <objc/NXConstStr.h> +#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 90e4db1e33c..030ba602db5 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 <string.h> #include <stdlib.h> #ifndef __NEXT_RUNTIME__ #include <objc/NXConstStr.h> +#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 ca08fed8d00..b08dfb242b3 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 <string.h> #include <stdlib.h> #ifndef __NEXT_RUNTIME__ #include <objc/NXConstStr.h> +#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 caa877e4de7..425ccc080ea 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 <string.h> #include <stdlib.h> #ifndef __NEXT_RUNTIME__ #include <objc/NXConstStr.h> +#else +#include "../../../objc-obj-c++-shared/nsconstantstring-class.h" #endif int main(int argc, void **args) |