From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2A88A3955409; Thu, 20 May 2021 10:23:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A88A3955409 From: "gscfq@t-online.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/100651] Weird memory corruption with multiple triggers Date: Thu, 20 May 2021 10:23:00 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gscfq@t-online.de 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: Message-ID: In-Reply-To: References: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 May 2021 10:23:01 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100651 --- Comment #2 from G. Steinmetz --- Simplified a bit : $ cat z1.f90 module m type :: t contains procedure, pass(this) :: assign_to_string generic :: assignment(=3D) =3D> assign_to_string end type contains subroutine assign_to_string(string, this) character(:), allocatable, intent(out) :: string class(t), intent(in) :: this end subroutine assert_code(err_msg) character(:), optional, allocatable, intent(inout) :: err_msg err_msg =3D 'foo bar' end function to_int(err_msg) result(ptr) integer :: ptr character(:), optional, allocatable, intent(inout) :: err_msg ptr =3D 1 call assert_code(err_msg) end end program main use m type, extends(t) :: t2 real(8) :: value =3D 1 end type type(t2) :: x integer :: n character(:), allocatable :: err_msg x =3D t2(2) n =3D to_int(err_msg) print *, 'allocated :', allocated(err_msg) print *, 'len : ', len(err_msg) ! print *, 'len_trim : ', len_trim(err_msg) print *, 'err_msg : ', err_msg end $ cat z2.f90 module m type :: t contains procedure, pass(this) :: assign_to_string generic :: assignment(=3D) =3D> assign_to_string end type contains subroutine assign_to_string(string, this) character(:), allocatable, intent(out) :: string class(t), intent(in) :: this end subroutine assert_code(err_msg) character(:), allocatable, intent(inout) :: err_msg err_msg =3D 'foo bar' end function to_int(err_msg) result(ptr) integer :: ptr character(:), allocatable, intent(inout) :: err_msg ptr =3D 1 call assert_code(err_msg) end end program main use m type, extends(t) :: t2 real(8) :: value =3D 1 end type type(t2) :: x integer :: n character(:), allocatable :: err_msg x =3D t2(2) n =3D to_int(err_msg) print *, 'allocated :', allocated(err_msg) print *, 'len : ', len(err_msg) ! print *, 'len_trim : ', len_trim(err_msg) print *, 'err_msg : ', err_msg end $ gfortran-12-20210516 z1.f90 -g -O0 && ./a.out allocated : T len : 0 Operating system error: Cannot allocate memory Memory allocation failure in xrealloc Error termination. Backtrace: #0 0x40d1c7 in write_character at ../../../libgfortran/io/write.c:1416 #1 0x41222e in list_formatted_write_scalar at ../../../libgfortran/io/write.c:1900 #2 0x40265e in MAIN__ at .../z1.f90:36 #3 0x4026a4 in main at .../z1.f90:24 $ gfortran-12-20210516 z2.f90 -g -O0 && ./a.out allocated : T len : 7 err_msg : foo bar=