From patchwork Tue Sep 12 06:00:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 812702 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461885-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="d5tL4nsV"; dkim-atps=neutral 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 3xrvNv2SvKz9s7g for ; Tue, 12 Sep 2017 16:03:24 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=aHgGhzHfOgPF XLhZU61arFhsl8BEiQ0Q3c8jyHLYjBzMiuCoLYkQy4/0OmhYInRzLcCbcVp//itz PwUp29C969lwjlsly2pcNMO5EWs6HqWSA9jJFTT3Nhxeb0ppUnp3MdZRhtc6whlI Crxc3jgyIxY8nSDDvUyAHJeRCmmhbGU= 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:from :to:cc:subject:date:message-id; s=default; bh=1y3LSD8givf9eXjTr5 ZnFgQyqww=; b=d5tL4nsVD2g8CLLSTTvSPkwOrPJjCgFb590qLM75bIjka/E+y+ l7yaQ5Np8nElFhRAwpbZ+vn0aHSpeYwqqODL5lW8Sm5K07GbK9T29+q7M3cRG6SP 5aJQpCNNWAOSqnll0gc4YhttdN1hOPDRKwfxeCxMslELTTjabryHPY48w= Received: (qmail 22139 invoked by alias); 12 Sep 2017 06:03:14 -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 22130 invoked by uid 89); 12 Sep 2017 06:03:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=origins X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Sep 2017 06:03:12 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 499BC8222C; Tue, 12 Sep 2017 08:03:10 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id B13ToVuDuxQV; Tue, 12 Sep 2017 08:03:10 +0200 (CEST) Received: from perdrix.act-europe.fr (perdrix.act-europe.fr [IPv6:2a02:2ab8:224:1:1adb:f2ff:fe3d:1472]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 2A2F78220C; Tue, 12 Sep 2017 08:03:10 +0200 (CEST) From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Pierre-Marie de Rodat Subject: [PATCH] [PR82155] Fix crash in dwarf2out_abstract_function Date: Tue, 12 Sep 2017 08:00:03 +0200 Message-Id: <20170912060003.32378-1-derodat@adacore.com> X-IsSubscribed: yes Hello, This patch is an attempt to fix the crash reported in PR82155. When generating a C++ class method for a class that is itself nested in a class method, dwarf2out_early_global_decl currently leaves the existing context DIE as it is if it already exists. However, it is possible that this call happens at a point where this context DIE is just a declaration that is itself not located in its own context. From there, if dwarf2out_early_global_decl is not called on any of the FUNCTION_DECL in the context chain, DIEs will be left badly scoped and some (such as the nested method) will be removed by the type pruning machinery. As a consequence, dwarf2out_abstract_function will will crash when called on the corresponding DECL because it asserts that the DECL has a DIE. This patch fixes this crash making dwarf2out_early_global_decl process context DIEs the same way we process abstract origins for FUNCTION_DECL: if the corresponding DIE exists but is only a declaration, call dwarf2out_decl anyway on it so that it is turned into a more complete DIE and so that it is relocated in the proper context. Bootstrapped and regtested on x86_64-linux. The crash this addresses is present both on trunk and on the gcc-7 branch: I suggest we commit this patch on both branches. Ok to commit? Thank you in advance! gcc/ PR debug/82155 * dwarf2out.c (dwarf2out_early_global_decl): Call dwarf2out_decl on the FUNCTION_DECL function context if it has a DIE that is a declaration. gcc/testsuite/ * g++.dg/pr82155.C: New testcase. --- gcc/dwarf2out.c | 10 ++++++++-- gcc/testsuite/g++.dg/pr82155.C | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr82155.C diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 00d6d951ba3..4cfc9c186af 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -25500,10 +25500,16 @@ dwarf2out_early_global_decl (tree decl) so that all nested DIEs are generated at the proper scope in the first shot. */ tree context = decl_function_context (decl); - if (context != NULL && lookup_decl_die (context) == NULL) + if (context != NULL) { + dw_die_ref context_die = lookup_decl_die (context); current_function_decl = context; - dwarf2out_decl (context); + + /* Avoid emitting DIEs multiple times, but still process CONTEXT + enough so that it lands in its own context. This avoids type + pruning issues later on. */ + if (context_die == NULL || is_declaration_die (context_die)) + dwarf2out_decl (context); } /* Emit an abstract origin of a function first. This happens diff --git a/gcc/testsuite/g++.dg/pr82155.C b/gcc/testsuite/g++.dg/pr82155.C new file mode 100644 index 00000000000..75d9b615f39 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr82155.C @@ -0,0 +1,36 @@ +/* { dg-do compile { target c++11 } } */ +/* { dg-options "-g -O2" } */ + +template struct b { a c; }; +template struct e { d *operator->(); }; +template class h { +public: + typedef e ag; +}; +class i { +protected: + i(int); +}; +class j { + virtual void k(int) = 0; + +public: + int f; + void l() { k(f); } +}; +struct m : i { + int cn; + m() : i(cn) { + struct n : j { + n() {} + void k(int) {} + }; + } +}; +struct o { + o() { + for (h>>::ag g;;) + g->c.c->l(); + } +}; +void fn1() { o(); }