From patchwork Wed Mar 29 19:42:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 744930 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vtdTb22kKz9s2s for ; Thu, 30 Mar 2017 06:42:58 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="I1K62VKe"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=PB0nP+1omFwMGkOtCCSoVkjb4opCL b0j1ZRWFaMacfEr7pEhwaFsPwcYVrVJXs6Jh91jqCmhtOHciS7U46Ef+UvCSbSRW 8bvSWE+EYoAlVqzZCAVPtWArrmigBTvprEyPkhCR1v8X6dWm9qEwgycqyAr9SDCD y8M+vFZPMSzcJA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=ksgknxG88ra/gH4YR0REaCK0tCs=; b=I1K 62VKeAxy4QCEgggWlDh+BecUAOKCG/WaTMpX7X2p4b1JBxcsZl1mFR0iKWYgVq/M d9BBvmZRB5KRDvjgT50PYfzPu0nmFGO9i9dzagL4CAAAoalZoPWrSHqyGulM+HaL uGXbX0ENWYeu6Tp+bGcaiTA2dSNEdnl8dtzmfOiw= Received: (qmail 128462 invoked by alias); 29 Mar 2017 19:42:48 -0000 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 Received: (qmail 128445 invoked by uid 89); 29 Mar 2017 19:42:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=minds X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 Mar 2017 19:42:45 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 67D233D961 for ; Wed, 29 Mar 2017 19:42:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 67D233D961 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 67D233D961 Received: from tucnak.zalov.cz (ovpn-116-72.ams2.redhat.com [10.36.116.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EC61D60F8B; Wed, 29 Mar 2017 19:42:44 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v2TJggXk013552; Wed, 29 Mar 2017 21:42:42 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v2TJgeD6013551; Wed, 29 Mar 2017 21:42:40 +0200 Date: Wed, 29 Mar 2017 21:42:40 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix dwarf2out ICE with C++17 inline static data members with redundant redeclaration (PR debug/80234) Message-ID: <20170329194240.GG17461@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! When a C++17 inline static data member has a redundant out-of-class deprecated redeclaration, we can end up with 2 DW_TAG_variable in DW_TAG_compile_unit, one DW_AT_declaration and one with DW_AT_specification pointing to it (the latter emitted for the redeclaration), before gen_member_die can do its job. In there we want to move the declaration DIE into the class and have a CU child DW_TAG_variable that has DW_AT_specification pointing to it. But in this case we've put the DIE with DW_AT_specification into the hash table and gen_member_die ICEs in splice_child_die. The following patch handles that case gracefully, by moving the DW_AT_declaration DIE into the class instead of trying to move the DW_AT_specification one, and by making sure we don't create yet another DIE with DW_AT_specification because we already have one. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-03-29 Jakub Jelinek PR debug/80234 * dwarf2out.c (gen_member_die): Handle C++17 inline static data members with redundant out-of-class redeclaration. * g++.dg/debug/dwarf2/pr80234-1.C: New test. * g++.dg/debug/dwarf2/pr80234-2.C: New test. Jakub --- gcc/dwarf2out.c.jj 2017-03-24 14:17:59.000000000 +0100 +++ gcc/dwarf2out.c 2017-03-29 17:19:08.513497649 +0200 @@ -24085,6 +24085,10 @@ gen_member_die (tree type, dw_die_ref co for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member)) { struct vlr_context vlr_ctx = { type, NULL_TREE }; + bool static_inline_p + = (TREE_STATIC (member) + && (lang_hooks.decls.decl_dwarf_attribute (member, DW_AT_inline) + != -1)); /* If we thought we were generating minimal debug info for TYPE and then changed our minds, some of the member declarations @@ -24096,9 +24100,33 @@ gen_member_die (tree type, dw_die_ref co { /* Handle inline static data members, which only have in-class declarations. */ + dw_die_ref ref = NULL; + if (child->die_tag == DW_TAG_variable + && child->die_parent == comp_unit_die ()) + { + ref = get_AT_ref (child, DW_AT_specification); + /* For C++17 inline static data members followed by redundant + out of class redeclaration, we might get here with + child being the DIE created for the out of class + redeclaration and with its DW_AT_specification being + the DIE created for in-class definition. We want to + reparent the latter, and don't want to create another + DIE with DW_AT_specification in that case, because + we already have one. */ + if (ref + && static_inline_p + && ref->die_tag == DW_TAG_variable + && ref->die_parent == comp_unit_die () + && get_AT (ref, DW_AT_specification) == NULL) + { + child = ref; + ref = NULL; + static_inline_p = false; + } + } if (child->die_tag == DW_TAG_variable && child->die_parent == comp_unit_die () - && get_AT (child, DW_AT_specification) == NULL) + && ref == NULL) { reparent_child (child, context_die); if (dwarf_version < 5) @@ -24126,9 +24154,7 @@ gen_member_die (tree type, dw_die_ref co /* For C++ inline static data members emit immediately a DW_TAG_variable DIE that will refer to that DW_TAG_member/DW_TAG_variable through DW_AT_specification. */ - if (TREE_STATIC (member) - && (lang_hooks.decls.decl_dwarf_attribute (member, DW_AT_inline) - != -1)) + if (static_inline_p) { int old_extern = DECL_EXTERNAL (member); DECL_EXTERNAL (member) = 0; --- gcc/testsuite/g++.dg/debug/dwarf2/pr80234-1.C.jj 2017-03-29 17:23:43.606901317 +0200 +++ gcc/testsuite/g++.dg/debug/dwarf2/pr80234-1.C 2017-03-29 17:22:51.000000000 +0200 @@ -0,0 +1,15 @@ +// PR debug/80234 +// { dg-do compile } +// { dg-options "-gdwarf-4 -std=c++17" } + +struct S +{ + static constexpr const char n = 'S'; + virtual ~S (); +}; + +constexpr const char S::n; + +S::~S() +{ +} --- gcc/testsuite/g++.dg/debug/dwarf2/pr80234-2.C.jj 2017-03-29 17:23:54.663756769 +0200 +++ gcc/testsuite/g++.dg/debug/dwarf2/pr80234-2.C 2017-03-29 17:23:59.818689378 +0200 @@ -0,0 +1,15 @@ +// PR debug/80234 +// { dg-do compile } +// { dg-options "-gdwarf-5 -std=c++17" } + +struct S +{ + static constexpr const char n = 'S'; + virtual ~S (); +}; + +constexpr const char S::n; + +S::~S() +{ +}