From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 4712E3858437; Tue, 8 Nov 2022 08:41:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4712E3858437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667896891; bh=x+tj9lFrSkZHiTjuCRyRQCPh3H0ktq4wbsChczVBQpw=; h=From:To:Subject:Date:From; b=i064nAjgZwT0xuj5vZlu9pZW9WFW7e86r2aEVad2Og4CAXG2QDpnUvrWrYb3iUrkq ycnPFnoUFtotzAjbdM8zCyxHHc7ntWSXksJHPd/RYqGLLImbienL1e3mA+B/Bgc8sN 45uMBjDtgbdRqL0xDj1a9OehnGVLHyrh9sZQ7Al4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3789] ada: Improve handling of declare expressions in deferred-freezing contexts X-Act-Checkin: gcc X-Git-Author: Steve Baird X-Git-Refname: refs/heads/master X-Git-Oldrev: 270713d3f65243a089f4cdee04cd689422a95530 X-Git-Newrev: f2fa41b442ae6b6ab1fbde82d31abcd986b9f1f3 Message-Id: <20221108084131.4712E3858437@sourceware.org> Date: Tue, 8 Nov 2022 08:41:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f2fa41b442ae6b6ab1fbde82d31abcd986b9f1f3 commit r13-3789-gf2fa41b442ae6b6ab1fbde82d31abcd986b9f1f3 Author: Steve Baird Date: Wed Oct 19 12:42:55 2022 -0700 ada: Improve handling of declare expressions in deferred-freezing contexts In some cases where a declare expression occurs in a deferred-freezing context (e.g., within the default value for a discriminant or for a formal parameter, or within the expression of an expression function), the compiler generates a bugbox. gcc/ada/ * sem_ch3.adb (Analyze_Object_Declaration): Do not perform expansion actions if In_Spec_Expression is true. Diff: --- gcc/ada/sem_ch3.adb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 8f4e9f80eb8..95ffbe00ba4 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -4721,6 +4721,26 @@ package body Sem_Ch3 is Expand_Sliding_Conversion (E, T); end if; + if In_Spec_Expression and then In_Declare_Expr > 0 then + -- It is too early to be doing expansion-ish things, + -- so exit early. But we have to set Ekind (Id) now so + -- that subsequent uses of this entity are not rejected + -- via the same mechanism that (correctly) rejects + -- "X : Integer := X;". + + if Constant_Present (N) then + Mutate_Ekind (Id, E_Constant); + Set_Is_True_Constant (Id); + else + Mutate_Ekind (Id, E_Variable); + if Present (E) then + Set_Has_Initial_Value (Id); + end if; + end if; + + goto Leave; + end if; + Expand_Subtype_From_Expr (N => N, Unc_Type => T,