This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Ada PATCH] don't modify record fields in update_pointer_to
- From: Duncan Sands <baldrick at free dot fr>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Eric Botcazou <ebotcazou at adacore dot com>, Arnaud Charlet <charlet at adacore dot com>
- Date: Sat, 9 Jun 2007 15:44:22 +0200
- Subject: Re: [Ada PATCH] don't modify record fields in update_pointer_to
- References: <200702211356.45659.baldrick@free.fr> <200706072108.41693.ebotcazou@adacore.com> <200706072136.39339.baldrick@free.fr>
Hi Eric,
> > > I didn't find gnat_desig_equiv anywhere, and XUT is also built using
> > > gnat_desig_type. So I didn't make any changes here.
> >
> > Hum...
> >
> > TYPE_OBJECT_RECORD_TYPE (gnu_old) = make_node (RECORD_TYPE);
> > TYPE_NAME (TYPE_OBJECT_RECORD_TYPE (gnu_old))
> > = concat_id_with_name (get_entity_name (gnat_desig_equiv),
> > "XUT");
> > TYPE_DUMMY_P (TYPE_OBJECT_RECORD_TYPE (gnu_old)) = 1;
>
> I looked for gnat_desig_equiv on Tuesday - but it only went in on Wednesday
> (revision 125370)!
>
> > > The first line is redundant: the field already has this type. Just to be
> > > sure I added an assertion that this was true, and then bootstrapped and
> > > ran the ACATS and gnat test suites - the assertion never fired. You might
> > > also wonder why the second line is not redundant: that's because the array
> > > type was modified a few lines above (gnat_substitute_in_type).
> >
> > OK, a comment would not be superfluous then because that's not trivial.
>
> I will send you a new patch dealing with these issues in a day or two.
here you go: I changed to gnat_desig_equiv and added a bunch of comments
to update_pointer_to. Passes testing.
Ciao,
Duncan.
Index: gcc.fsf.master/gcc/ada/decl.c
===================================================================
--- gcc.fsf.master.orig/gcc/ada/decl.c 2007-06-08 22:35:01.000000000 +0200
+++ gcc.fsf.master/gcc/ada/decl.c 2007-06-09 11:32:31.000000000 +0200
@@ -3041,12 +3041,11 @@
&& ! Is_Constrained (gnat_desig_rep));
/* If we are pointing to an incomplete type whose completion is an
- unconstrained array, make a fat pointer type instead of a pointer
- to VOID. The two types in our fields will be pointers to VOID and
- will be replaced in update_pointer_to. Similarly, if the type
- itself is a dummy type or an unconstrained array. Also make
- a dummy TYPE_OBJECT_RECORD_TYPE in case we have any thin
- pointers to it. */
+ unconstrained array, make a fat pointer type. The two types in our
+ fields will be pointers to dummy nodes and will be replaced in
+ update_pointer_to. Similarly, if the type itself is a dummy type or
+ an unconstrained array. Also make a dummy TYPE_OBJECT_RECORD_TYPE
+ in case we have any thin pointers to it. */
if (is_unconstrained_array
&& (Present (gnat_desig_full)
@@ -3075,6 +3074,21 @@
gnu_type = TYPE_POINTER_TO (gnu_old);
if (!gnu_type)
{
+ tree gnu_template_type = make_node (ENUMERAL_TYPE);
+ tree gnu_ptr_template = build_pointer_type (gnu_template_type);
+ tree gnu_array_type = make_node (ENUMERAL_TYPE);
+ tree gnu_ptr_array = build_pointer_type (gnu_array_type);
+
+ TYPE_NAME (gnu_template_type)
+ = concat_id_with_name (get_entity_name (gnat_desig_equiv),
+ "XUB");
+ TYPE_DUMMY_P (gnu_template_type) = 1;
+
+ TYPE_NAME (gnu_array_type)
+ = concat_id_with_name (get_entity_name (gnat_desig_equiv),
+ "XUA");
+ TYPE_DUMMY_P (gnu_array_type) = 1;
+
gnu_type = make_node (RECORD_TYPE);
SET_TYPE_UNCONSTRAINED_ARRAY (gnu_type, gnu_old);
TYPE_POINTER_TO (gnu_old) = gnu_type;
@@ -3084,10 +3098,10 @@
= chainon (chainon (NULL_TREE,
create_field_decl
(get_identifier ("P_ARRAY"),
- ptr_void_type_node, gnu_type,
- 0, 0, 0, 0)),
+ gnu_ptr_array,
+ gnu_type, 0, 0, 0, 0)),
create_field_decl (get_identifier ("P_BOUNDS"),
- ptr_void_type_node,
+ gnu_ptr_template,
gnu_type, 0, 0, 0, 0));
/* Make sure we can place this into a register. */
Index: gcc.fsf.master/gcc/ada/trans.c
===================================================================
--- gcc.fsf.master.orig/gcc/ada/trans.c 2007-06-08 22:35:01.000000000 +0200
+++ gcc.fsf.master/gcc/ada/trans.c 2007-06-09 11:32:31.000000000 +0200
@@ -5201,19 +5201,6 @@
return GS_ALL_DONE;
}
- return GS_UNHANDLED;
-
- case COMPONENT_REF:
- /* We have a kludge here. If the FIELD_DECL is from a fat pointer and is
- from an early dummy type, replace it with the proper FIELD_DECL. */
- if (TYPE_FAT_POINTER_P (TREE_TYPE (TREE_OPERAND (*expr_p, 0)))
- && DECL_ORIGINAL_FIELD (TREE_OPERAND (*expr_p, 1)))
- {
- TREE_OPERAND (*expr_p, 1)
- = DECL_ORIGINAL_FIELD (TREE_OPERAND (*expr_p, 1));
- return GS_OK;
- }
-
/* ... fall through ... */
default:
Index: gcc.fsf.master/gcc/ada/utils.c
===================================================================
--- gcc.fsf.master.orig/gcc/ada/utils.c 2007-06-08 22:35:01.000000000 +0200
+++ gcc.fsf.master/gcc/ada/utils.c 2007-06-09 11:32:31.000000000 +0200
@@ -3160,29 +3160,28 @@
}
/* Now deal with the unconstrained array case. In this case the "pointer"
- is actually a RECORD_TYPE where the types of both fields are
- pointers to void. In that case, copy the field list from the
- old type to the new one and update the fields' context. */
+ is actually a RECORD_TYPE where both fields are pointers to dummy nodes.
+ Turn them into pointers to the correct types using update_pointer_to. */
else if (TREE_CODE (ptr) != RECORD_TYPE || !TYPE_IS_FAT_POINTER_P (ptr))
gcc_unreachable ();
else
{
tree new_obj_rec = TYPE_OBJECT_RECORD_TYPE (new_type);
- tree fields = TYPE_FIELDS (TYPE_POINTER_TO (new_type));
- tree new_fields, ptr_temp_type, new_ref, bounds, var;
-
- /* Replace contents of old pointer with those of new pointer. */
- new_fields = copy_node (fields);
- TREE_CHAIN (new_fields) = copy_node (TREE_CHAIN (fields));
-
- SET_DECL_ORIGINAL_FIELD (TYPE_FIELDS (ptr), new_fields);
- SET_DECL_ORIGINAL_FIELD (TREE_CHAIN (TYPE_FIELDS (ptr)),
- TREE_CHAIN (new_fields));
-
- TYPE_FIELDS (ptr) = new_fields;
- DECL_CONTEXT (new_fields) = ptr;
- DECL_CONTEXT (TREE_CHAIN (new_fields)) = ptr;
+ tree array_field = TYPE_FIELDS (ptr);
+ tree bounds_field = TREE_CHAIN (TYPE_FIELDS (ptr));
+ tree new_ptr = TYPE_POINTER_TO (new_type);
+ tree new_ref;
+ tree var;
+
+ /* Make pointers to the dummy template point to the real template. */
+ update_pointer_to
+ (TREE_TYPE (TREE_TYPE (bounds_field)),
+ TREE_TYPE (TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (new_ptr)))));
+
+ /* Replace new_ptr with ptr - replacing ptr with new_ptr is not
+ feasible. This means introducing a new array type since the
+ existing one uses new_ptr to reference the template bounds. */
/* Rework the PLACEHOLDER_EXPR inside the reference to the template
bounds and update the pointers to them.
@@ -3190,39 +3189,36 @@
??? This is now the only use of gnat_substitute_in_type, which
is now a very "heavy" routine to do this, so it should be replaced
at some point. */
- bounds = TREE_TYPE (TREE_TYPE (new_fields));
- ptr_temp_type = TREE_TYPE (TREE_CHAIN (new_fields));
- new_ref = build3 (COMPONENT_REF, ptr_temp_type,
+ new_ref = build3 (COMPONENT_REF, TREE_TYPE (bounds_field),
build0 (PLACEHOLDER_EXPR, ptr),
- TREE_CHAIN (new_fields), NULL_TREE);
- update_pointer_to (bounds,
- gnat_substitute_in_type (bounds,
- TREE_CHAIN (fields),
- new_ref));
+ bounds_field, NULL_TREE);
- for (var = TYPE_MAIN_VARIANT (ptr); var; var = TYPE_NEXT_VARIANT (var))
- {
- SET_TYPE_UNCONSTRAINED_ARRAY (var, new_type);
+ /* Create the new array type and update old array pointers. */
+ update_pointer_to
+ (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (new_ptr))),
+ gnat_substitute_in_type (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (new_ptr))),
+ TREE_CHAIN (TYPE_FIELDS (new_ptr)), new_ref));
+
+ /* Make pointers to the dummy array also point to the new array. */
+ update_pointer_to
+ (TREE_TYPE (TREE_TYPE (array_field)),
+ TREE_TYPE (TREE_TYPE (TYPE_FIELDS (new_ptr))));
- /* This may seem a bit gross, in particular wrt DECL_CONTEXT, but
- actually is in keeping with what build_qualified_type does. */
- TYPE_FIELDS (var) = new_fields;
- }
+ for (var = TYPE_MAIN_VARIANT (ptr); var; var = TYPE_NEXT_VARIANT (var))
+ SET_TYPE_UNCONSTRAINED_ARRAY (var, new_type);
TYPE_POINTER_TO (new_type) = TYPE_REFERENCE_TO (new_type)
= TREE_TYPE (new_type) = ptr;
/* Now handle updating the allocation record, what the thin pointer
points to. Update all pointers from the old record into the new
- one, update the types of the fields, and recompute the size. */
+ one, update the type of the array field, and recompute the size. */
update_pointer_to (TYPE_OBJECT_RECORD_TYPE (old_type), new_obj_rec);
- TREE_TYPE (TYPE_FIELDS (new_obj_rec))
- = TREE_TYPE (TREE_TYPE (TREE_CHAIN (new_fields)));
-
+ /* Use the newly created array type. */
TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (new_obj_rec)))
- = TREE_TYPE (TREE_TYPE (new_fields));
+ = TREE_TYPE (TREE_TYPE (array_field));
/* The size recomputation needs to account for alignment constraints, so
we let layout_type work it out. This will reset the field offsets to
Index: gcc.fsf.master/gcc/ada/ChangeLog
===================================================================
--- gcc.fsf.master.orig/gcc/ada/ChangeLog 2007-06-08 22:35:01.000000000 +0200
+++ gcc.fsf.master/gcc/ada/ChangeLog 2007-06-09 11:32:32.000000000 +0200
@@ -1,3 +1,11 @@
+2007-06-09 Duncan Sands <baldrick@free.fr>
+
+ * decl.c (gnat_to_gnu_entity): Use pointers to dummy nodes, rather than
+ void*, for the fields when making a new fat pointer type.
+ * trans.c (gnat_gimplify_expr): Remove COMPONENT_REF kludge.
+ * utils.c (update_pointer_to): Update fat pointers by updating the dummy
+ node pointers used for the fields.
+
2007-06-06 Thomas Quinot <quinot@adacore.com>
Bob Duff <duff@adacore.com>