From patchwork Fri Dec 15 10:21:50 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: 849078 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-469313-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="XszlMbCf"; 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 3yymgv08qqz9s4q for ; Fri, 15 Dec 2017 21:22:02 +1100 (AEDT) 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:mime-version:content-type; q=dns; s=default; b=VYfwE+0WCS1wr8JpYTZWVfX508PFXfSrH0Avu7xSE8DS6rj3JA pGnL9msV68+RLNbAk4Xl5DEpnTpvUPfmyxvCZXp/YGUjyeoczYzWzabPyzwi5QAP YExoXwyPshhWbQFzOrqzkVBy0OT5Pm7k9BXtUomm/r9qHAorNWtfEKn9g= 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:mime-version:content-type; s= default; bh=97nEtEGmYx2y5h9nItAQ5JS4d+k=; b=XszlMbCf846EvRNjjawm 1Y3L7A7qe4VG829JKlZnl7ryEZQkgRmzGA8bheHPxDJOm5hqR/7ptlhP0TwXDla0 21ds0i7p38Morr+QnZd7pyWXhyYe30jX+SGPZp5hKSWSGZDAbswqjAFqpynXfBKD 6R+RIk9i6Wfk2kFtntptK9I= Received: (qmail 14772 invoked by alias); 15 Dec 2017 10:21:54 -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 14762 invoked by uid 89); 15 Dec 2017 10:21:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=16636, 5538, 5638 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 15 Dec 2017 10:21:52 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 133C5116EC2; Fri, 15 Dec 2017 05:21:51 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id zuEnY1mx+esM; Fri, 15 Dec 2017 05:21:51 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id F4179116DB4; Fri, 15 Dec 2017 05:21:50 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4862) id EE847508; Fri, 15 Dec 2017 05:21:50 -0500 (EST) Date: Fri, 15 Dec 2017 05:21:50 -0500 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Compiler crash with -gnatd.1 (force unnesting of subprograms) Message-ID: <20171215102150.GA7479@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes This patch fixes a crash in the compiler when enabling unnesting of subprograms on a generic unit. The following must compile quietly: gcc -c -gnatg -gnatd.1 a-btgbso.adb Tested on x86_64-pc-linux-gnu, committed on trunk 2017-12-15 Ed Schonberg * exp_unst.adb (Unnest_Subprograms): Nothing to do if the main unit is a generic package body. Unnesting is only an issue when generating code, and if the main unit is generic then nested instance bodies have not been created and analyzed, and unnesting will crash in the absence of those bodies, Index: exp_unst.adb =================================================================== --- exp_unst.adb (revision 255680) +++ exp_unst.adb (working copy) @@ -302,6 +302,16 @@ return; end if; + -- If the main unit is a package body then we need to examine the spec + -- to determine whether the main unit is generic (the scope stack is not + -- present when this is called on the main unit). + + if Ekind (Cunit_Entity (Main_Unit)) = E_Package_Body + and then Is_Generic_Unit (Spec_Entity (Cunit_Entity (Main_Unit))) + then + return; + end if; + -- At least for now, do not unnest anything but main source unit if not In_Extended_Main_Source_Unit (Subp_Body) then @@ -553,8 +563,8 @@ Ent := Entity (Name (N)); -- We are only interested in calls to subprograms nested - -- within Subp. Calls to Subp itself or to subprograms that - -- are outside the nested structure do not affect us. + -- within Subp. Calls to Subp itself or to subprograms + -- that are outside the nested structure do not affect us. if Scope_Within (Ent, Subp) then @@ -1653,7 +1663,6 @@ if Present (STT.ARECnF) and then Nkind (CTJ.N) /= N_Attribute_Reference then - -- CTJ.N is a call to a subprogram which may require a pointer -- to an activation record. The subprogram containing the call -- is CTJ.From and the subprogram being called is CTJ.To, so we