From patchwork Mon Sep 12 08:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 1154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1782065wrt; Mon, 12 Sep 2022 01:33:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR6RaoWZuNNCRVbrs4cNL9564GH6cED1nBnSsGwaxFcReJDOEKDDUT88n3CX9fkK2DpBJ7lI X-Received: by 2002:a17:906:9b92:b0:730:a237:40fe with SMTP id dd18-20020a1709069b9200b00730a23740femr17934391ejc.464.1662971608040; Mon, 12 Sep 2022 01:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662971608; cv=none; d=google.com; s=arc-20160816; b=Xu51s0uB6qvl4sivjU5Kmfl2JYAKq5lfDS5uixVEx+WapNaykx4ym1Jq1hUu2WyTo1 LPRrBA4lNZkXRchrEhVNtv9OpuNwRr7AGPp6B0DcFv6PVoeoIPzGjNXpvOOcsNDB4jMT N1cpgATCv/vpAWBnrkZuseFTpKqoonk76j2whD+cT77k62b9RyOsDynsFVmXX2SFayWj /3qnTy/2UdwwvYteMvoj1atamvHwLywmFR7pVjANOmGBYea81bfHzIwEGxB4dokvUobZ PBhqFA2sVGJG5EbMCqY94rCLDhaVGHtb404/NLtK9E6734EVW+Kf/xXLyLq5zqRjX5ij Lfcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=d2LPt+RvWCN8ryJxeca0ZuduHUeUWI5sP/98V1uFprI=; b=iqy6Y22HbBSB83xzi57s4O4s460oy40Ak6DyvizTQcxrv4f3EGV+URYyjAlJEDdfi1 aV3Ez0ymwd7y/H7E2SWPPr/9p+2nihmzCunjNlq/QC8bhrDxw6bDPBGLTAHh30lYv/6I mGD+297H5njQROtZmVXdKGHyTpS1jgpPWL+bvBJ05R/8P2C0uAuYDU2QPfTUl4CV6+lM LIIziD8+gDEv3KZ4utEkEzJPs+C0OJ8hws8VO5H8blGU73tLC8SpduYkENdjJHdZX7xq z/KIvzuVFD89Ne7XGwndwGVFI18Ps/+PGzCJNrjxMzY2eBwVgXlC89BX2AVniTq+pNDA 8A3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LhPzkX3C; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id xg12-20020a170907320c00b0072ab4b5ffe5si6313019ejb.987.2022.09.12.01.33.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 01:33:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LhPzkX3C; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E47963AA88FF for ; Mon, 12 Sep 2022 08:25:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E47963AA88FF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662971140; bh=d2LPt+RvWCN8ryJxeca0ZuduHUeUWI5sP/98V1uFprI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=LhPzkX3CPqax1TPiQspO6C3410nkYHP3ejEQkStgOmA6viYEB+uBcbY25tT2fYqB/ xWbiFg+SM+4IfqQH6xdcs1YDNYhkzhZ22fhGaA8ZPrtVl5oEZp3rocwdDZugscRGh2 ilAWmER07vMSVVL8yYUDhksvS1L+yixKAFExr+oY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 8A896385020E for ; Mon, 12 Sep 2022 08:19:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8A896385020E Received: by mail-wr1-x432.google.com with SMTP id c11so14030189wrp.11 for ; Mon, 12 Sep 2022 01:19:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=d2LPt+RvWCN8ryJxeca0ZuduHUeUWI5sP/98V1uFprI=; b=YAlAqjP9wvhAjyhgUesTvDBnRmhLWgT6js7Ial5ZnO2qcMuKoSQrh87d+MB3bJiohW y/GwLwbtDvDxyN8m7JdHwMoSTtzcOTNLL0EUyhC1cAdsV8GSTzpFUq8DjYHtljP+TXDU BZHlnrszgwBly+SYpnuEPiukObgAukrqflvOgYeqTTVHyNR9kloPwZ4rZQTxT90TPqfp Yw0Uyp7XgaCTD6uZj4RUaOIQowoAm7jYZSO9b/8KNHSnHGTmMoKEsrdm6TGbi6q2ocS3 wH4cdN7hiVlNBnpKAm8OzU/CZFq/a7AA/ZW5aY7huctevCxqM0Ieqa763VxjQNXAcR3n rW8A== X-Gm-Message-State: ACgBeo1GvD6Demu6MUBjKuIEKVCrlNHpT+HTB8XF1I5gsLtWrNOKGxB4 jv58UsbU6jDeMgVBI6LpV+uAqG8C9uGgLQ== X-Received: by 2002:a5d:64c2:0:b0:228:cb2b:f38d with SMTP id f2-20020a5d64c2000000b00228cb2bf38dmr14242632wri.491.1662970786194; Mon, 12 Sep 2022 01:19:46 -0700 (PDT) Received: from poulhies-Precision-5550 (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id u8-20020a05600c19c800b003a54d610e5fsm9840051wmq.26.2022.09.12.01.19.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 01:19:45 -0700 (PDT) Date: Mon, 12 Sep 2022 10:19:45 +0200 To: gcc-patches@gcc.gnu.org Subject: [Ada] Storage_Error raised analyzing type with call in its range constraint Message-ID: <20220912081945.GA1513162@poulhies-Precision-5550> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: Marc =?iso-8859-1?q?Poulhi=E8s?= Cc: Justin Squirek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743752116782979450?= X-GMAIL-MSGID: =?utf-8?q?1743752116782979450?= This patch corrects a problem in the compiler whereby the determination of scope levels during the generation of accessibility checks for function calls within range constraints leads to a compiler crash due to the type not being fully analyzed at the point in which its scope depth must be obtained. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.adb (Innermost_Master_Scope_Depth): Detect and handle case where scope depth is not set on an enclosing scope. diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -316,8 +316,20 @@ package body Sem_Util is -- Ignore transient scopes made during expansion if Comes_From_Source (Node_Par) then - return - Scope_Depth (Encl_Scop) + Master_Lvl_Modifier; + -- Note that in some rare cases the scope depth may not be + -- set, for example, when we are in the middle of analyzing + -- a type and the enclosing scope is said type. So, instead, + -- continue to move up the parent chain since the scope + -- depth of the type's parent is the same as that of the + -- type. + + if not Scope_Depth_Set (Encl_Scop) then + pragma Assert (Nkind (Parent (Encl_Scop)) + = N_Full_Type_Declaration); + else + return + Scope_Depth (Encl_Scop) + Master_Lvl_Modifier; + end if; end if; -- For a return statement within a function, return