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

--- Comment #3 from federico <federico.perini at gmail dot com> ---
Analysis (-fdump-tree-original):

The caller first builds the transpose(a) descriptor correctly by swapping dims,
no copy — shape [4,3], strides (3,1):

parm.12.dim[0].ubound = 4;  parm.12.dim[0].stride = 3;
parm.12.dim[1].ubound = 3;  parm.12.dim[1].stride = 1;

For the CONTIGUOUS dummy it then packs parm.12 and builds the temp descriptor —
but swaps the dims a second time:

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.

Reply via email to