From fe04c6ae2ccad7e2cca0d44f3dfc57a39614cafd Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Fri, 28 Apr 2023 21:51:11 +0200 Subject: translate: fix use on subtype attribute in signal declaration Fix #2424 --- src/vhdl/translate/trans-chap4.adb | 30 ++++++++++++------------------ src/vhdl/translate/trans-chap6.adb | 12 ++++++++++-- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/vhdl/translate/trans-chap4.adb b/src/vhdl/translate/trans-chap4.adb index 2c33231c4..dfc83890b 100644 --- a/src/vhdl/translate/trans-chap4.adb +++ b/src/vhdl/translate/trans-chap4.adb @@ -1062,20 +1062,14 @@ package body Trans.Chap4 is Res.Already_Resolved := True; end if; end if; - case Get_Info (Targ_Type).Type_Mode is - when Type_Mode_Records => - Res.Value := Stabilize (Data.Value); - if Data.Has_Val then - Res.Init_Val := Stabilize (Data.Init_Val); - end if; - when Type_Mode_Arrays => - Res.Value := Chap3.Get_Composite_Base (Data.Value); - if Data.Has_Val then - Res.Init_Val := Chap3.Get_Composite_Base (Data.Init_Val); - end if; - when others => - raise Internal_Error; - end case; + + -- Stabilize for records as the values will be read for each element. + if Get_Info (Targ_Type).Type_Mode in Type_Mode_Records then + Res.Value := Stabilize (Data.Value); + if Data.Has_Val then + Res.Init_Val := Stabilize (Data.Init_Val); + end if; + end if; return Res; end Elab_Signal_Prepare_Composite; @@ -1097,14 +1091,14 @@ package body Trans.Chap4 is N_Init_Val : Mnode; begin if Data.Has_Val then - N_Init_Val := Chap3.Index_Base (Data.Init_Val, Targ_Type, - New_Obj_Value (Index)); + N_Init_Val := Chap6.Translate_Indexed_Name_By_Offset + (Data.Init_Val, Targ_Type, Index); else N_Init_Val := Mnode_Null; end if; return Elab_Signal_Data' - (Value => Chap3.Index_Base (Data.Value, Targ_Type, - New_Obj_Value (Index)), + (Value => Chap6.Translate_Indexed_Name_By_Offset + (Data.Value, Targ_Type, Index), Init_Val => N_Init_Val, Has_Val => Data.Has_Val, If_Stmt => null, diff --git a/src/vhdl/translate/trans-chap6.adb b/src/vhdl/translate/trans-chap6.adb index 608cab45a..01801eb20 100644 --- a/src/vhdl/translate/trans-chap6.adb +++ b/src/vhdl/translate/trans-chap6.adb @@ -506,18 +506,26 @@ package body Trans.Chap6 is function Translate_Indexed_Name_By_Offset (Prefix : Mnode; Prefix_Type : Iir; Offset : O_Dnode) return Mnode is + Pfx_Tinfo : constant Type_Info_Acc := Get_Type_Info (Prefix); El_Type : constant Iir := Get_Element_Subtype (Prefix_Type); El_Tinfo : constant Type_Info_Acc := Get_Info (El_Type); Kind : constant Object_Kind_Type := Get_Object_Kind (Prefix); + Pfx : Mnode; Fat_Res : Mnode; Base : Mnode; Bounds : Mnode; begin - Base := Chap3.Index_Array (Prefix, Prefix_Type, New_Obj_Value (Offset)); + if Is_Unbounded_Type (Pfx_Tinfo) then + Pfx := Stabilize (Prefix); + else + Pfx := Prefix; + end if; + + Base := Chap3.Index_Array (Pfx, Prefix_Type, New_Obj_Value (Offset)); if Is_Unbounded_Type (El_Tinfo) then Fat_Res := Create_Temp (El_Tinfo, Kind); - Bounds := Chap3.Get_Composite_Bounds (Prefix); + Bounds := Chap3.Get_Composite_Bounds (Pfx); Bounds := Chap3.Array_Bounds_To_Element_Bounds (Bounds, Prefix_Type); -- Assignment to M2Lp works as this is not a copy. -- cgit v1.2.3