From cff00f7c56fe0bdcc05c302c679e22ad04c097f7 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Thu, 23 Mar 2023 18:40:43 +0100 Subject: Sem_Array_Aggregate: free subtype definitions if not used. --- src/vhdl/vhdl-sem_expr.adb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src') diff --git a/src/vhdl/vhdl-sem_expr.adb b/src/vhdl/vhdl-sem_expr.adb index 047a62a77..be60e12c8 100644 --- a/src/vhdl/vhdl-sem_expr.adb +++ b/src/vhdl/vhdl-sem_expr.adb @@ -4149,6 +4149,7 @@ package body Vhdl.Sem_Expr is -- Avoid error propagation. Set_Range_Constraint (Info.Index_Subtype, Get_Range_Constraint (Index_Type)); + Set_Is_Ref (Info.Index_Subtype, True); Free_Iir (Index_Subtype_Constraint); else Set_Direction (Index_Subtype_Constraint, Dir); @@ -4346,6 +4347,24 @@ package body Vhdl.Sem_Expr is else Set_Aggregate_Expand_Flag (Aggr, False); end if; + + if Get_Literal_Subtype (Aggr) = Null_Iir then + -- Free the index range info if not used to create the literal + -- subtype. + for I in Infos'Range loop + declare + St : constant Iir := Infos (I).Index_Subtype; + Rng : constant Iir := Get_Range_Constraint (St); + begin + if not Get_Is_Ref (St) then + Free_Iir (Get_Left_Limit_Expr (Rng)); + Free_Iir (Get_Right_Limit_Expr (Rng)); + Free_Iir (Rng); + end if; + Free_Iir (St); + end; + end loop; + end if; else -- If the array is not constrained, expression cannot be more -- static than the type. In particular, if the type is not -- cgit v1.2.3