Hi Peter,

On 2/19/24 16:19, Peter Hill wrote:
Hi Harald,

Thanks for your help, please see the updated and signed-off patch below.

great!  This is fine, and I'll commit it tomorrow unless others
have further comments.

It also occurred to me that array temporaries aren't _required_ here
(for arrays of derived type components), but in the general case with
a type with differently sized components, the stride wouldn't be a
multiple of the component's type's size. Is it possible in principle
to have an arbitrary stride?

It is possible to have an arbitrary (fixed, non-unit) stride,
but it is not always taken advantage of.

If you take the last version of the testcase and compile with
option -fdump-tree-original, you can see that the cases commented
with "no temp needed" actually create a suitable descriptor.
E.g.

    call print_poly (uu(2,2::2))

becomes:

    {
      struct __class__STAR_1_0t class.28;
      struct array01_integer(kind=4) parm.29;

class.28._vptr = (struct __vtype__STAR * {ref-all}) &__vtab_INTEGER_4_;
      parm.29.span = 4;
      parm.29.dtype = {.elem_len=4, .version=0, .rank=1, .type=1};
      parm.29.dim[0].lbound = 1;
      parm.29.dim[0].ubound = 3;
      parm.29.dim[0].stride = 10;
      parm.29.data = (void *) &uu[6];
      parm.29.offset = -10;
      class.28._data = parm.29;
      class.28._len = 0;
      print_poly (&class.28);
    }

Since we know that 'uu' is a contiguous array, we can calculate
the stride (10) for the 1-d section.

The case of the section of the character array is quite similar,
but the variant with the substring reference would need further
work to avoid the temporary.  (It would be possible.)

But as you say, the general case, which may involve types/classes,
does not map to a simple descriptor.

Thanks for your patch!

Harald


Reply via email to