[PATCH 01/12] fortran: array descriptor: Use the setter to modify the offset [PR122521]
Mikael Morin <[email protected]> Sat, 11 Jul 2026 16:46:28 +0200
| Newsgroups | gmane.comp.gcc.patches,gmane.comp.gcc.fortran |
|---|---|
| Message-ID | <[email protected]> |
From: Mikael Morin <[email protected]> Regression tested on aarch64-unknown-linux-gnu. OK for master? -- >8 -- Use the setter function to generate code modifying the array descriptor offset and remove from the public API the function giving direct access to that field. PR fortran/122521 gcc/fortran/ChangeLog: * trans-descriptor.cc (gfc_conv_descriptor_offset): Make static and rename ... (conv_descriptor_offset): ... to this. (gfc_conv_descriptor_offset_get, gfc_conv_descriptor_offset_set): Update callers. * trans-descriptor.h (gfc_conv_descriptor_offset): Remove declaration. * trans-array.cc (gfc_alloc_allocatable_for_assignment): Use the setter function to generate a modification of the array descriptor offset. --- gcc/fortran/trans-array.cc | 3 +-- gcc/fortran/trans-descriptor.cc | 15 +++++++++++---- gcc/fortran/trans-descriptor.h | 1 - 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 871a83207f3..950ebf75813 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -12056,8 +12056,7 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo *loop, /* Set the lhs descriptor and scalarizer offsets. For rank > 1, the array offset is saved and the info.offset is used for a running offset. Use the saved_offset instead. */ - tmp = gfc_conv_descriptor_offset (desc); - gfc_add_modify (&fblock, tmp, offset); + gfc_conv_descriptor_offset_set (&fblock, desc, offset); /* Take into account _len of unlimited polymorphic entities, so that span for array descriptors and allocation sizes are computed correctly. */ diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc index 79c6439c08f..d24e5c6f178 100644 --- a/gcc/fortran/trans-descriptor.cc +++ b/gcc/fortran/trans-descriptor.cc @@ -98,24 +98,31 @@ gfc_conv_descriptor_data_set (stmtblock_t *block, tree desc, tree value) } -tree -gfc_conv_descriptor_offset (tree desc) +/* Return a reference to the offset field of the array descriptor DESC. */ + +static tree +conv_descriptor_offset (tree desc) { tree field = gfc_get_descriptor_field (desc, OFFSET_FIELD); gcc_assert (TREE_TYPE (field) == gfc_array_index_type); return field; } +/* Return the offset value of the array descriptor DESC. */ + tree gfc_conv_descriptor_offset_get (tree desc) { - return gfc_conv_descriptor_offset (desc); + return conv_descriptor_offset (desc); } +/* Add code to BLOCK assigning VALUE to the offset field of the array descriptor + DESC. */ + void gfc_conv_descriptor_offset_set (stmtblock_t *block, tree desc, tree value) { - tree t = gfc_conv_descriptor_offset (desc); + tree t = conv_descriptor_offset (desc); gfc_add_modify (block, t, fold_convert (TREE_TYPE (t), value)); } diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h index 816973825b6..b68a28bddff 100644 --- a/gcc/fortran/trans-descriptor.h +++ b/gcc/fortran/trans-descriptor.h @@ -29,7 +29,6 @@ tree gfc_conv_descriptor_type (tree); tree gfc_get_descriptor_dimension (tree); tree gfc_conv_descriptor_dimension (tree, tree); tree gfc_conv_descriptor_token (tree); -tree gfc_conv_descriptor_offset (tree); tree gfc_conv_descriptor_data_get (tree); tree gfc_conv_descriptor_offset_get (tree); -- 2.53.0