From 1cdca4261e88f4dc9c3293c6b3c2fff3071ca32b Mon Sep 17 00:00:00 2001 From: Harris Snyder Date: Wed, 27 Jan 2021 22:54:04 +0100 Subject: Fix strides for C descriptors with stride > 2. 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. --- libgfortran/runtime/ISO_Fortran_binding.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'libgfortran/runtime') diff --git a/libgfortran/runtime/ISO_Fortran_binding.c b/libgfortran/runtime/ISO_Fortran_binding.c index 3746ec1..20833ad 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); + } } } -- cgit v1.1