From 77476d6ecc45f1761125524cbdeddfe74e3b157a Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Mon, 13 Sep 2021 21:51:43 +0200 Subject: ortho: for slices, get element size from the result type and not from the object type. Fix #1862 --- src/ortho/gcc/ortho-lang-49.c | 11 ++++++++++- src/ortho/gcc/ortho-lang-5.c | 11 ++++++++++- src/ortho/gcc/ortho-lang-6.c | 11 ++++++++++- src/ortho/gcc/ortho-lang-7.c | 11 ++++++++++- src/ortho/gcc/ortho-lang-8.c | 11 ++++++++++- src/ortho/gcc/ortho-lang-9.c | 11 ++++++++++- 6 files changed, 60 insertions(+), 6 deletions(-) (limited to 'src/ortho/gcc') 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 -- cgit v1.2.3