An ICE with a variable length array in a derived type

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

An ICE with a variable length array in a derived type

Jorge D'ELIA
Hi all,

The following test with a variable length array in a derived type
gives me an internal compiler error, test that also contains a
workaround.


Regards,
Jorge.

$ which gfortran
$ gfortran --version
  GNU Fortran (GCC) 10.0.0 20191002 (experimental)
$ gfortran -std=f2018 -Wall -Wextra -Wsurprising -o test.exe test.f90

test.f90:48:0:

   48 |   mt1 = mytype(1, 20.0, 30.0)  !ICE with GNU Fortran (GCC) 10.0.0 20191002 (exp)
      |
internal compiler error: in gfc_conv_expr_descriptor, at fortran/trans-array.c:7190
0x5aa88f gfc_conv_expr_descriptor(gfc_se*, gfc_expr*)
        ../../gcc/fortran/trans-array.c:7190
0x8db55d gfc_trans_alloc_subarray_assign
        ../../gcc/fortran/trans-expr.c:7767
0x8de987 gfc_trans_subcomponent_assign
        ../../gcc/fortran/trans-expr.c:8106
0x8dfd1c gfc_trans_structure_assign(tree_node*, gfc_expr*, bool, bool)
        ../../gcc/fortran/trans-expr.c:8389
0x8e0bc0 gfc_conv_structure(gfc_se*, gfc_expr*, int)
        ../../gcc/fortran/trans-expr.c:8456
0x8e2abd gfc_trans_assignment_1
        ../../gcc/fortran/trans-expr.c:10795
0x89c4a8 trans_code
        ../../gcc/fortran/trans.c:1852
0x8ca240 gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6781
0x84c9dc translate_all_program_units
        ../../gcc/fortran/parse.c:6254
0x84c9dc gfc_parse_file()
        ../../gcc/fortran/parse.c:6493
0x89721b gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:204
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.

$ cat test.f90

!--- begin example ---
! Test example adapted from
! https://stackoverflow.com/questions/52727324/
!           /variable-length-array-in-derived-type
!        – Rodrigo Rodrigues Oct 10 '18 at 21:22
module m_pdt
   !
  type :: mytype (n)
    integer, len :: n
    real         :: x1
    real, dimension (n) :: x2
  end type mytype
  !
end module m_pdt
!
program test_pdt
  use m_adt
  implicit none
  !
  type (mytype (1)) :: mt1
  type (mytype(10)) :: mt2
  integer :: i
  !
 !mt1 = mytype(1)(20.0,[30.0]) !Error: Invalid character in name at (1)
 !mt1 = mytype(1, 20.0,[30.0]) !a workarround
  mt1 = mytype(1, 20.0, 30.0)  !ICE with GNU Fortran (GCC) 10.0.0 20191002 (exp)
  !
  mt2%x1 = 40.0
  mt2%x2 = [(0.5*i, i=1,10)]
  !
  call sub2 (mt1)
  call sub1 (mt2)
  !
contains
  !
  subroutine sub1 (m)
    type (mytype(*)) :: m          ! accepts values with any n parameter
    integer, dimension (m%n+1):: y ! it can also used in declarations
    type (mytype(m%n)) :: w
    print *, m%n, w%n, size(y)
  end subroutine sub1
  !
  subroutine sub2 (m)
    type (mytype(1)) :: m          ! only accepts values with n=1
    print *, m%x1, m%x2, m%n
  end subroutine sub2
  !
end program test_pdt
!--- end example ---