https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94578
--- Comment #9 from Thomas Koenig <tkoenig at gcc dot gnu.org> --- Here's what a solution could look like. I am not really sure that this is the way to go, there may be some corner cases (pointer to an argument which was passed as a transposed argument?) which this might get wrong. diff --git a/libgfortran/generated/maxval_i4.c b/libgfortran/generated/maxval_i4.c index abad45b50ae..3a9ed436956 100644 --- a/libgfortran/generated/maxval_i4.c +++ b/libgfortran/generated/maxval_i4.c @@ -50,6 +50,7 @@ maxval_i4 (gfc_array_i4 * const restrict retarray, index_type delta; index_type dim; int continue_loop; + int ret_factor; /* Make dim zero based to avoid confusion. */ rank = GFC_DESCRIPTOR_RANK (array) - 1; @@ -112,6 +113,7 @@ maxval_i4 (gfc_array_i4 * const restrict retarray, return; } + ret_factor = 1; } else { @@ -124,12 +126,16 @@ maxval_i4 (gfc_array_i4 * const restrict retarray, if (unlikely (compile_options.bounds_check)) bounds_ifunction_return ((array_t *) retarray, extent, "return value", "MAXVAL"); + if (retarray->span != 0) + ret_factor = retarray->span / sizeof(GFC_INTEGER_4); + else + ret_factor = 1; } for (n = 0; n < rank; n++) { count[n] = 0; - dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n); + dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n) * ret_factor; if (extent[n] <= 0) return; }