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

            Bug ID: 87448
           Summary: ICE at trans-expr:3417 in allocate statement with type
                    signature using an associated variable
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mscfd at gmx dot net
  Target Milestone: ---

The following code triggers an ICE (also seen in some gfortran-7 version):

module mod

implicit none
public

contains

function fun(cs) result(rs)
   character(len=:), allocatable :: rs
   character(len=*), intent(in) :: cs

   associate(l => len(cs))
      allocate(character(len=1+l) :: rs)
   end associate
end function fun

end module mod


gfortran -c assoc_len.f90 gives

assoc_len.f90:13:0:

       allocate(character(len=1+l) :: rs)

internal compiler error: in gfc_conv_expr_op, at fortran/trans-expr.c:3417
0x5b156d gfc_conv_expr_op
        ../.././gcc/fortran/trans-expr.c:3417
0x5b156d gfc_conv_expr(gfc_se*, gfc_expr*)
        ../.././gcc/fortran/trans-expr.c:7918
0x72bfb9 gfc_trans_allocate(gfc_code*)
        ../.././gcc/fortran/trans-stmt.c:6115
0x6bc4b7 trans_code
        ../.././gcc/fortran/trans.c:1996
0x72858f gfc_trans_block_construct(gfc_code*)
        ../.././gcc/fortran/trans-stmt.c:2058
0x6bc527 trans_code
        ../.././gcc/fortran/trans.c:1924
0x6e293b gfc_generate_function_code(gfc_namespace*)
        ../.././gcc/fortran/trans-decl.c:6507
0x6bfec9 gfc_generate_module_code(gfc_namespace*)
        ../.././gcc/fortran/trans.c:2222
0x6734f4 translate_all_program_units
        ../.././gcc/fortran/parse.c:6108
0x6734f4 gfc_parse_file()
        ../.././gcc/fortran/parse.c:6324
0x6b991f gfc_be_parse_file
        ../.././gcc/fortran/f95-lang.c:204

The problem is triggered by the combination of using associate in conjunction
with the allocate. With a local variable instead of the associate for l, or
with another statement instead of an allocate (i.e. "print *,l), gfortran
compiles.
Also when simplifying the length expression in the allocate from "len=1+l" to
just "len=l" the ICE disappears.

Reply via email to