parametrized derived-data type with variable string

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

parametrized derived-data type with variable string

albertop
Hello,

I am trying to compile a sample program that contains a parametrized derived-data type with a variable length string inside.
The idea is just to test the compatibility of such complex structures with embedded deferred-size objects.
The first sample works well will flang-20181226, but it gives error with gcc-8.3.0.

-----------------------------------%<-----------------------------------
program mytest
implicit none

type :: BookDef(n)
    integer, len :: n
    character(len=n) :: title
end type BookDef

character(len=100) :: mytitle
character(len=100) :: tail = "12345"
integer :: mylen
type(BookDef(:)), allocatable :: mybook

mytitle = "This is my title"
mylen = len_trim(mytitle) + len_trim(tail)
allocate(type(BookDef(mylen)) :: mybook)

mybook%title = trim(mytitle)//trim(tail)
write(*,*) mybook%title

end program mytest

$ gfortran -v -save-temps -g mytest.f90
Driving: gfortran -v -save-temps -g mytest.f90 -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/home/alberto/software/gcc-8.3.0/libexec/gcc/x86_64-pc-linux-gnu/8.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/home/alberto/software/gcc-8.3.0 --enable-checking=release --disable-multilib
Thread model: posix
gcc version 8.3.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /home/alberto/software/gcc-8.3.0/libexec/gcc/x86_64-pc-linux-gnu/8.3.0/f951 mytest.f90 -quiet -dumpbase mytest.f90 -mtune=generic -march=x86-64 -auxbase mytest -g -version -fintrinsic-modules-path /home/alberto/software/gcc-8.3.0/lib/gcc/x86_64-pc-linux-gnu/8.3.0/finclude -o mytest.s
GNU Fortran (GCC) version 8.3.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Fortran2008 (GCC) version 8.3.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
mytest.f90:16:9:

 allocate(type(BookDef(mylen)) :: mybook)
         1
Error: Allocate-object at (1) is neither a data pointer nor an allocatable variable
----------------------------------->%-----------------------------------

Trying a slightly different approach consisting of embedding the parametrized derived-data type inside another type, gcc-8.3.0 crashes.
This time flang-20181226 does not work as well.

-----------------------------------%<-----------------------------------
program mytestembd
implicit none

type :: BookDef(n)
    integer, len :: n
    character(len=n) :: title
end type BookDef

type :: BookOuter
    type(BookDef(50)) :: innerbook
end type BookOuter

character(len=100) :: mytitle = "This is my title"
character(len=100) :: tail = "12345"
type(BookOuter) :: mybook

mybook%innerbook%title = trim(mytitle)//trim(tail)
write(*,*) mybook%innerbook%title

end program mytestembd

$ gfortran -g mytestembd.f90
mytestembd.f90:1:0:

 program mytestembd
 
internal compiler error: in gfc_get_derived_type, at fortran/trans-types.c:2545
0x5c7335 gfc_get_derived_type(gfc_symbol*, int)
        ../../gcc/fortran/trans-types.c:2545
0x755c28 gfc_get_derived_type(gfc_symbol*, int)
        ../../gcc/fortran/trans-types.c:2691
0x756618 gfc_typenode_for_spec(gfc_typespec*, int)
        ../../gcc/fortran/trans-types.c:1203
0x7568dc gfc_sym_type(gfc_symbol*)
        ../../gcc/fortran/trans-types.c:2272
0x7568dc gfc_sym_type(gfc_symbol*)
        ../../gcc/fortran/trans-types.c:2230
0x7015bd gfc_get_symbol_decl(gfc_symbol*)
        ../../gcc/fortran/trans-decl.c:1739
0x704677 generate_local_decl
        ../../gcc/fortran/trans-decl.c:5606
0x6ca382 do_traverse_symtree
        ../../gcc/fortran/symbol.c:4179
0x7052aa generate_local_vars
        ../../gcc/fortran/trans-decl.c:5803
0x7052aa gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6450
0x6958f6 translate_all_program_units
        ../../gcc/fortran/parse.c:6125
0x6958f6 gfc_parse_file()
        ../../gcc/fortran/parse.c:6328
0x6dc13f 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 <https://gcc.gnu.org/bugs/> for instructions.
----------------------------------->%-----------------------------------