]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix freezing of Default_Value expressions
authorPiotr Trojanek <trojanek@adacore.com>
Mon, 24 Jun 2024 11:07:13 +0000 (13:07 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 1 Aug 2024 15:14:36 +0000 (17:14 +0200)
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.

gcc/ada/sem_ch13.adb

index c8fe7d367c10cec873c165652136a1adc88e3db4..3784f8314107705f9b803bea2589c55edcaaee1b 100644 (file)
@@ -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