This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Ada PATCH] don't modify record fields in update_pointer_to


Hi Eric,

> Unfortunately the FSF mainline code is somewhat outdated wrt to dummy nodes 
> and fat-pointer types, so I'm not sure your patch will still work once they 
> are again synchronized with that of AdaCore.

I rediffed it against the current tree, and added a Changelog entry.  It still
works, bootstraps and passes all tests.  It fixes the dwarf2 debug info problem
described in http://gcc.gnu.org/ml/gcc-patches/2007-04/msg00542.html, as well as
eliminating the problem that constructors and component refs can contain fields
from the original fat pointer even after the fat pointer is updated.  It is also
a simplification, in that it updates fat pointers using the standard dummy node
mechanism.

Please consider applying.

Best wishes,

Duncan.
Index: gcc.fsf.master/gcc/ada/decl.c
===================================================================
--- gcc.fsf.master.orig/gcc/ada/decl.c	2007-04-10 16:05:45.000000000 +0200
+++ gcc.fsf.master/gcc/ada/decl.c	2007-04-30 23:23:50.000000000 +0200
@@ -3006,8 +3006,8 @@
 
 	/* 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
+	   to VOID.  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.  */
@@ -3053,6 +3053,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_type),
+					 "XUB");
+		TYPE_DUMMY_P (gnu_template_type) = 1;
+
+		TYPE_NAME (gnu_array_type)
+		  = concat_id_with_name (get_entity_name (gnat_desig_type),
+					 "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;
@@ -3062,10 +3077,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-04-12 23:53:09.000000000 +0200
+++ gcc.fsf.master/gcc/ada/trans.c	2007-04-30 11:49:41.000000000 +0200
@@ -4908,19 +4908,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-04-10 16:05:43.000000000 +0200
+++ gcc.fsf.master/gcc/ada/utils.c	2007-04-30 23:29:18.000000000 +0200
@@ -2953,20 +2953,15 @@
   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;
+
+      update_pointer_to
+	(TREE_TYPE (TREE_TYPE (bounds_field)),
+	 TREE_TYPE (TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (new_ptr)))));
 
       /* Rework the PLACEHOLDER_EXPR inside the reference to the template
 	 bounds and update the pointers to them.
@@ -2974,24 +2969,21 @@
 	 ??? 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);
+      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));
+
+      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;
@@ -3002,13 +2994,12 @@
 
       update_pointer_to (TYPE_OBJECT_RECORD_TYPE (old_type), new_obj_rec);
 
-      TREE_TYPE (TYPE_FIELDS (new_obj_rec)) = TREE_TYPE (ptr_temp_type);
       TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (new_obj_rec)))
-	= TREE_TYPE (TREE_TYPE (new_fields));
+	= TREE_TYPE (TREE_TYPE (array_field));
       DECL_SIZE (TREE_CHAIN (TYPE_FIELDS (new_obj_rec)))
-	= TYPE_SIZE (TREE_TYPE (TREE_TYPE (new_fields)));
+	= TYPE_SIZE (TREE_TYPE (TREE_TYPE (array_field)));
       DECL_SIZE_UNIT (TREE_CHAIN (TYPE_FIELDS (new_obj_rec)))
-	= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (new_fields)));
+	= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (array_field)));
 
       TYPE_SIZE (new_obj_rec)
 	= size_binop (PLUS_EXPR,
Index: gcc.fsf.master/gcc/ada/ChangeLog
===================================================================
--- gcc.fsf.master.orig/gcc/ada/ChangeLog	2007-04-30 23:09:30.000000000 +0200
+++ gcc.fsf.master/gcc/ada/ChangeLog	2007-04-30 23:32:04.000000000 +0200
@@ -1,3 +1,11 @@
+2007-04-30  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-04-22  Andrew Pinski  <andrew_pinski@playstation.sony.com>
 
 	PR ada/31660

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]