This makes it so that the Ada compiler emits named array types in the debug 
info (DW_TAG_typedef in DWARF) for array types declared in the sources.

Tested on i586-suse-linux, applied on the mainline.


2011-04-02  Eric Botcazou  <ebotca...@adacore.com>

        * gcc-interface/gigi.h (record_builtin_type): Add ARTIFICIAL_P param.
        * gcc-interface/utils.c (gnat_pushdecl): If this is a non-artificial
        declaration of an array type, then set DECL_ORIGINAL_TYPE to a distinct
        copy.
        (record_builtin_type): Add ARTIFICIAL_P parameter.  Set DECL_ARTIFICIAL
        flag of the type accordingly.
        * gcc-interface/trans.c (gigi): Adjust calls to record_builtin_type.


-- 
Eric Botcazou
Index: gcc-interface/utils.c
===================================================================
--- gcc-interface/utils.c	(revision 171818)
+++ gcc-interface/utils.c	(working copy)
@@ -508,7 +508,18 @@ gnat_pushdecl (tree decl, Node_Id gnat_n
       tree t = TREE_TYPE (decl);
 
       if (!(TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL))
-	;
+	{
+	  /* Array types aren't tagged types in the C sense so we force the
+	     type to be associated with its typedef in the DWARF back-end,
+	     in order to make sure that the latter is always preserved.  */
+	  if (!DECL_ARTIFICIAL (decl) && TREE_CODE (t) == ARRAY_TYPE)
+	    {
+	      tree tt = build_distinct_type_copy (t);
+	      TYPE_NAME (tt) = DECL_NAME (decl);
+	      TYPE_STUB_DECL (tt) = TYPE_STUB_DECL (t);
+	      DECL_ORIGINAL_TYPE (decl) = tt;
+	    }
+	}
       else if (TYPE_IS_FAT_POINTER_P (t))
 	{
 	  tree tt = build_variant_type_copy (t);
@@ -535,14 +546,15 @@ gnat_pushdecl (tree decl, Node_Id gnat_n
     }
 }
 
-/* Record TYPE as a builtin type for Ada.  NAME is the name of the type.  */
+/* Record TYPE as a builtin type for Ada.  NAME is the name of the type.
+   ARTIFICIAL_P is true if it's a type that was generated by the compiler.  */
 
 void
-record_builtin_type (const char *name, tree type)
+record_builtin_type (const char *name, tree type, bool artificial_p)
 {
   tree type_decl = build_decl (input_location,
 			       TYPE_DECL, get_identifier (name), type);
-
+  DECL_ARTIFICIAL (type_decl) = artificial_p;
   gnat_pushdecl (type_decl, Empty);
 
   if (debug_hooks->type_decl)
Index: gcc-interface/gigi.h
===================================================================
--- gcc-interface/gigi.h	(revision 171818)
+++ gcc-interface/gigi.h	(working copy)
@@ -504,8 +504,10 @@ extern void init_dummy_type (void);
 /* Make a dummy type corresponding to GNAT_TYPE.  */
 extern tree make_dummy_type (Entity_Id gnat_type);
 
-/* Record TYPE as a builtin type for Ada.  NAME is the name of the type.  */
-extern void record_builtin_type (const char *name, tree type);
+/* Record TYPE as a builtin type for Ada.  NAME is the name of the type.
+   ARTIFICIAL_P is true if it's a type that was generated by the compiler.  */
+extern void record_builtin_type (const char *name, tree type,
+				 bool artificial_p);
 
 /* Given a record type RECORD_TYPE and a list of FIELD_DECL nodes FIELD_LIST,
    finish constructing the record or union type.  If REP_LEVEL is zero, this
Index: gcc-interface/trans.c
===================================================================
--- gcc-interface/trans.c	(revision 171818)
+++ gcc-interface/trans.c	(working copy)
@@ -308,10 +308,10 @@ gigi (Node_Id gnat_root, int max_gnat_no
 
   /* Record the builtin types.  Define `integer' and `character' first so that
      dbx will output them first.  */
-  record_builtin_type ("integer", integer_type_node);
-  record_builtin_type ("character", unsigned_char_type_node);
-  record_builtin_type ("boolean", boolean_type_node);
-  record_builtin_type ("void", void_type_node);
+  record_builtin_type ("integer", integer_type_node, false);
+  record_builtin_type ("character", unsigned_char_type_node, false);
+  record_builtin_type ("boolean", boolean_type_node, false);
+  record_builtin_type ("void", void_type_node, false);
 
   /* Save the type we made for integer as the type for Standard.Integer.  */
   save_gnu_tree (Base_Type (standard_integer),
@@ -397,7 +397,7 @@ gigi (Node_Id gnat_root, int max_gnat_no
   jmpbuf_type
     = build_array_type (gnat_type_for_mode (Pmode, 0),
 			build_index_type (size_int (5)));
-  record_builtin_type ("JMPBUF_T", jmpbuf_type);
+  record_builtin_type ("JMPBUF_T", jmpbuf_type, true);
   jmpbuf_ptr_type = build_pointer_type (jmpbuf_type);
 
   /* Functions to get and set the jumpbuf pointer for the current thread.  */
@@ -552,7 +552,7 @@ gigi (Node_Id gnat_root, int max_gnat_no
 	}
 
       finish_record_type (fdesc_type_node, nreverse (field_list), 0, false);
-      record_builtin_type ("descriptor", fdesc_type_node);
+      record_builtin_type ("descriptor", fdesc_type_node, true);
       null_fdesc_node = gnat_build_constructor (fdesc_type_node, null_vec);
     }
 
@@ -566,7 +566,8 @@ gigi (Node_Id gnat_root, int max_gnat_no
       longest_float_type_node = make_node (REAL_TYPE);
       TYPE_PRECISION (longest_float_type_node) = LONG_DOUBLE_TYPE_SIZE;
       layout_type (longest_float_type_node);
-      record_builtin_type ("longest float type", longest_float_type_node);
+      record_builtin_type ("longest float type", longest_float_type_node,
+			   false);
     }
   else
     longest_float_type_node = TREE_TYPE (long_long_float_type);

Reply via email to