[PATCH] Fix DW_AT_import for C++ using of a base type typedef (take 2)

Jakub Jelinek jakub@redhat.com
Fri Jul 3 11:52:00 GMT 2009


On Thu, Jul 02, 2009 at 01:57:05PM -0400, Jason Merrill wrote:
> On 07/02/2009 11:15 AM, Jakub Jelinek wrote:
>> On Thu, Jul 02, 2009 at 10:21:50AM -0400, Jason Merrill wrote:
>>> Testcase?
>
>> I just don't think it is easy enough to check for it using -g -dA
>> regexps, it is something for gdb testsuite instead.
>
> Fair enough.  Did you have a reaction to my other comment?

>From quick testing, seems you are right and all TYPE_DECLs should be
forcing the typedef.  And, CONST_DECLs were handled wrongly as well,
in the following testcase using A::F was treated basically as using
A::E.  Will do full bootstrap/regtest when VTA/trunk -ftime-report
comparison finishes.

// { dg-options "-g -O0 -dA" }

namespace A
{
  typedef int I;
  struct S { char c; };
  typedef struct S2 { char c; } T;
  const int c = 6;
  enum E { F = 4 };
  int v = 8;
}

int
main ()
{
  using A::I;
  using A::S;
  using A::T;
  using A::c;
  using A::F;
  using A::v;
  I i = 0;
  S s = { 0 };
  T t = { 0 };
  return i + s.c + t.c + c + F - v - 2;
}

Before patch:

(gdb) ptype I
No symbol "I" in current context.
(gdb) ptype S
type = struct A::S {
    char c;
}
(gdb) ptype T
type = struct A::S2 {
    char c;
}
(gdb) p c
$1 = 6
(gdb) p F
No symbol "F" in current context.
(gdb) p v
$2 = 8
(gdb) p (int) F
No symbol "F" in current context.

After patch:

(gdb) ptype I
type = int
(gdb) ptype S
type = struct A::S {
    char c;
}
(gdb) ptype T
type = struct A::S2 {
    char c;
}
(gdb) p c
$1 = 6
(gdb) p F
$2 = A::F
(gdb) p v
$3 = 8
(gdb) p (int) F
$4 = 4

2009-07-03  Jakub Jelinek  <jakub@redhat.com>

	* dwarf2out.c (dwarf2out_imported_module_or_decl_1): For TYPE_DECLs
	always call gen_typedef_die + lookup_type_die, for CONST_DECLs
	call lookup_decl_die.

--- gcc/dwarf2out.c.jj	2009-07-03 11:14:48.000000000 +0200
+++ gcc/dwarf2out.c	2009-07-03 13:21:41.000000000 +0200
@@ -13668,7 +13668,10 @@ gen_enumeration_type_die (tree type, dw_
 			      IDENTIFIER_POINTER (TREE_PURPOSE (link)));
 
 	  if (TREE_CODE (value) == CONST_DECL)
-	    value = DECL_INITIAL (value);
+	    {
+	      equate_decl_number_to_die (value, enum_die);
+	      value = DECL_INITIAL (value);
+	    }
 
 	  if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
 	    /* DWARF2 does not provide a way of indicating whether or
@@ -15850,22 +15853,17 @@ dwarf2out_imported_module_or_decl_1 (tre
   else
     xloc = expand_location (input_location);
 
-  if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
+  if (TREE_CODE (decl) == TYPE_DECL)
     {
-      if (is_base_type (TREE_TYPE (decl)))
-	at_import_die = base_type_die (TREE_TYPE (decl));
-      else
-	at_import_die = force_type_die (TREE_TYPE (decl));
-      /* For namespace N { typedef void T; } using N::T; base_type_die
-	 returns NULL, but DW_TAG_imported_declaration requires
-	 the DW_AT_import tag.  Force creation of DW_TAG_typedef.  */
+      gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
+      at_import_die = lookup_type_die (TREE_TYPE (decl));
+      gcc_assert (at_import_die);
+    }
+  else if (TREE_CODE (decl) == CONST_DECL)
+    {
+      at_import_die = lookup_decl_die (decl);
       if (!at_import_die)
-	{
-	  gcc_assert (TREE_CODE (decl) == TYPE_DECL);
-	  gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
-	  at_import_die = lookup_type_die (TREE_TYPE (decl));
-	  gcc_assert (at_import_die);
-	}
+	return;
     }
   else
     {


	Jakub



More information about the Gcc-patches mailing list