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

            Bug ID: 108837
           Summary: Deferred string length component of DT + array section
                    passes the wrong array elements
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
  Target Milestone: ---

Created attachment 54482
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54482&action=edit
Draft patch - fixes the issue but does not regtest

The string handling for components seems to be still rather broken - and having
the string length saves twice, in a hidden string-length component and as
(elem_len / char-kind) looks also wrong + it does not quite work as 'allocate'
does not seem to update that len component for arrays.

Additionally, it feels very wrong to have  ts->u.cl.backend_decl =
int_zero_cst(...) in gfc_get_derived_type.

 * * *

However, the issue here is that the attached testcase has
   ['1a', '2b', '3c']
instead of the expected
   ['7g', '8h', '9i']
inside the called function as offset = 0 as TYPE_SIZE = 0

 * * *

The attached patch now uses elem_len of the array descriptor which should work
and also fixes the attached testcase.

However, there are now the following fails. I have not debugged them and it is
likely that the bug there is that elem_len is not properly set.

gfortran.dg/PR100120.f90 (execution)
gfortran.dg/array_reference_3.f90 (scan dump)
gfortran.dg/class_to_type_1.f03 (execution)
gfortran.dg/class_array_21.f03 (execution)
gfortran.dg/finalize_13.f90 (execution)

Additionally, it might be very well that more callers should pass the elemsz.

Reply via email to