diff mbox series

[COMMITTED,14/30] ada: Fix freezing of Default_Value expressions

Message ID 20240801151738.400796-14-poulhies@adacore.com
State New
Headers show
Series [COMMITTED,01/30] ada: Remove obsolete workaround | expand

Commit Message

Marc Poulhiès Aug. 1, 2024, 3:17 p.m. UTC
From: Piotr Trojanek <trojanek@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch13.adb | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox series

Patch

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