[RFA] dwarf2out.c - subrange_type cleanup

Joel Brobecker brobecker@gnat.com
Thu Jan 15 08:43:00 GMT 2004


Hello,

this is the second cleanup patch to dwarf2out.c wrt subrange_type DIEs
emission. This is a followup on:

    http://gcc.gnu.org/ml/gcc-patches/2004-01/msg00693.html

We decided to explore the possibility of removing the checks for
  - TYPE_NAME
  - TREE_UNSIGNED
  - is_ada

In a previous patch, I first removed the check for TYPE_NAME. This
patch now removes the checks for is_ada() and TYPE_UNSIGNED.

I have sent a patch to gdb-patches adding support for subrange_type
DIEs: http://sources.redhat.com/ml/gdb-patches/2004-01/msg00380.html.
It might be wiser to wait for the GDB patch to be applied before this
GCC patch goes in (but the change can still be reviewed anytime, though :)

2004-01-15  J. Brobecker  <brobecker at gnat dot com>

        * dwarf2out.c (is_subrange_type): Renamed from is_ada_subrange_type().
        Remove checks for is_ada() and TREE_UNSIGNED.
        (subrange_type_die): Emit a byte_size attribute if the subrange
        type size is different from the base type size.
        (modified_type_die): Replace call to is_ada_subrange_type() by
        call to is_subrange_type().

Bootstrapped on x86-linux, and tested against the testsuite and the
GDB testsuite (GDB was built with the patch I mentionned above).

OK to apply?

Thanks,
-- 
Joel
-------------- next part --------------
Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2out.c,v
retrieving revision 1.475
diff -u -p -r1.475 dwarf2out.c
--- dwarf2out.c	14 Jan 2004 21:12:02 -0000	1.475
+++ dwarf2out.c	15 Jan 2004 06:58:13 -0000
@@ -3703,7 +3703,7 @@ static void output_file_names (void);
 static dw_die_ref base_type_die (tree);
 static tree root_type (tree);
 static int is_base_type (tree);
-static bool is_ada_subrange_type (tree);
+static bool is_subrange_type (tree);
 static dw_die_ref subrange_type_die (tree, dw_die_ref);
 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
 static int type_is_enum (tree);
@@ -7812,24 +7812,14 @@ simple_type_size_in_bits (tree type)
    emitted as a subrange type.  */
 
 static inline bool
-is_ada_subrange_type (tree type)
+is_subrange_type (tree type)
 {
-  /* We should use a subrange type in the following situations:
-     - For Ada modular types: These types are stored as integer subtypes
-       of an unsigned integer type;
-     - For subtypes of an Ada enumeration type: These types are stored
-       as integer subtypes of enumeral types.
-     
-     This subrange type is mostly for the benefit of debugger users.
-     A nameless type would therefore not be very useful, so no need
-     to generate a subrange type in these cases.  */
   tree subtype = TREE_TYPE (type);
 
-  if (is_ada ()
-      && TREE_CODE (type) == INTEGER_TYPE
+  if (TREE_CODE (type) == INTEGER_TYPE
       && subtype != NULL_TREE)
     {
-      if (TREE_CODE (subtype) == INTEGER_TYPE && TREE_UNSIGNED (subtype))
+      if (TREE_CODE (subtype) == INTEGER_TYPE)
         return true;
       if (TREE_CODE (subtype) == ENUMERAL_TYPE)
         return true;
@@ -7846,6 +7836,7 @@ subrange_type_die (tree type, dw_die_ref
   dw_die_ref subtype_die;
   dw_die_ref subrange_die;
   tree name = TYPE_NAME (type);
+  const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
 
   if (context_die == NULL)
     context_die = comp_unit_die;
@@ -7864,6 +7855,13 @@ subrange_type_die (tree type, dw_die_ref
       add_name_attribute (subrange_die, IDENTIFIER_POINTER (name));
     }
 
+  if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
+    {
+      /* The size of the subrange type and its base type do not match,
+         so we need to generate a size attribute for the subrange type.  */
+      add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
+    }
+
   if (TYPE_MIN_VALUE (type) != NULL)
     add_bound_info (subrange_die, DW_AT_lower_bound,
                     TYPE_MIN_VALUE (type));
@@ -7966,7 +7964,7 @@ modified_type_die (tree type, int is_con
 #endif
 	  item_type = TREE_TYPE (type);
 	}
-      else if (is_ada_subrange_type (type))
+      else if (is_subrange_type (type))
         mod_type_die = subrange_type_die (type, context_die);
       else if (is_base_type (type))
 	mod_type_die = base_type_die (type);


More information about the Gcc-patches mailing list