PR fortran/93524 - rank >= 3 array stride incorrectly set in CFI_establish
Harris Snyder
hsnyder@structura.bio
Wed Jan 27 19:38:04 GMT 2021
Hi all,
Now that my copyright assignment is complete, I'm submitting this fix.
Test cases are included.
OK for master? I do not have write access, so someone will need to
commit this for me.
Regards,
Harris
libgfortran/ChangeLog:
* runtime/ISO_Fortran_binding.c (CFI_establish): fixed strides
for rank >2 arrays
gcc/testsuite/ChangeLog:
* gfortran.dg/ISO_Fortran_binding_18.c: New test.
* gfortran.dg/ISO_Fortran_binding_18.f90: New test.
On Wed, Jan 13, 2021 at 2:10 PM Harris Snyder <hsnyder@structura.bio> wrote:
>
> Hi Tobias / all,
>
> Further related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93524
> `sm` is being incorrectly computed in CFI_establish. Take a look at
> the diff below - we are currently only using the extent of the
> previous rank to assign `sm`, instead of all previous ranks. Have I
> got this right, or am I missing something / does this need to be
> handled differently? I can offer some test cases and submit a proper
> patch if we think this solution is OK...
>
> Thanks,
> Harris
>
> diff --git a/libgfortran/runtime/ISO_Fortran_binding.c
> b/libgfortran/runtime/ISO_Fortran_binding.c
> index 3746ec1c681..20833ad2025 100644
> --- a/libgfortran/runtime/ISO_Fortran_binding.c
> +++ b/libgfortran/runtime/ISO_Fortran_binding.c
> @@ -391,7 +391,12 @@ int CFI_establish (CFI_cdesc_t *dv, void
> *base_addr, CFI_attribute_t attribute,
> if (i == 0)
> dv->dim[i].sm = dv->elem_len;
> else
> - dv->dim[i].sm = (CFI_index_t)(dv->elem_len * extents[i - 1]);
> + {
> + CFI_index_t extents_product = 1;
> + for (int j = 0; j < i; j++)
> + extents_product *= extents[j];
> + dv->dim[i].sm = (CFI_index_t)(dv->elem_len * extents_product);
> + }
> }
> }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hsnyder_iso_fortran_binding2.patch
Type: application/x-patch
Size: 2662 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/fortran/attachments/20210127/8d954220/attachment.bin>
More information about the Fortran
mailing list