https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108652
Bug ID: 108652 Summary: type-bound procedure that returns integer used to allocate character on stack Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: Boyce at engineer dot com Target Milestone: --- Created attachment 54400 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54400&action=edit Source code, bash file to compile, and error message type-bound procedure that returns integer used to allocate character on stack This is similar to Bug 59450 - [OOP] ICE for type-bound-procedure expression in module procedure interface But the error still occurs for the following code: --------------------------------------------------------------- module character_stack_error implicit none type char character(:), allocatable:: str contains procedure, pass(ch):: char_sub procedure, pass(ch):: char_len end type ! contains ! subroutine char_sub(ch, ch2) class(char), intent(in):: ch character(*), intent(out):: ch2 character(ch%char_len()):: work ! ch%char_len() -> internal compiler error: Segmentation fault !character(char_len(ch)):: work ! This raises: Error: MODULE-PROC procedure at (1) is already declared as EXTERNAL-PROC procedure !character(len(ch%str)):: work ! while not correct, this works fine !character(char_len2(ch)):: work ! this works too !character(char_len3(ch)):: work ! this works too work = ch%str ch2 = work end subroutine ! pure function char_len(ch) result(siz) class(char), intent(in):: ch integer:: siz if(allocated(ch%str)) then siz = len(ch%str) else siz = 0 end if end function ! pure function char_len2(ch) result(siz) class(char), intent(in):: ch integer:: siz if(allocated(ch%str)) then siz = len(ch%str) else siz = 0 end if end function ! pure function char_len3(ch) result(siz) class(char), intent(in):: ch integer:: siz siz = char_len(ch) end function end module program MAIN use character_stack_error implicit none type(char):: ch1 character(5):: ch2 ch1%str = 'abc' call ch1%char_sub(ch2) end program --------------------------------------------------------------- which gives the following error is given: f951: internal compiler error: Segmentation fault 0xd41627 internal_error(char const*, ...) ???:0 0x14c28f0 gfc_find_derived_vtab(gfc_symbol*) ???:0 0x14f619e gfc_reduce_init_expr(gfc_expr*) ???:0 0x14d0afa gfc_match_char_spec(gfc_typespec*) ???:0 0x14fdc8f gfc_match_decl_type_spec(gfc_typespec*, int) ???:0 0x158cb55 gfc_parse_file() ???:0 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions. --------------------------------------------------------------- where the error is because ch%char_len() returns an integer used to make work in: character(ch%char_len()):: work I have in the code commented different versions that will work, but the original should also. I tested this code with with 11.3.0 and 12.1.0 I attached a simple code, the resulting error message, and bash file for compiling to create the error.