From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BBD1A385840D; Fri, 3 Feb 2023 00:23:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBD1A385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675383799; bh=Jiq3D841AmoRG6eVbF54x0bshOIzp3rV8AuGmKgwUT8=; h=From:To:Subject:Date:From; b=R+M96H9NvaeWHkr4KsP6RDXumcJluli7mscup2MPZVy9QptKGC2dkw9SfVLimjEvy qTFVOd+Zes6ZkMIzwnY+IsR9KzMWKuJp+MNc7ggy2xZB+EahU+ijGtHGNeadwIXCPW t+I0GGKqnb8uwiU1jxMSD5lKQpoXL9IA8u6609WU= From: "Boyce at engineer dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/108652] New: type-bound procedure that returns integer used to allocate character on stack Date: Fri, 03 Feb 2023 00:23:19 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 11.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: Boyce at engineer dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108652 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=3D54400&action=3Dedit Source code, bash file to compile, and error message type-bound procedure that returns integer used to allocate character on sta= ck This is similar to=20 Bug 59450 - [OOP] ICE for type-bound-procedure expression in module procedure interface=20 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=20 !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 =3D ch%str ch2 =3D work end subroutine ! pure function char_len(ch) result(siz) class(char), intent(in):: ch integer:: siz if(allocated(ch%str)) then siz =3D len(ch%str) else siz =3D 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 =3D len(ch%str) else siz =3D 0 end if end function ! pure function char_len3(ch) result(siz) class(char), intent(in):: ch integer:: siz siz =3D char_len(ch) end function end module program MAIN use character_stack_error implicit none type(char):: ch1 character(5):: ch2 ch1%str =3D '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 for instructions. --------------------------------------------------------------- where the error is because ch%char_len() returns an integer used to make wo= rk 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=20 I attached a simple code, the resulting error message, and bash file for compiling to create the error.=