https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125998

--- Comment #10 from Mikael Morin <mikael at gcc dot gnu.org> ---
(In reply to Mikael Morin from comment #9)
> I have the impression that the problem is more in gfc_conv_subref_array_arg
> though.
Or rather gfc_conv_array_parameter (gfc_conv_subref_array_arg is not used for
the testcase).


(In reply to federico from comment #3)
> D.3111 = _gfortran_internal_pack (&parm.12);   // tight 4×3 buffer
> arg_desc.14.dim[0] = parm.12.dim[1];   // BUG: extent 3, stride 1
> arg_desc.14.dim[1] = parm.12.dim[0];   // BUG: extent 4, stride 3
> 
> Since parm.12 is already the transposed descriptor, re-swapping
> un-transposes it back to a's [3,4] layout — hence the wrong shape. The
> strides are wrong too: internal_pack produced a tight 4×3 buffer (correct
> descriptor: dim[0]{4,1}, dim[1]{3,4}), but arg_desc.14 indexes it as 3×4
> with stride 3, so the values are also corrupt. The defect is in the
> descriptor construction around internal_pack in the contiguous repack path.
I think your analysis is correct.
The following fixes the testcase, but is probably insufficient: the strides
need to be recalculated.

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 2a5c8f36667..829996ad657 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -9254,7 +9254,7 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr,
bool g77,
                  for (int i = 0; i < expr->rank; i++)
                    {
                      old_field = gfc_conv_descriptor_dimension (old_desc,
-                       gfc_rank_cst[get_array_ref_dim_for_loop_dim (ss, i)]);
+                       gfc_rank_cst[i]);
                      new_field = gfc_conv_descriptor_dimension (new_desc,
                        gfc_rank_cst[i]);
                      gfc_add_modify (&se->pre, new_field, old_field);

Reply via email to