From patchwork Tue Nov 30 16:06:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 73620 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 C19BDB70B0 for ; Wed, 1 Dec 2010 03:06:59 +1100 (EST) Received: (qmail 2279 invoked by alias); 30 Nov 2010 16:06:57 -0000 Received: (qmail 2252 invoked by uid 22791); 30 Nov 2010 16:06:52 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=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; Tue, 30 Nov 2010 16:06:47 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oAUG6jkY001536 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 30 Nov 2010 11:06:46 -0500 Received: from adjoa.redhat.com (ovpn-113-41.phx2.redhat.com [10.3.113.41]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oAUG6has014560; Tue, 30 Nov 2010 11:06:44 -0500 From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches Subject: Re: Fix PR debug/45088 References: <4CED9B5F.1010900@redhat.com> X-URL: http://www.redhat.com Date: Tue, 30 Nov 2010 17:06:42 +0100 In-Reply-To: <4CED9B5F.1010900@redhat.com> (Jason Merrill's message of "Wed, 24 Nov 2010 18:10:23 -0500") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 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 Jason Merrill writes: > On 11/12/2010 06:47 AM, Dodji Seketeli wrote: >> One possible way to do resolve that dilemma is [at the FE level] to >> fixup the type of *ai to make it be A instead of the self-reference >> type of A. I figure the fact that the self-reference type is different >> from A itself should be kept as an implementation detail of the FE >> anyway. > > I think the typedef should be emitted so that name lookup in the > debugger can find it. TYPE_DECL_IS_STUB should not be true for the > injected-class-name. Yes this makes a lot of sense. I initially got somewhat confused by this code snippet in is_redundant_typedef: if (DECL_ARTIFICIAL (decl) && DECL_CONTEXT (decl) && is_tagged_type (DECL_CONTEXT (decl)) && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) /* Also ignore the artificial member typedef for the class name. */ return 1; From what I understand it basically is tailored to not emit debug info precisely for injected-class-names. But maybe at that time we didn't have the help of cgraph and the unused type debug info pruning we have today. In other words I think emitting debug info for the injected-class-name won't necessarily increase bloat because if the debug info of the injected-class-name typedef will be pruned if it is not used. So would the patch below be more acceptable? I have tested it against trunk on x86_64-unknown-linux-gnu. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 04764ba..a8fe4b5 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -20566,13 +20566,12 @@ is_redundant_typedef (const_tree decl) if (TYPE_DECL_IS_STUB (decl)) return 1; - if (DECL_ARTIFICIAL (decl) - && DECL_CONTEXT (decl) - && is_tagged_type (DECL_CONTEXT (decl)) - && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL - && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) - /* Also ignore the artificial member typedef for the class name. */ - return 1; + /* For C++ We consider injected-class-names (which are typedefs) + like a non-redundant typedef. They are needed so that lookups of + a class name from inside the scope of the class to succeed in the + debugger. This should hopefully not result in debug size + explosion as we have infrastructure in place to prune debug info + of unused types anyway. */ return 0; } diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-1.C b/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-1.C new file mode 100644 index 0000000..81bcb27 --- /dev/null +++ b/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-1.C @@ -0,0 +1,28 @@ +// Origin: PR debug/45088 +// { dg-do compile } +// { dg-options "-g -dA" } +// { dg-final { scan-assembler-times "\[^\n\r\]*\\(DIE\[^\n\r\]*DW_TAG_pointer_type\\)\[\n\r\]{1,2}\[^\n\r\]*DW_AT_byte_size\[\n\r\]{1,2}\[^\n\r\]*DW_AT_type" 4 } } + +struct A +{ + virtual ~A(); +}; + +struct B : public A +{ + virtual ~B(){} +}; + +struct C : public B +{ + A* a1; +}; + +int +main() +{ + C c; + c.a1 = 0; + return 0; +} + diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-2.C b/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-2.C new file mode 100644 index 0000000..b1c5401 --- /dev/null +++ b/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-2.C @@ -0,0 +1,29 @@ +// Origin: PR debug/45088 +// { dg-do compile } +// { dg-options "-g -dA" } +// { dg-final { scan-assembler-times "\[^\n\r\]*\\(DIE\[^\n\r\]*DW_TAG_pointer_type\\)\[\n\r\]{1,2}\[^\n\r\]*DW_AT_byte_size\[\n\r\]{1,2}\[^\n\r\]*DW_AT_type" 4 } } + +template +struct A +{ + virtual ~A(); +}; + +struct B : public A +{ + virtual ~B(){} +}; + +struct C : public B +{ + A* a1; +}; + +int +main() +{ + C c; + c.a1 = 0; + return 0; +} +