aboutsummaryrefslogtreecommitdiffstats
path: root/src/ortho
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2021-09-13 21:51:43 +0200
committerTristan Gingold <tgingold@free.fr>2021-09-14 04:16:51 +0200
commit77476d6ecc45f1761125524cbdeddfe74e3b157a (patch)
treef6107b185b8c92f28e99d129e839a0c28fbe211e /src/ortho
parent95cbcc921d92d58dbd25d328de60c18976083d2a (diff)
downloadghdl-77476d6ecc45f1761125524cbdeddfe74e3b157a.tar.gz
ghdl-77476d6ecc45f1761125524cbdeddfe74e3b157a.tar.bz2
ghdl-77476d6ecc45f1761125524cbdeddfe74e3b157a.zip
ortho: for slices, get element size from the result type
and not from the object type. Fix #1862
Diffstat (limited to 'src/ortho')
-rw-r--r--src/ortho/debug/ortho_debug.adb2
-rw-r--r--src/ortho/gcc/ortho-lang-49.c11
-rw-r--r--src/ortho/gcc/ortho-lang-5.c11
-rw-r--r--src/ortho/gcc/ortho-lang-6.c11
-rw-r--r--src/ortho/gcc/ortho-lang-7.c11
-rw-r--r--src/ortho/gcc/ortho-lang-8.c11
-rw-r--r--src/ortho/gcc/ortho-lang-9.c11
-rw-r--r--src/ortho/mcode/ortho_code-exprs.adb9
8 files changed, 65 insertions, 12 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;