This patch is for the google/gcc-4_7 branch. Backport upstream patch to fix a problem where type signature does not include the type's context.
Tested with bootstrap and regression tests. 2012-07-19 Jason Merrill <ja...@redhat.com> PR debug/53235 * dwarf2out.c (get_die_parent): New. (generate_type_signature): Use it. Index: gcc/testsuite/g++.dg/debug/dwarf2/nested-4.C =================================================================== --- gcc/testsuite/g++.dg/debug/dwarf2/nested-4.C (revision 0) +++ gcc/testsuite/g++.dg/debug/dwarf2/nested-4.C (revision 0) @@ -0,0 +1,14 @@ +// PR debug/53235 +// { dg-options "-gdwarf-4" } +// { dg-final { scan-assembler-times "debug_types" 2 } } + +namespace E { + class O {}; + void f (O o) {} +} +namespace F { + class O {}; + void f (O fo) {} +} +E::O eo; +int main () {} Index: gcc/dwarf2out.c =================================================================== --- gcc/dwarf2out.c (revision 190940) +++ gcc/dwarf2out.c (working copy) @@ -5066,6 +5066,23 @@ get_AT (dw_die_ref die, enum dwarf_attri return NULL; } +/* Returns the parent of the declaration of DIE. */ + +static dw_die_ref +get_die_parent (dw_die_ref die) +{ + dw_die_ref t; + + if (!die) + return NULL; + + if ((t = get_AT_ref (die, DW_AT_abstract_origin)) + || (t = get_AT_ref (die, DW_AT_specification))) + die = t; + + return die->die_parent; +} + /* Return the "low pc" attribute value, typically associated with a subprogram DIE. Return null if the "low pc" attribute is either not present, or if it cannot be represented as an assembler label identifier. */ @@ -6698,9 +6715,11 @@ generate_type_signature (dw_die_ref die, unsigned char checksum[16]; struct md5_ctx ctx; dw_die_ref decl; + dw_die_ref parent; name = get_AT_string (die, DW_AT_name); decl = get_AT_ref (die, DW_AT_specification); + parent = get_die_parent (die); /* First, compute a signature for just the type name (and its surrounding context, if any. This is stored in the type unit DIE for link-time @@ -6711,8 +6730,8 @@ generate_type_signature (dw_die_ref die, md5_init_ctx (&ctx); /* Checksum the names of surrounding namespaces and structures. */ - if (decl != NULL && decl->die_parent != NULL) - checksum_die_context (decl->die_parent, &ctx); + if (parent != NULL) + checksum_die_context (parent, &ctx); md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx); md5_process_bytes (name, strlen (name) + 1, &ctx); @@ -6728,8 +6747,8 @@ generate_type_signature (dw_die_ref die, die->die_mark = mark; /* Checksum the names of surrounding namespaces and structures. */ - if (decl != NULL && decl->die_parent != NULL) - checksum_die_context (decl->die_parent, &ctx); + if (parent != NULL) + checksum_die_context (parent, &ctx); /* Checksum the DIE and its children. */ die_checksum_ordered (die, &ctx, &mark);