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

            Bug ID: 128936
           Summary: [PDT] LEN of a character array component with a
                    LEN-parameter length is not scalar
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jvdelisle at gcc dot gnu.org
  Target Milestone: ---

Created attachment 66250
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66250&action=edit
Draft patch to fix this one.

For a parameterized derived type whose CHARACTER array component has
a length given by a LEN parameter, LEN of that component is folded to
the type parameter but keeps the rank of the component and drops the
array reference of the base object.  The result is a rejected
assignment, an ICE, or an ignored KIND= argument:

  type t(n)
    integer, len :: n
    character(len=n) :: ch(2)
  end type

1) Rejected:

  type(t(4)) :: x
  integer :: i
  i = len (x%ch)

  Error: Incompatible ranks 0 and 1 in assignment at (1)

2) ICE with an array of the type:

  type(t(4)) :: y(3)
  print *, len (y(2)%ch)

  17.0:   internal compiler error: in gfc_trans_transfer, at
          fortran/trans-io.cc:2649
  16.2.1: internal compiler error: in wide_int_to_tree_1, at
          tree.cc:1900

3) KIND= ignored:

  type(t(4)) :: x
  print *, kind (len (x%ch, kind=8))

  17.0 prints 4, expected 8.  16.2.1 ICEs in wide_int_to_tree_1.

A related ICE affects a type parameter inquiry on an array section,
which is scalar even if the designator is an array (F2023 9.4.5,
Note 1):

  type t(n)
    integer, len :: n
    character(len=n) :: s
  end type
  type(t(4)) :: y(3)
  print *, y(2:3)%n

  17.0:   f951: internal compiler error: free_expr0(): Bad expr type
  16.2.1: compiles but prints "4 4" instead of the scalar 4.

reset_array_ref_to_scalar in resolve.cc, which makes the inquiry
scalar, frees the end and stride of the section without clearing
them, so they are freed a second time later.

Expected: LEN (x%ch) and y(2:3)%n are scalars equal to 4, and
LEN (x%ch, kind=8) has kind 8.

Fix available - patch attached.
  • [Bug fortran/128936] New: [PDT] ... jvdelisle at gcc dot gnu.org via Gcc-bugs

Reply via email to