diff options
author | Piotr Trojanek <trojanek@adacore.com> | 2024-05-16 10:59:31 +0200 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2024-06-21 10:34:18 +0200 |
commit | a0546a36e007d1def02f5a575d1b4e2a08a66115 (patch) | |
tree | 4960faefb85bb3c0864f5ca63bc206a723913ad1 /gcc/ada/sem_ch13.adb | |
parent | 3ebd803b861e1da85f08664915e3267f690ff611 (diff) | |
download | gcc-a0546a36e007d1def02f5a575d1b4e2a08a66115.zip gcc-a0546a36e007d1def02f5a575d1b4e2a08a66115.tar.gz gcc-a0546a36e007d1def02f5a575d1b4e2a08a66115.tar.bz2 |
ada: Fix for Default_Component_Value with declare expressions
When the expression of aspect Default_Component_Value includes a declare
expression with current type instance, we attempted to recursively froze
that type, which itself caused an infinite recursion, because we didn't
properly manage the scope of declare expression.
This patch fixes both the detection of the current type instance and
analysis of the expression that caused recursive freezing.
gcc/ada/
* sem_attr.adb (In_Aspect_Specification): Use the standard
condition that works correctly with declare expressions.
* sem_ch13.adb (Analyze_Aspects_At_Freeze_Point): Replace
ordinary analysis with preanalysis of spec expressions.
Diffstat (limited to 'gcc/ada/sem_ch13.adb')
-rw-r--r-- | gcc/ada/sem_ch13.adb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 4012932..a86f774 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -1037,11 +1037,19 @@ package body Sem_Ch13 is Parent_Type : Entity_Id; + Save_In_Spec_Expression : constant Boolean := In_Spec_Expression; + begin -- Ensure Expr is analyzed so that e.g. all types are properly - -- resolved for Find_Type_Reference. + -- resolved for Find_Type_Reference. We preanalyze this expression + -- as a spec expression (to avoid recursive freezing), while skipping + -- resolution (to not fold type self-references, e.g. T'Last). - Analyze (Expr); + In_Spec_Expression := True; + + Preanalyze (Expr); + + In_Spec_Expression := Save_In_Spec_Expression; -- A self-referential aspect is illegal if it forces freezing the -- entity before the corresponding aspect has been analyzed. |