From patchwork Tue Jun 22 00:06:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cary Coutant X-Patchwork-Id: 56383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 966CFB6EEE for ; Tue, 22 Jun 2010 10:07:26 +1000 (EST) Received: (qmail 916 invoked by alias); 22 Jun 2010 00:07:04 -0000 Received: (qmail 849 invoked by uid 22791); 22 Jun 2010 00:06:54 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_GD, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Jun 2010 00:06:49 +0000 Received: from wpaz33.hot.corp.google.com (wpaz33.hot.corp.google.com [172.24.198.97]) by smtp-out.google.com with ESMTP id o5M06jja007349 for ; Mon, 21 Jun 2010 17:06:46 -0700 Received: from gwb11 (gwb11.prod.google.com [10.200.2.11]) by wpaz33.hot.corp.google.com with ESMTP id o5M06Shq007568 for ; Mon, 21 Jun 2010 17:06:44 -0700 Received: by gwb11 with SMTP id 11so1364637gwb.16 for ; Mon, 21 Jun 2010 17:06:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.48.40 with SMTP id v40mr5285666ybv.232.1277165204385; Mon, 21 Jun 2010 17:06:44 -0700 (PDT) Received: by 10.150.93.20 with HTTP; Mon, 21 Jun 2010 17:06:44 -0700 (PDT) Date: Mon, 21 Jun 2010 17:06:44 -0700 Message-ID: Subject: [patch] Fix two bugs with -gdwarf-4 From: Cary Coutant To: gcc-patches Cc: Jim Wilson , Jason Merrill X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch fixes a couple of bugs with -gdwarf-4. One is an ICE that occurs when there's a particular kind of local typedef in a member function, and the other caused an unsatisfied reference at link time caused by moving a locally-scoped type into a type unit. Bootstrapped and tested on x86_64. OK? -cary gcc/ChangeLog: * dwarf2out.c (is_nested_in_subprogram): New function. (should_move_die_to_comdat): Use it. (copy_ancestor_tree): Don't mark DIEs here. (copy_decls_walk): Start walk from root of newly-added tree; mark DIEs here instead. gcc/testsuite/ChangeLog: * g++.dg/debug/dwarf2/dwarf4-typedef.C: New test. Index: testsuite/g++.dg/debug/dwarf2/dwarf4-typedef.C =================================================================== --- testsuite/g++.dg/debug/dwarf2/dwarf4-typedef.C (revision 0) +++ testsuite/g++.dg/debug/dwarf2/dwarf4-typedef.C (revision 0) @@ -0,0 +1,34 @@ +/* { dg-do compile } */ +/* { dg-options "-gdwarf-4" } */ + +/* Regression test for an ICE in output_die when using -gdwarf-4. */ + +namespace { + +struct A { + virtual ~A(); +}; + +struct B : public A { + template + bool foo(A x[2]) { } +}; + +template +struct C { + T v[2]; +}; + +template +bool X(T &b) { + typedef C D; + D x[2]; + return b.foo(x); +} + +void f() { + B b; + X(b); +} + +} Index: dwarf2out.c =================================================================== --- dwarf2out.c (revision 161107) +++ dwarf2out.c (working copy) @@ -9630,6 +9630,18 @@ is_declaration_die (dw_die_ref die) return 0; } +/* Return non-zero if this DIE is nested inside a subprogram. */ + +static int +is_nested_in_subprogram (dw_die_ref die) +{ + dw_die_ref decl = get_AT_ref (die, DW_AT_specification); + + if (decl == NULL) + decl = die; + return local_scope_p (decl); +} + /* Return non-zero if this is a type DIE that should be moved to a COMDAT .debug_types section. */ @@ -9642,8 +9654,11 @@ should_move_die_to_comdat (dw_die_ref di case DW_TAG_structure_type: case DW_TAG_enumeration_type: case DW_TAG_union_type: - /* Don't move declarations or inlined instances. */ - if (is_declaration_die (die) || get_AT (die, DW_AT_abstract_origin)) + /* Don't move declarations, inlined instances, or types nested in a + subprogram. */ + if (is_declaration_die (die) + || get_AT (die, DW_AT_abstract_origin) + || is_nested_in_subprogram (die)) return 0; return 1; case DW_TAG_array_type: @@ -10055,8 +10070,6 @@ copy_ancestor_tree (dw_die_ref unit, dw_ if (decl_table != NULL) { - /* Make sure the copy is marked as part of the type unit. */ - copy->die_mark = 1; /* Record the pointer to the copy. */ entry->copy = copy; } @@ -10130,7 +10143,18 @@ copy_decls_walk (dw_die_ref unit, dw_die installed in a previously-added context, it won't get visited otherwise. */ if (parent != unit) - copy_decls_walk (unit, parent, decl_table); + { + /* Find the highest point of the newly-added tree, + mark each node along the way, and walk from there. */ + parent->die_mark = 1; + while (parent->die_parent + && parent->die_parent->die_mark == 0) + { + parent = parent->die_parent; + parent->die_mark = 1; + } + copy_decls_walk (unit, parent, decl_table); + } } } }