From patchwork Mon May 8 16:27:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 759706 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 3wM7Gh2L4kz9s0g for ; Tue, 9 May 2017 02:28:25 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ip5tccbD"; 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 :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=cPqDcfJGbjK7Nka ZdAOA1n6rcKDgGFU6trdkNU+YFVj9nvAnYgAIZxOJQmOC4W2TIGkSdthCUu6j8Es RZVNuH6MeOFAM4AYE3gh31DO8wi4gIPsrqRJFG1j02wi1qmfdDkzqkGcoeT2SrBD HtL826ylnt8zYIPHkNq5ftic/iz4= 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 :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; s=default; bh=4dpHv9b/tKqIMJCqVtbVp 2/F1l0=; b=ip5tccbD/BY7HICFwrYkLyfWNjnTe7rJoMPnSRpZ2sVURh+27Cp7e 7gEld8sJt7AomWXP/V8O5kdXXM6G1dZy717DB46p5Z1kODhIA8uRe4IsLjsyPDrY O0gma3LGpfX83DrNeREvuPXbZNesGlIFanyxpaoocDcVl2jInuZazE= Received: (qmail 54867 invoked by alias); 8 May 2017 16:27:52 -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 54733 invoked by uid 89); 8 May 2017 16:27:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy=jasonredhatcom, jason@redhat.com, sk:jason@r, stake X-HELO: mail-io0-f179.google.com Received: from mail-io0-f179.google.com (HELO mail-io0-f179.google.com) (209.85.223.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 08 May 2017 16:27:49 +0000 Received: by mail-io0-f179.google.com with SMTP id o12so25237594iod.3 for ; Mon, 08 May 2017 09:27:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=aXdcE4HMe8pdHUSC6dFPw7N+74/ElF2ZiEMfOXUQMsA=; b=b+zHEcagQgiJcVaW9fuVZdON3d+149FBJwFmJ1NtV3GkfqPWl8oV8dj5yQijyeZrqm vrEAffyazIJbepIO5aLNLy09qoF8ZVP4rYupocrr7aSE/mn6NPMlubynddsJzF8Jxjje sBaFuGPCn4rxY1JsNXljbhJ3fY/oPYnhHLh2us8dV8c+7xWixyncrOcZ2LZWicHz5OME SkEPDifoUut488H7j0Hq3IhqjAORIq5TTBTsCF+wFsAXdSUi+wRfa/BA76E6rVmjuRL1 k1PXrKcAO+qAMomIfeKqHUia/imK08LG54tRowrWK9Lna8o1mJd1PhuySrbdFv76wkYi EZoQ== X-Gm-Message-State: AODbwcCQq7PWeGIjAUts51e+P+pliL/f8JqSuu8a8wEHJPWBuYgBGYDu 0yQIYsWsRjwAQPylK0SvX/qTHZ/t2jdR X-Received: by 10.107.25.203 with SMTP id 194mr8631310ioz.182.1494260869768; Mon, 08 May 2017 09:27:49 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.6.226 with HTTP; Mon, 8 May 2017 09:27:29 -0700 (PDT) In-Reply-To: References: <20170314122410.21497-1-derodat@adacore.com> From: Jason Merrill Date: Mon, 8 May 2017 12:27:29 -0400 Message-ID: Subject: Re: [PATCH] [PR79542][Ada] Fix ICE in dwarf2out.c with nested func. inlining To: Pierre-Marie de Rodat Cc: gcc-patches List X-IsSubscribed: yes On Wed, May 3, 2017 at 3:22 PM, Jason Merrill wrote: > On Tue, Mar 14, 2017 at 8:24 AM, Pierre-Marie de Rodat > wrote: >> Hello, >> >> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79542 reports an ICE in >> dwarf2out.c for an Ada testcase built with optimization. >> >> This crash happens during the late generation pass because >> add_gnat_descriptive_type cannot find the type DIE corresponding to some >> descriptive type after having tried to generate it. This is because the >> DIE was generated during the early generation pass, but then pruned by >> the type pruning machinery. So why was it pruned? >> >> We are in a situation where we have cloned types (because of inlining, >> IIUC) whose TYPE_NAME have non-null DECL_ABSTRACT_ORIGIN attributes. As >> a consequence: >> >> * In modified_type_die, the "handle C typedef types" part calls >> gen_type_die on the cloned type. >> >> * gen_type_die matches a typedef variant, and then calls gen_decl_die >> on its TYPE_NAME, which will end up calling gen_typedef_die. >> >> * gen_typedef_die checks decl_ultimate_origin for this TYPE_DECL, and >> finds one, so it only adds a DW_AT_abstract_origin attribute to the >> DW_TAG_typedef DIE, but the cloned type itself does not get its own >> DIE. > > That seems like a bug; if gen_typedef_die is going to generate a DIE > for a cloned typedef, it needs to associate the type with the DIE. > >> * Back in modified_type_die, the call to lookup_type_die on the type >> passed to gen_type_die returns NULL. > >> In the end, whole type trees, i.e. the ones referenced by >> DECL_ABSTRACT_ORIGIN attributes, are never referenced from type pruning >> "roots" and are thus pruned. The descriptive type at stake here is one >> of them, hence the assertion failure. >> >> This patch attemps to fix that with what seems to be the most sensible >> thing to do in my opinion: updating the "handle C typedef types" part in >> modified_type_die to check decl_ultimate_origin before calling >> gen_type_die: if that function returns something not null, then we know >> that gen_type_die/gen_typedef_die will not generate a DIE for the input >> type, so we try to process the ultimate origin instead. > > This soundsn good; the DWARF standard says that we don't need to have > a die at all for the cloned typedef. > >> @@ -12496,6 +12496,18 @@ modified_type_die (tree type, int cv_quals, bool reverse, >> >> if (qualified_type == dtype) >> { >> + tree origin >> + = TYPE_NAME (qualified_type) == NULL >> + ? NULL >> + : decl_ultimate_origin (TYPE_NAME (qualified_type)); > > This is unnecessarily complicated; at this point we already know that > TYPE_NAME (qualified_type) is non-null and in the variable "name". > >> + /* Typedef variants that have an abstract origin don't get their own >> + type DIE (see gen_typedef_die), so fall back on the ultimate > > gen_typedef_die does create a DIE for them, it just doesn't do it > properly. But we could change gen_typedef_die to abort in that case, > making this comment correct. Something like this, which also avoids routinely creating DIEs for local typedefs that will only be pruned away later; this patch doesn't change the size of .debug_info in cc1plus. commit 56cce11181d1296e43cb4d603fc8efc6ac2570fa Author: Jason Merrill Date: Thu May 4 15:00:51 2017 -0400 inline-static diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 6caf598..bf6a65b 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -24355,7 +24355,7 @@ gen_typedef_die (tree decl, dw_die_ref context_die) type_die = new_die (DW_TAG_typedef, context_die, decl); origin = decl_ultimate_origin (decl); if (origin != NULL) - add_abstract_origin_attribute (type_die, origin); + gcc_unreachable (), add_abstract_origin_attribute (type_die, origin); else { tree type = TREE_TYPE (decl); @@ -24858,6 +24858,16 @@ process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die) else die = NULL; + if ((origin || DECL_ABSTRACT_ORIGIN (decl)) + && (TREE_CODE (decl_or_origin) == TYPE_DECL + || (VAR_P (decl_or_origin) && TREE_STATIC (decl_or_origin)))) + { + origin = decl_ultimate_origin (decl_or_origin); + if (decl && VAR_P (decl)) + equate_decl_number_to_die (decl, lookup_decl_die (origin)); + return; + } + if (die != NULL && die->die_parent == NULL) add_child_die (context_die, die); else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)