From: Piotr Trojanek Date: Mon, 24 Jun 2024 11:07:13 +0000 (+0200) Subject: ada: Fix freezing of Default_Value expressions X-Git-Tag: basepoints/gcc-16~6933 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f46aaaecd99e80245bfaa90e08ff28a4d02d631b;p=thirdparty%2Fgcc.git ada: Fix freezing of Default_Value expressions This patch fixes an infinite loop in freezing that occurred when expression of the Default_Value aspect includes a declare expression with an object of the annotated type. gcc/ada/ * sem_ch13.adb (Check_Aspect_Too_Late): Prevent freezing during preanalysis. --- diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index c8fe7d367c1..3784f831410 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -1049,17 +1049,21 @@ package body Sem_Ch13 is Parent_Type : Entity_Id; Save_In_Spec_Expression : constant Boolean := In_Spec_Expression; + Save_Must_Not_Freeze : constant Boolean := Must_Not_Freeze (Expr); begin -- Ensure Expr is analyzed so that e.g. all types are properly -- 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). + -- (to avoid expansion), handle it as a spec expression (like default + -- expression), disable freezing and skip resolution (to not fold + -- type self-references, e.g. T'Last). In_Spec_Expression := True; + Set_Must_Not_Freeze (Expr); Preanalyze (Expr); + Set_Must_Not_Freeze (Expr, Save_Must_Not_Freeze); In_Spec_Expression := Save_In_Spec_Expression; -- A self-referential aspect is illegal if it forces freezing the