diff options
-rw-r--r-- | src/ortho/debug/ortho_debug.adb | 2 | ||||
-rw-r--r-- | src/ortho/gcc/ortho-lang-49.c | 11 | ||||
-rw-r--r-- | src/ortho/gcc/ortho-lang-5.c | 11 | ||||
-rw-r--r-- | src/ortho/gcc/ortho-lang-6.c | 11 | ||||
-rw-r--r-- | src/ortho/gcc/ortho-lang-7.c | 11 | ||||
-rw-r--r-- | src/ortho/gcc/ortho-lang-8.c | 11 | ||||
-rw-r--r-- | src/ortho/gcc/ortho-lang-9.c | 11 | ||||
-rw-r--r-- | src/ortho/mcode/ortho_code-exprs.adb | 9 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap3.adb | 4 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap6.adb | 12 |
10 files changed, 76 insertions, 17 deletions
diff --git a/src/ortho/debug/ortho_debug.adb b/src/ortho/debug/ortho_debug.adb index 9961fd2e0..2feda5932 100644 --- a/src/ortho/debug/ortho_debug.adb +++ b/src/ortho/debug/ortho_debug.adb @@ -1122,7 +1122,7 @@ package body Ortho_Debug is raise Type_Error; end if; -- The element type of ARR must be constrained. - Check_Constrained_Type (Get_Array_El_Type (Arr.Rtype)); + Check_Constrained_Type (Get_Array_El_Type (Res_Type)); -- The result is an array. if Res_Type.Kind not in ON_Array_Kinds then raise Type_Error; diff --git a/src/ortho/gcc/ortho-lang-49.c b/src/ortho/gcc/ortho-lang-49.c index f5586bf41..a411ba813 100644 --- a/src/ortho/gcc/ortho-lang-49.c +++ b/src/ortho/gcc/ortho-lang-49.c @@ -1500,8 +1500,17 @@ new_slice (tree arr, tree res_type, tree index) TREE_TYPE (TYPE_DOMAIN (res_type))); } + /* Take the element size from RES_TYPE (and not from ARR, which is the + default. */ + tree elmt_type = TREE_TYPE (res_type); + tree elmt_size = TYPE_SIZE_UNIT (elmt_type); + tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type)); + + /* Divide the element size by the alignment of the element type (above). */ + elmt_size = size_binop (EXACT_DIV_EXPR, elmt_size, factor); + ortho_mark_addressable (arr); - return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, NULL_TREE); + return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, elmt_size); } tree diff --git a/src/ortho/gcc/ortho-lang-5.c b/src/ortho/gcc/ortho-lang-5.c index 66233d49e..647854bb0 100644 --- a/src/ortho/gcc/ortho-lang-5.c +++ b/src/ortho/gcc/ortho-lang-5.c @@ -1486,8 +1486,17 @@ new_slice (tree arr, tree res_type, tree index) TREE_TYPE (TYPE_DOMAIN (res_type))); } + /* Take the element size from RES_TYPE (and not from ARR, which is the + default. */ + tree elmt_type = TREE_TYPE (res_type); + tree elmt_size = TYPE_SIZE_UNIT (elmt_type); + tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type)); + + /* Divide the element size by the alignment of the element type (above). */ + elmt_size = size_binop (EXACT_DIV_EXPR, elmt_size, factor); + ortho_mark_addressable (arr); - return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, NULL_TREE); + return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, elmt_size); } tree diff --git a/src/ortho/gcc/ortho-lang-6.c b/src/ortho/gcc/ortho-lang-6.c index 15649c8ae..736d0ddce 100644 --- a/src/ortho/gcc/ortho-lang-6.c +++ b/src/ortho/gcc/ortho-lang-6.c @@ -1486,8 +1486,17 @@ new_slice (tree arr, tree res_type, tree index) TREE_TYPE (TYPE_DOMAIN (res_type))); } + /* Take the element size from RES_TYPE (and not from ARR, which is the + default. */ + tree elmt_type = TREE_TYPE (res_type); + tree elmt_size = TYPE_SIZE_UNIT (elmt_type); + tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type)); + + /* Divide the element size by the alignment of the element type (above). */ + elmt_size = size_binop (EXACT_DIV_EXPR, elmt_size, factor); + ortho_mark_addressable (arr); - return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, NULL_TREE); + return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, elmt_size); } tree diff --git a/src/ortho/gcc/ortho-lang-7.c b/src/ortho/gcc/ortho-lang-7.c index 1bc705298..b87e4d60c 100644 --- a/src/ortho/gcc/ortho-lang-7.c +++ b/src/ortho/gcc/ortho-lang-7.c @@ -1498,8 +1498,17 @@ new_slice (tree arr, tree res_type, tree index) TREE_TYPE (TYPE_DOMAIN (res_type))); } + /* Take the element size from RES_TYPE (and not from ARR, which is the + default. */ + tree elmt_type = TREE_TYPE (res_type); + tree elmt_size = TYPE_SIZE_UNIT (elmt_type); + tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type)); + + /* Divide the element size by the alignment of the element type (above). */ + elmt_size = size_binop (EXACT_DIV_EXPR, elmt_size, factor); + ortho_mark_addressable (arr); - return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, NULL_TREE); + return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, elmt_size); } tree diff --git a/src/ortho/gcc/ortho-lang-8.c b/src/ortho/gcc/ortho-lang-8.c index d710c8b99..d6d72b0a9 100644 --- a/src/ortho/gcc/ortho-lang-8.c +++ b/src/ortho/gcc/ortho-lang-8.c @@ -1499,8 +1499,17 @@ new_slice (tree arr, tree res_type, tree index) TREE_TYPE (TYPE_DOMAIN (res_type))); } + /* Take the element size from RES_TYPE (and not from ARR, which is the + default. */ + tree elmt_type = TREE_TYPE (res_type); + tree elmt_size = TYPE_SIZE_UNIT (elmt_type); + tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type)); + + /* Divide the element size by the alignment of the element type (above). */ + elmt_size = size_binop (EXACT_DIV_EXPR, elmt_size, factor); + ortho_mark_addressable (arr); - return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, NULL_TREE); + return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, elmt_size); } tree diff --git a/src/ortho/gcc/ortho-lang-9.c b/src/ortho/gcc/ortho-lang-9.c index 622bd5b38..cd3e14240 100644 --- a/src/ortho/gcc/ortho-lang-9.c +++ b/src/ortho/gcc/ortho-lang-9.c @@ -1499,8 +1499,17 @@ new_slice (tree arr, tree res_type, tree index) TREE_TYPE (TYPE_DOMAIN (res_type))); } + /* Take the element size from RES_TYPE (and not from ARR, which is the + default. */ + tree elmt_type = TREE_TYPE (res_type); + tree elmt_size = TYPE_SIZE_UNIT (elmt_type); + tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type)); + + /* Divide the element size by the alignment of the element type (above). */ + elmt_size = size_binop (EXACT_DIV_EXPR, elmt_size, factor); + ortho_mark_addressable (arr); - return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, NULL_TREE); + return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, elmt_size); } tree diff --git a/src/ortho/mcode/ortho_code-exprs.adb b/src/ortho/mcode/ortho_code-exprs.adb index cb913a49d..b8cd698e8 100644 --- a/src/ortho/mcode/ortho_code-exprs.adb +++ b/src/ortho/mcode/ortho_code-exprs.adb @@ -893,15 +893,13 @@ package body Ortho_Code.Exprs is end Extract_Pow2; function New_Index_Slice_Element - (Arr : O_Lnode; Index : O_Enode; Res_Type : O_Tnode) + (Arr : O_Lnode; Index : O_Enode; Res_Type : O_Tnode; El_Type : O_Tnode) return O_Lnode is - El_Type : O_Tnode; In_Type : O_Tnode; Sz : O_Enode; El_Size : Uns32; begin - El_Type := Get_Type_Array_Element (Get_Enode_Type (O_Enode (Arr))); In_Type := Get_Enode_Type (Index); if Flag_Debug_Assert then @@ -953,7 +951,7 @@ package body Ortho_Code.Exprs is if Flag_Debug_Hli then return New_Hli_Index_Slice (OE_Index_Ref, El_Type, Arr, Index); else - return New_Index_Slice_Element (Arr, Index, El_Type); + return New_Index_Slice_Element (Arr, Index, El_Type, El_Type); end if; end New_Indexed_Element; @@ -969,7 +967,8 @@ package body Ortho_Code.Exprs is if Flag_Debug_Hli then return New_Hli_Index_Slice (OE_Slice_Ref, Res_Type, Arr, Index); else - return New_Index_Slice_Element (Arr, Index, Res_Type); + return New_Index_Slice_Element + (Arr, Index, Res_Type, Get_Type_Array_Element (Res_Type)); end if; end New_Slice; diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb index 9291bd38b..f09601066 100644 --- a/src/vhdl/translate/trans-chap3.adb +++ b/src/vhdl/translate/trans-chap3.adb @@ -1180,6 +1180,10 @@ package body Trans.Chap3 is if Info.Type_Locally_Constrained then Arr := Arr_Def; else + -- If the element has been constrained, there is no ortho array + -- with the constrained element. So use the base type as a fall + -- back (if the element cannot be constrained, it is the same as the + -- base type element). Arr := Get_Base_Type (Arr_Def); end if; return Get_Element_Subtype (Arr); diff --git a/src/vhdl/translate/trans-chap6.adb b/src/vhdl/translate/trans-chap6.adb index 1e5fe6bc2..1f4edde79 100644 --- a/src/vhdl/translate/trans-chap6.adb +++ b/src/vhdl/translate/trans-chap6.adb @@ -558,15 +558,14 @@ package body Trans.Chap6 is -- Type of the first (and only) index of the prefix array type. Index_Type : constant Iir := Get_Index_Type (Prefix_Type, 0); - -- Element type. - El_Type : constant Iir := - Chap3.Get_Element_Subtype_For_Info (Prefix_Type); - El_Tinfo : constant Type_Info_Acc := Get_Info (El_Type); - -- Type of the slice. Slice_Type : constant Iir := Get_Type (Expr); Slice_Info : Type_Info_Acc; + -- Element type. + El_Type : Iir; + El_Tinfo : Type_Info_Acc; + -- Suffix of the slice (discrete range). Expr_Range : constant Iir := Get_Suffix (Expr); @@ -597,6 +596,9 @@ package body Trans.Chap6 is Prefix_Var := Prefix; + El_Type := Chap3.Get_Element_Subtype_For_Info (Slice_Type); + El_Tinfo := Get_Info (El_Type); + if Is_Unbounded_Type (El_Tinfo) then -- Copy layout of element before building the bounds -- pragma Assert (Is_Unbounded_Type (Prefix_Info)); |