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

            Bug ID: 106367
           Summary: ICE in fold_convert_loc.c when referencing an
                    array-of-structure-eleents from within a polymorphic
                    function
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: federico.perini at gmail dot com
  Target Milestone: ---

Created attachment 53321
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53321&action=edit
test program

I get an ICE with all gfortran versions from 5 to 12 when having a type-bound
procedure that creates an array from some of its structure components.

The error does not appear if the same command is called not within a function,
or, the when the function argument is not polymorphic.


The error (on 11.3.0) points to 

  31 |         array = c%list%indices(c%v(1:)%flag)
      |                                            1
internal compiler error: in fold_convert_loc, at fold-const.c:2440

This is a minimal program that reproduces the error. It was part of a far more
complex structure: 

```
module mymod
    implicit none

    type vert
        integer :: flag    = 0 ! The fvm node flag (16 exploitable bits)
    end type vert

    type contnr
        type(vert), allocatable :: v(:)
        integer, allocatable :: list(:)

        contains
           procedure :: poly_get_list
    end type contnr

    contains

    ! Polymorphic function causes ICE
    function poly_get_list(c) result(array)
        class(contnr), intent(in) :: c
        integer, allocatable :: array(:)

        ! ICE internal compiler error: in fold_convert_loc, at
fold-const.c:2440 (11.3.0)
        ! when this is put into a function
        array = c%list(c%v(1:)%flag)

    end function poly_get_list

    ! Non-polymorphic version works
    function get_list(c) result(array)
        type(contnr), intent(in) :: c
        integer, allocatable :: array(:)

        array = c%list(c%v(1:)%flag)

    end function get_list

end module mymod

program arrayOfStruct
    use mymod
    implicit none

    type(contnr) :: c
    integer :: i

    allocate(c%v(-1:100),c%list(-1:100))
    forall(i=1:100)
        c%v(i)%flag = i
        c%list(i) = 100-i+1
    end forall

    ! Direct: works!
    print "(*(1x,i0))", c%list(c%v(1:)%flag)

    ! Wrapped with TYPE(contnr): works!
    print "(*(1x,i0))", get_list(c)

    ! Wrapped with polymorphic CLASS(contnr): ICE
    ! Wrapped with TYPE(contnr): works!
    print "(*(1x,i0))", c%poly_get_list()

end program arrayOfStruct


```

Reply via email to