From 8c5fdb98306e45ea1009e919d55623c87b61d03c Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Wed, 4 Aug 2021 10:27:17 +0200 Subject: vhdl: adjust ownership of agrgegate element subtypes. Fix #1419 Disable transfer of array aggregate element subtype ownership, but create the info of aggregate element subtype. --- src/vhdl/translate/trans-chap3.adb | 40 ++++++++++++++++++++++++++------------ src/vhdl/vhdl-sem_expr.adb | 5 +++-- 2 files changed, 31 insertions(+), 14 deletions(-) (limited to 'src/vhdl') diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb index 12916d12b..ce01f0a26 100644 --- a/src/vhdl/translate/trans-chap3.adb +++ b/src/vhdl/translate/trans-chap3.adb @@ -1175,13 +1175,18 @@ package body Trans.Chap3 is procedure Translate_Array_Subtype_Definition (Def : Iir) is Parent_Type : constant Iir := Get_Parent_Type (Def); - Parent_El_Type : constant Iir := Get_Element_Subtype (Parent_Type); El_Type : constant Iir := Get_Element_Subtype (Def); El_Tinfo : Type_Info_Acc; Mark : Id_Mark_Type; begin -- Handle element subtype. - if Get_Array_Element_Constraint (Def) /= Null_Iir then + El_Tinfo := Get_Info (El_Type); + if El_Tinfo = null then + -- Usually, if the array element subtype was not yet translated, + -- it's because it is defined by the array subtype (the array + -- subtype adds constraints to the elements). + -- However, for an aggregate, the array type may not be the owner. + -- Do not create vars for element subtype, but use -- the layout field of the array vars. Push_Identifier_Prefix (Mark, "ET"); @@ -1189,16 +1194,27 @@ package body Trans.Chap3 is Pop_Identifier_Prefix (Mark); El_Tinfo := Get_Info (El_Type); - if Is_Composite (El_Tinfo) then - pragma Assert (El_Tinfo.S.Composite_Layout = Null_Var); - El_Tinfo.S.Subtype_Owner := Get_Info (Def); - end if; - elsif Get_Info (El_Type) = null then - -- if the element subtype is created for this subtype, be sure it - -- has infos. - -- FIXME: the test should be refined. There can be a new element - -- subtype because a resolver has been added. - Set_Info (El_Type, Get_Info (Parent_El_Type)); + case El_Tinfo.S.Kind is + when Kind_Type_Array + | Kind_Type_Record => + pragma Assert (El_Tinfo.S.Composite_Layout = Null_Var); + El_Tinfo.S.Subtype_Owner := Get_Info (Def); + when Kind_Type_Scalar => + if El_Tinfo.S.Range_Var = Null_Var then + -- Happen only for subtypes of enumeration type ? + declare + El_Parent_Type : constant Iir := + Get_Element_Subtype (Parent_Type); + El_Parent_Tinfo : constant Type_Info_Acc := + Get_Info (El_Parent_Type); + begin + El_Tinfo.S.Range_Var := El_Parent_Tinfo.S.Range_Var; + end; + end if; + when Kind_Type_File + | Kind_Type_Protected => + raise Internal_Error; + end case; end if; if Get_Constraint_State (Def) = Fully_Constrained then diff --git a/src/vhdl/vhdl-sem_expr.adb b/src/vhdl/vhdl-sem_expr.adb index 0f46a8687..091bf0a0b 100644 --- a/src/vhdl/vhdl-sem_expr.adb +++ b/src/vhdl/vhdl-sem_expr.adb @@ -3579,7 +3579,8 @@ package body Vhdl.Sem_Expr is -- TODO: try to extract the 'best' element subtype: with -- static indexes, with constrained sub-elements. -- Possibly create an hybrid subtype (for records). - if Get_Index_Constraint_Flag (New_El_Subtype) then + if Get_Constraint_State (New_El_Subtype) = Fully_Constrained + then El_Subtype := New_El_Subtype; return; end if; @@ -4090,7 +4091,7 @@ package body Vhdl.Sem_Expr is else A_Subtype := Create_Array_Subtype (Base_Type, Get_Location (Aggr)); Set_Element_Subtype (A_Subtype, El_Subtype); - if El_Subtype /= El_Type then + if False and then El_Subtype /= El_Type then -- If the element subtype is defined by an element of the -- aggregate, move the ownership to the aggregate type. Sem_Array_Aggregate_Move_Element_Subtype_Owner -- cgit v1.2.3