From patchwork Thu Nov 18 20:42:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 72145 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 D9909B71CD for ; Fri, 19 Nov 2010 07:42:30 +1100 (EST) Received: (qmail 27061 invoked by alias); 18 Nov 2010 20:42:26 -0000 Received: (qmail 27046 invoked by uid 22791); 18 Nov 2010 20:42:25 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_GD, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 18 Nov 2010 20:42:20 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oAIKgIOB016576 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 18 Nov 2010 15:42:19 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oAIKgHnO010937 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 18 Nov 2010 15:42:18 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id oAIKgH53015076; Thu, 18 Nov 2010 21:42:17 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id oAIKgH9u015074; Thu, 18 Nov 2010 21:42:17 +0100 Date: Thu, 18 Nov 2010 21:42:16 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ICE with -feliminate-dwarf2-dups or -gdwarf-4 (PR debug/46123) Message-ID: <20101118204216.GB29412@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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 Hi! As mentioned in the PR, reusing a DW_TAG_subprogram DW_AT_declaration DIE for the definition doesn't work with -feliminate-dwarf2-dups or -gdwarf-4, there we really want to avoid DW_TAG_subprograms for actual routine definitions, otherwise we ICE because .debug_aranges isn't split to point to those units (but the comdat CUs don't seem to be meant to contain debug info for code). Fixed thusly, bootstrapped/regtested on x86_64-linux, ok for trunk? 2010-11-18 Jakub Jelinek PR debug/46123 * dwarf2out.c (gen_subprogram_die): Don't reuse the old die if -feliminate-dwarf2-dups or -gdwarf-4. * g++.dg/debug/pr46123.C: New test. * g++.dg/debug/dwarf2/pr46123.C: New test. Jakub --- gcc/dwarf2out.c.jj 2010-11-15 23:28:02.000000000 +0100 +++ gcc/dwarf2out.c 2010-11-18 13:45:10.189654791 +0100 @@ -18840,6 +18840,21 @@ gen_subprogram_die (tree decl, dw_die_re && (get_AT_unsigned (old_die, DW_AT_decl_line) == (unsigned) s.line)))) { + /* Don't use the old DIE if eliminating DWARF dups using + break_out_includes or DWARF4 .debug_types, as that could + leave subprogram DIEs with *_pc attributes in the comdat CUs + or .debug_types. */ + if ((flag_eliminate_dwarf2_dups || dwarf_version >= 4) + && !is_cu_die (old_die->die_parent)) + { + if (decl_function_context (decl) + && DECL_CONTEXT (decl) + && TREE_CODE (DECL_CONTEXT (decl)) != FUNCTION_DECL + && TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL) + context_die = comp_unit_die (); + goto new_subr_die; + } + subr_die = old_die; /* Clear out the declaration attribute and the formal parameters. @@ -18853,6 +18868,7 @@ gen_subprogram_die (tree decl, dw_die_re } else { + new_subr_die: subr_die = new_die (DW_TAG_subprogram, context_die, decl); add_AT_specification (subr_die, old_die); if (get_AT_file (old_die, DW_AT_decl_file) != file_index) --- gcc/testsuite/g++.dg/debug/dwarf2/pr46123.C.jj 2010-11-18 13:31:40.000000000 +0100 +++ gcc/testsuite/g++.dg/debug/dwarf2/pr46123.C 2010-11-18 13:46:09.889261025 +0100 @@ -0,0 +1,47 @@ +// PR debug/46123 +// { dg-do compile } +// { dg-options "-gdwarf-4" } + +struct foo +{ + static int bar () + { + int i; + static int baz = 1; + { + static int baz = 2; + i = baz++; + } + { + struct baz + { + static int m () + { + static int n; + return n += 10; + } + }; + baz a; + i += a.m (); + } + { + static int baz = 3; + i += baz; + baz += 30; + } + i += baz; + baz += 60; + return i; + } +}; + +int main () +{ + foo x; + + if (x.bar () != 16) + return 1; + if (x.bar() != 117) + return 1; + return 0; +} --- gcc/testsuite/g++.dg/debug/pr46123.C.jj 2010-11-18 13:31:40.078247818 +0100 +++ gcc/testsuite/g++.dg/debug/pr46123.C 2010-11-18 13:34:06.486261122 +0100 @@ -0,0 +1,47 @@ +// PR debug/46123 +// { dg-do compile } +// { dg-options "-g -feliminate-dwarf2-dups" } + +struct foo +{ + static int bar () + { + int i; + static int baz = 1; + { + static int baz = 2; + i = baz++; + } + { + struct baz + { + static int m () + { + static int n; + return n += 10; + } + }; + baz a; + i += a.m (); + } + { + static int baz = 3; + i += baz; + baz += 30; + } + i += baz; + baz += 60; + return i; + } +}; + +int main () +{ + foo x; + + if (x.bar () != 16) + return 1; + if (x.bar() != 117) + return 1; + return 0; +}