summaryrefslogtreecommitdiff
path: root/gcc/objc/objc-act.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/objc/objc-act.c')
-rw-r--r--gcc/objc/objc-act.c45
1 files changed, 34 insertions, 11 deletions
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;
}