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]

Re: debug/2971: Type of variable is wrong in dwarf2 debugging info


Here's the patch promised in the PR.  I don't think I completely
understand the comment about recursive types.  It suggests that this
patch might break those, but if so, I'm pretty sure they were broken
anyway.

I've made qualified_type a register variable, since I guess it
deserves it if item_type deserves it.

Mark


Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	* dwarf2out.c (modified_type_die): Reorganize somewhat.  Return
	NULL if type is ERROR_MARK.  Only call equate_type_number_to_die
	if an appropriately qualified variant of TYPE already exists.

Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/dwarf2out.c,v
retrieving revision 1.242.2.18
diff -u -p -r1.242.2.18 dwarf2out.c
--- dwarf2out.c 2001/05/21 23:29:41 1.242.2.18
+++ dwarf2out.c 2001/05/27 10:20:36
@@ -6890,113 +6890,107 @@ modified_type_die (type, is_const_type, 
      register dw_die_ref context_die;
 {
   register enum tree_code code = TREE_CODE (type);
+  register tree qualified_type;
   register dw_die_ref mod_type_die = NULL;
   register dw_die_ref sub_die = NULL;
   register tree item_type = NULL;
 
-  if (code != ERROR_MARK)
+  if (code == ERROR_MARK)
+    return NULL;
+
+  /* See if we already have the appropriately qualified variant of
+     this type.  */
+  qualified_type = get_qualified_type (type,
+				       ((is_const_type ? TYPE_QUAL_CONST : 0)
+					| (is_volatile_type 
+					   ? TYPE_QUAL_VOLATILE : 0)));
+  /* If we do, then we can just use its DIE, if it exists.  */
+  if (qualified_type)
     {
-      tree qualified_type;
+      mod_type_die = lookup_type_die (qualified_type);
+      if (mod_type_die)
+	return mod_type_die;
+    }
 
-      /* See if we already have the appropriately qualified variant of
-	 this type.  */
-      qualified_type 
-	= get_qualified_type (type,
-			      ((is_const_type ? TYPE_QUAL_CONST : 0)
-			       | (is_volatile_type 
-				  ? TYPE_QUAL_VOLATILE : 0)));
-      /* If we do, then we can just use its DIE, if it exists.  */
-      if (qualified_type)
+  /* Handle C typedef types.  */
+  if (qualified_type && TYPE_NAME (qualified_type) 
+      && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
+      && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
+    {
+      tree type_name = TYPE_NAME (qualified_type);
+      tree dtype = TREE_TYPE (type_name);
+      if (qualified_type == dtype)
 	{
+	  /* For a named type, use the typedef.  */
+	  gen_type_die (qualified_type, context_die);
 	  mod_type_die = lookup_type_die (qualified_type);
-	  if (mod_type_die)
-	    return mod_type_die;
 	}
 
-      /* Handle C typedef types.  */
-      if (qualified_type && TYPE_NAME (qualified_type) 
-	  && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
-	  && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
-	{
-	  tree type_name = TYPE_NAME (qualified_type);
-	  tree dtype = TREE_TYPE (type_name);
-	  if (qualified_type == dtype)
-	    {
-	      /* For a named type, use the typedef.  */
-	      gen_type_die (qualified_type, context_die);
-	      mod_type_die = lookup_type_die (qualified_type);
-	    }
-
-	  else if (is_const_type < TYPE_READONLY (dtype)
-		   || is_volatile_type < TYPE_VOLATILE (dtype))
-	    /* cv-unqualified version of named type.  Just use the unnamed
-	       type to which it refers.  */
-	    mod_type_die
-	      = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
-				   is_const_type, is_volatile_type,
-				   context_die);
-	  /* Else cv-qualified version of named type; fall through.  */
-	}
+      else if (is_const_type < TYPE_READONLY (dtype)
+	       || is_volatile_type < TYPE_VOLATILE (dtype))
+	/* cv-unqualified version of named type.  Just use the unnamed
+	   type to which it refers.  */
+	mod_type_die = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
+					  is_const_type, is_volatile_type,
+					  context_die);
+      /* Else cv-qualified version of named type; fall through.  */
+    }
 
-      if (mod_type_die)
-	/* OK.  */
-	;
-      else if (is_const_type)
-	{
-	  mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
-	  sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
-	}
-      else if (is_volatile_type)
-	{
-	  mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
-	  sub_die = modified_type_die (type, 0, 0, context_die);
-	}
-      else if (code == POINTER_TYPE)
-	{
-	  mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
-	  add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
+  if (mod_type_die)
+    /* OK.  */
+    ;
+  else if (is_const_type)
+    {
+      mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
+      sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
+    }
+  else if (is_volatile_type)
+    {
+      mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
+      sub_die = modified_type_die (type, 0, 0, context_die);
+    }
+  else if (code == POINTER_TYPE)
+    {
+      mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
+      add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
 #if 0
-	  add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
+      add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
 #endif
-	  item_type = TREE_TYPE (type);
-	}
-      else if (code == REFERENCE_TYPE)
-	{
-	  mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
-	  add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
+      item_type = TREE_TYPE (type);
+    }
+  else if (code == REFERENCE_TYPE)
+    {
+      mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
+      add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
 #if 0
-	  add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
+      add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
 #endif
-	  item_type = TREE_TYPE (type);
-	}
-      else if (is_base_type (type))
-	mod_type_die = base_type_die (type);
-      else
-	{
-	  gen_type_die (type, context_die);
-
-	  /* We have to get the type_main_variant here (and pass that to the
-	     `lookup_type_die' routine) because the ..._TYPE node we have
-	     might simply be a *copy* of some original type node (where the
-	     copy was created to help us keep track of typedef names) and
-	     that copy might have a different TYPE_UID from the original
-	     ..._TYPE node.  */
-	  mod_type_die = lookup_type_die (type_main_variant (type));
-	  if (mod_type_die == NULL)
-	    abort ();
-	}
+      item_type = TREE_TYPE (type);
+    }
+  else if (is_base_type (type))
+    mod_type_die = base_type_die (type);
+  else
+    {
+      gen_type_die (type, context_die);
 
-      /* We want to equate the qualified type to the die below.  */
-      if (qualified_type)
-	type = qualified_type;
+      /* We have to get the type_main_variant here (and pass that to
+	 the `lookup_type_die' routine) because the ..._TYPE node we
+	 have might simply be a *copy* of some original type node
+	 (where the copy was created to help us keep track of typedef
+	 names) and that copy might have a different TYPE_UID from the
+	 original ..._TYPE node.  */
+      mod_type_die = lookup_type_die (type_main_variant (type));
+      if (mod_type_die == NULL)
+	abort ();
     }
 
-  equate_type_number_to_die (type, mod_type_die);
+  if (qualified_type)
+    equate_type_number_to_die (qualified_type, mod_type_die);
   if (item_type)
-    /* We must do this after the equate_type_number_to_die call, in case
-       this is a recursive type.  This ensures that the modified_type_die
-       recursion will terminate even if the type is recursive.  Recursive
-       types are possible in Ada.  */
+    /* We must do this after the equate_type_number_to_die call, in
+       case this is a recursive type.  This ensures that the
+       modified_type_die recursion will terminate even if the type is
+       recursive.  Recursive types are possible in Ada.  */
     sub_die = modified_type_die (item_type,
 				 TYPE_READONLY (item_type),
 				 TYPE_VOLATILE (item_type),


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