From patchwork Wed Aug 4 23:40:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 60903 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 8CAD3B70A8 for ; Thu, 5 Aug 2010 09:40:45 +1000 (EST) Received: (qmail 19501 invoked by alias); 4 Aug 2010 23:40:43 -0000 Received: (qmail 19489 invoked by uid 22791); 4 Aug 2010 23:40:42 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, 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; Wed, 04 Aug 2010 23:40:38 +0000 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o74NeY64002293 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 4 Aug 2010 19:40:35 -0400 Received: from anchor.twiddle.home ([10.3.113.15]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o74NeWcV014280; Wed, 4 Aug 2010 19:40:33 -0400 Message-ID: <4C59FA70.8090206@redhat.com> Date: Wed, 04 Aug 2010 16:40:32 -0700 From: Richard Henderson User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.7) Gecko/20100720 Fedora/3.1.1-1.fc13 Thunderbird/3.1.1 MIME-Version: 1.0 To: GCC Patches CC: Dodji Seketeli , howarth@bromo.med.uc.edu Subject: Fix debug/45171 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 Following 2010-05-25 Dodji Seketeli PR c++/44188 * c-common.c (is_typedef_decl): Move this definition ... * tree.c (is_typedef_decl): ... here. (typdef_variant_p): Move definition here from gcc/cp/tree.c. * c-common.h (is_typedef_decl): Move this declaration ... * tree.h (is_typedef_decl): ... here. (typedef_variant_p): Move declaration here from gcc/cp/cp-tree.h * dwarf2out.c (is_naming_typedef_decl): New function. (gen_tagged_type_die): Split out of ... (gen_type_die_with_usage): ... this function. When an anonymous tagged type is named by a typedef, make sure a DW_TAG_typedef DIE is emitted for the typedef. (gen_typedef_die): Emit DW_TAG_typedef also for typedefs naming anonymous tagged types. The test case shows a path through gen_typedef_die for which the unnamed type had already been emitted. "Emitting" it again results in duplicate attributes being added to the existing die. In the future, I hope that we can (optionally) incorporate dwarflint into the gcc testsuite, at least within dwarf2.exp. Talking with Roland, it isn't quite ready for that yet. Tested on x86_64-linux. r~ commit 27fead82006aba0eb90dd61e2195e4463ba70708 Author: Richard Henderson Date: Wed Aug 4 16:29:16 2010 -0700 PR debug/45171 * dwarf2out.c (gen_typedef_die): Don't re-generate the die of an is_naming_typedef_decl. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 95de468..651642a 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -19785,22 +19785,24 @@ gen_typedef_die (tree decl, dw_die_ref context_die) type = TREE_TYPE (decl); if (is_naming_typedef_decl (TYPE_NAME (type))) - /* - Here, we are in the case of decl being a typedef naming - an anonymous type, e.g: + { + /* Here, we are in the case of decl being a typedef naming + an anonymous type, e.g: typedef struct {...} foo; - In that case TREE_TYPE (decl) is not a typedef variant - type and TYPE_NAME of the anonymous type is set to the - TYPE_DECL of the typedef. This construct is emitted by - the C++ FE. - - TYPE is the anonymous struct named by the typedef - DECL. As we need the DW_AT_type attribute of the - DW_TAG_typedef to point to the DIE of TYPE, let's - generate that DIE right away. add_type_attribute - called below will then pick (via lookup_type_die) that - anonymous struct DIE. */ - gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE); + In that case TREE_TYPE (decl) is not a typedef variant + type and TYPE_NAME of the anonymous type is set to the + TYPE_DECL of the typedef. This construct is emitted by + the C++ FE. + + TYPE is the anonymous struct named by the typedef + DECL. As we need the DW_AT_type attribute of the + DW_TAG_typedef to point to the DIE of TYPE, let's + generate that DIE right away. add_type_attribute + called below will then pick (via lookup_type_die) that + anonymous struct DIE. */ + if (!TREE_ASM_WRITTEN (type)) + gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE); + } } add_type_attribute (type_die, type, TREE_READONLY (decl), diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/typedef4.C b/gcc/testsuite/g++.dg/debug/dwarf2/typedef4.C new file mode 100644 index 0000000..2879f60 --- /dev/null +++ b/gcc/testsuite/g++.dg/debug/dwarf2/typedef4.C @@ -0,0 +1,10 @@ +// Origin: PR debug/45171 +// { dg-options "-g -dA -fno-eliminate-unused-debug-types" } +// { dg-do compile } + +// There should be 2 real instances of byte_size -- one for the +// struct and one for "int". The other two instances are from +// the comments in the .debug_abbrev section. +// { dg-final { scan-assembler-times "DW_AT_byte_size" 4 } } + +typedef struct { int a, b; } x;