diff options
author | Steve Baird <baird@adacore.com> | 2022-10-19 12:42:55 -0700 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2022-11-08 09:35:00 +0100 |
commit | f2fa41b442ae6b6ab1fbde82d31abcd986b9f1f3 (patch) | |
tree | 5e18471a3d34aee25efb740a4a1c5e58b7ef5851 /gcc | |
parent | 270713d3f65243a089f4cdee04cd689422a95530 (diff) | |
download | gcc-f2fa41b442ae6b6ab1fbde82d31abcd986b9f1f3.zip gcc-f2fa41b442ae6b6ab1fbde82d31abcd986b9f1f3.tar.gz gcc-f2fa41b442ae6b6ab1fbde82d31abcd986b9f1f3.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/sem_ch3.adb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 8f4e9f8..95ffbe0 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, |