diff options
author | zlaski <zlaski@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-06-29 21:01:29 +0000 |
---|---|---|
committer | zlaski <zlaski@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-06-29 21:01:29 +0000 |
commit | 0616a9489ecf745db46e0c0cc886e602782b6c05 (patch) | |
tree | 6eb42b09d8fffee909d4e2a323a1040fbd7da55c | |
parent | 20e8f94aec029aa6191e559427d50255e67af01f (diff) | |
download | gcc-0616a9489ecf745db46e0c0cc886e602782b6c05.tar.gz |
[gcc/ChangeLog]
2005-06-29 Ziemowit Laski <zlaski@apple.com>
* config/darwin.c (machopic_select_section): constant ObjC string
objects now always have type "__builtin_ObjCString".
[gcc/objc/ChangeLog]
2005-06-29 Ziemowit Laski <zlaski@apple.com>
* objc-act.c (objc_build_internal_const_str_type): New function.
(check_string_class_template): Use objc_get_class_ivars() instead
of TYPE_FIELDS() to retrieve ivar list.
(AT_LEAST_AS_LARGE_AS): Check the size of each field's type rather
than the field itself.
(objc_build_string_object): Synthesize a "__builtin_ObjCString"
type and use it to lay out compile-time string objects.
* objc-act.h (OCTI_INTERNAL_CNST_STR_TYPE, internal_const_str_type):
New.
[gcc/testsuite/ChangeLog]
2005-06-29 Ziemowit Laski <zlaski@apple.com>
* obj-c++.dg/const-str-1[0-1].mm: New.
* objc.dg/const-str-1[0-1].m: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@101437 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/config/darwin.c | 12 | ||||
-rw-r--r-- | gcc/objc/ChangeLog | 12 | ||||
-rw-r--r-- | gcc/objc/objc-act.c | 45 | ||||
-rw-r--r-- | gcc/objc/objc-act.h | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/const-str-10.mm | 28 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/const-str-11.mm | 27 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/const-str-10.m | 28 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/const-str-11.m | 27 |
10 files changed, 176 insertions, 15 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9bf9bc22cd0..ed408afbd1a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2005-06-29 Ziemowit Laski <zlaski@apple.com> + + * config/darwin.c (machopic_select_section): constant ObjC string + objects now always have type "__builtin_ObjCString". + 2005-06-29 Richard Henderson <rth@redhat.com> * config/alpha/alpha.md (vec_shl_<VEC>, vec_shr_<VEC>): New. diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 13de45f74a5..cac61e403c9 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -1048,10 +1048,14 @@ machopic_select_section (tree exp, int reloc, tree name = TYPE_NAME (TREE_TYPE (exp)); if (TREE_CODE (name) == TYPE_DECL) name = DECL_NAME (name); - if (!strcmp (IDENTIFIER_POINTER (name), "NSConstantString")) - objc_constant_string_object_section (); - else if (!strcmp (IDENTIFIER_POINTER (name), "NXConstantString")) - objc_string_object_section (); + + if (!strcmp (IDENTIFIER_POINTER (name), "__builtin_ObjCString")) + { + if (flag_next_runtime) + objc_constant_string_object_section (); + else + objc_string_object_section (); + } else base_function (); } diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 52325f4b70a..a11966ea7af 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,3 +1,15 @@ +2005-06-29 Ziemowit Laski <zlaski@apple.com> + + * objc-act.c (objc_build_internal_const_str_type): New function. + (check_string_class_template): Use objc_get_class_ivars() instead + of TYPE_FIELDS() to retrieve ivar list. + (AT_LEAST_AS_LARGE_AS): Check the size of each field's type rather + than the field itself. + (objc_build_string_object): Synthesize a "__builtin_ObjCString" + type and use it to lay out compile-time string objects. + * objc-act.h (OCTI_INTERNAL_CNST_STR_TYPE, internal_const_str_type): + New. + 2005-06-28 Paul Brook <paul@codesourcery.com> * objc-act.c (objc_init_exceptions): Call diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index d4c20a87ec9..b522b8ddba6 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -814,9 +814,9 @@ objc_build_struct (tree name, tree fields, tree super_name) && TREE_CODE (TREE_CHAIN (field)) == FIELD_DECL) field = TREE_CHAIN (field); - /* For ObjC ABI purposes, the "packed" size of a base class is - the the sum of the offset and the size (in bits) of the last - field in the class. */ + /* For ObjC ABI purposes, the "packed" size of a base class is the + the sum of the offset and the size (in bits) of the last field + in the class. */ DECL_SIZE (base) = (field && TREE_CODE (field) == FIELD_DECL ? size_binop (PLUS_EXPR, @@ -1707,11 +1707,11 @@ synth_module_prologue (void) static int check_string_class_template (void) { - tree field_decl = TYPE_FIELDS (constant_string_type); + tree field_decl = objc_get_class_ivars (constant_string_id); #define AT_LEAST_AS_LARGE_AS(F, T) \ (F && TREE_CODE (F) == FIELD_DECL \ - && (TREE_INT_CST_LOW (DECL_SIZE (F)) \ + && (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (F))) \ >= TREE_INT_CST_LOW (TYPE_SIZE (T)))) if (!AT_LEAST_AS_LARGE_AS (field_decl, ptr_type_node)) @@ -1730,6 +1730,27 @@ check_string_class_template (void) /* Avoid calling `check_string_class_template ()' more than once. */ static GTY(()) int string_layout_checked; +/* Construct an internal string layout to be used as a template for + creating NSConstantString/NXConstantString instances. */ + +static tree +objc_build_internal_const_str_type (void) +{ + tree type = (*lang_hooks.types.make_type) (RECORD_TYPE); + tree fields = build_decl (FIELD_DECL, NULL_TREE, ptr_type_node); + tree field = build_decl (FIELD_DECL, NULL_TREE, ptr_type_node); + + TREE_CHAIN (field) = fields; fields = field; + field = build_decl (FIELD_DECL, NULL_TREE, unsigned_type_node); + TREE_CHAIN (field) = fields; fields = field; + /* NB: The finish_builtin_struct() routine expects FIELD_DECLs in + reverse order! */ + finish_builtin_struct (type, "__builtin_ObjCString", + fields, NULL_TREE); + + return type; +} + /* Custom build_string which sets TREE_TYPE! */ static tree @@ -1802,6 +1823,7 @@ objc_build_string_object (tree string) { string_layout_checked = -1; constant_string_class = lookup_interface (constant_string_id); + internal_const_str_type = objc_build_internal_const_str_type (); if (!constant_string_class || !(constant_string_type @@ -1838,9 +1860,9 @@ objc_build_string_object (tree string) *loc = desc = ggc_alloc (sizeof (*desc)); desc->literal = string; - /* GNU: & ((NXConstantString) { NULL, string, length }) */ - /* NeXT: & ((NSConstantString) { isa, string, length }) */ - fields = TYPE_FIELDS (constant_string_type); + /* GNU: (NXConstantString *) & ((__builtin_ObjCString) { NULL, string, length }) */ + /* NeXT: (NSConstantString *) & ((__builtin_ObjCString) { isa, string, length }) */ + fields = TYPE_FIELDS (internal_const_str_type); initlist = build_tree_list (fields, flag_next_runtime @@ -1852,13 +1874,13 @@ objc_build_string_object (tree string) fields = TREE_CHAIN (fields); initlist = tree_cons (fields, build_int_cst (NULL_TREE, length), initlist); - constructor = objc_build_constructor (constant_string_type, + constructor = objc_build_constructor (internal_const_str_type, nreverse (initlist)); TREE_INVARIANT (constructor) = true; if (!flag_next_runtime) constructor - = objc_add_static_instance (constructor, constant_string_type); + = objc_add_static_instance (constructor, internal_const_str_type); else { var = build_decl (CONST_DECL, NULL, TREE_TYPE (constructor)); @@ -1870,7 +1892,8 @@ objc_build_string_object (tree string) desc->constructor = constructor; } - addr = build_unary_op (ADDR_EXPR, desc->constructor, 1); + addr = convert (build_pointer_type (constant_string_type), + build_unary_op (ADDR_EXPR, desc->constructor, 1)); return addr; } diff --git a/gcc/objc/objc-act.h b/gcc/objc/objc-act.h index 8d32e962109..dc62862673a 100644 --- a/gcc/objc/objc-act.h +++ b/gcc/objc/objc-act.h @@ -263,6 +263,7 @@ enum objc_tree_index OCTI_CNST_STR_TYPE, OCTI_CNST_STR_GLOB_ID, OCTI_STRING_CLASS_DECL, + OCTI_INTERNAL_CNST_STR_TYPE, OCTI_SUPER_DECL, OCTI_UMSG_NONNIL_DECL, OCTI_UMSG_NONNIL_STRET_DECL, @@ -450,6 +451,7 @@ extern GTY(()) tree objc_global_trees[OCTI_MAX]; #define constant_string_global_id \ objc_global_trees[OCTI_CNST_STR_GLOB_ID] #define string_class_decl objc_global_trees[OCTI_STRING_CLASS_DECL] +#define internal_const_str_type objc_global_trees[OCTI_INTERNAL_CNST_STR_TYPE] #define UOBJC_SUPER_decl objc_global_trees[OCTI_SUPER_DECL] #endif /* GCC_OBJC_ACT_H */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0c5663fdf6e..0ba3b14ba23 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-06-29 Ziemowit Laski <zlaski@apple.com> + + * obj-c++.dg/const-str-1[0-1].mm: New. + * objc.dg/const-str-1[0-1].m: New. + 2005-05-29 Richard Henderson <rth@redhat.com> * lib/target-supports.exp (check_effective_target_vect_no_int_max): diff --git a/gcc/testsuite/obj-c++.dg/const-str-10.mm b/gcc/testsuite/obj-c++.dg/const-str-10.mm new file mode 100644 index 00000000000..4efe044c13e --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-10.mm @@ -0,0 +1,28 @@ +/* Test if ObjC constant string layout is checked properly, regardless of how + constant string classes get derived. */ +/* Contributed by Ziemowit Laski <zlaski@apple.com> */ + +/* { dg-options "-fnext-runtime" } */ +/* { dg-do compile { target *-*-darwin* } } */ + +#include <objc/Object.h> + +@interface NSString: Object +@end + +@interface NSSimpleCString : NSString { +@protected + char *bytes; + unsigned int numBytes; +} +@end + +@interface NSConstantString : NSSimpleCString +@end + +extern struct objc_class _NSConstantStringClassReference; + +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" } } */ diff --git a/gcc/testsuite/obj-c++.dg/const-str-11.mm b/gcc/testsuite/obj-c++.dg/const-str-11.mm new file mode 100644 index 00000000000..3b7ec7ad51f --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/const-str-11.mm @@ -0,0 +1,27 @@ +/* Test if ObjC constant string layout is checked properly, regardless of how + constant string classes get derived. */ +/* Contributed by Ziemowit Laski <zlaski@apple.com> */ + +/* { dg-options "-fnext-runtime -fconstant-string-class=XStr" } */ +/* { dg-do compile { target *-*-darwin* } } */ + +#include <objc/Object.h> + +@interface XString: Object { +@protected + char *bytes; +} +@end + +@interface XStr : XString { +@public + unsigned int len; +} +@end + +extern struct objc_class _XStrClassReference; + +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" } } */ diff --git a/gcc/testsuite/objc.dg/const-str-10.m b/gcc/testsuite/objc.dg/const-str-10.m new file mode 100644 index 00000000000..4efe044c13e --- /dev/null +++ b/gcc/testsuite/objc.dg/const-str-10.m @@ -0,0 +1,28 @@ +/* Test if ObjC constant string layout is checked properly, regardless of how + constant string classes get derived. */ +/* Contributed by Ziemowit Laski <zlaski@apple.com> */ + +/* { dg-options "-fnext-runtime" } */ +/* { dg-do compile { target *-*-darwin* } } */ + +#include <objc/Object.h> + +@interface NSString: Object +@end + +@interface NSSimpleCString : NSString { +@protected + char *bytes; + unsigned int numBytes; +} +@end + +@interface NSConstantString : NSSimpleCString +@end + +extern struct objc_class _NSConstantStringClassReference; + +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" } } */ diff --git a/gcc/testsuite/objc.dg/const-str-11.m b/gcc/testsuite/objc.dg/const-str-11.m new file mode 100644 index 00000000000..3b7ec7ad51f --- /dev/null +++ b/gcc/testsuite/objc.dg/const-str-11.m @@ -0,0 +1,27 @@ +/* Test if ObjC constant string layout is checked properly, regardless of how + constant string classes get derived. */ +/* Contributed by Ziemowit Laski <zlaski@apple.com> */ + +/* { dg-options "-fnext-runtime -fconstant-string-class=XStr" } */ +/* { dg-do compile { target *-*-darwin* } } */ + +#include <objc/Object.h> + +@interface XString: Object { +@protected + char *bytes; +} +@end + +@interface XStr : XString { +@public + unsigned int len; +} +@end + +extern struct objc_class _XStrClassReference; + +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" } } */ |