https://gcc.gnu.org/g:f46aaaecd99e80245bfaa90e08ff28a4d02d631b

commit r15-2620-gf46aaaecd99e80245bfaa90e08ff28a4d02d631b
Author: Piotr Trojanek <troja...@adacore.com>
Date:   Mon Jun 24 13:07:13 2024 +0200

    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:
---
 gcc/ada/sem_ch13.adb | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index c8fe7d367c10..3784f8314107 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

Reply via email to