From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 382A33858D20; Fri, 11 Aug 2023 09:11:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 382A33858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691745085; bh=NS4EDGkFbT3m92IjXcvf0H7VgC5NWUvkylC7bYtmdxw=; h=From:To:Subject:Date:From; b=mIY8lZ0m1UHVf5bmnGntGbwmH7d31n44s4O5/A9qSyU10pIj8YGc5MZNFRbFPfv+N WH9PTpd1dszxymteeDuHMhz6WWu19rBsNlD7CPn7JkDw9MakeTaa50eWgU5aN6pQy4 6+5SB8QGve8eNygB8fxPGNoC15eMLQlfcCMZvihU= From: "chilikin.k at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/110987] New: Segmentation fault after finalization of a temporary variable Date: Fri, 11 Aug 2023 09:11:20 +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: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: chilikin.k at gmail 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=3D110987 Bug ID: 110987 Summary: Segmentation fault after finalization of a temporary variable Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: chilikin.k at gmail dot com Target Milestone: --- Created attachment 55720 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D55720&action=3Dedit Test case The attached test program works fine with gfortran 12.2.0 and crashes with a segmentation fault when compiled with gfortran 13.2.0. The compilation command is gfortran -g -o test test.f90 The segmentation fault happens when the function T1_GET_NEXT() tries to acc= ess SELF%NEXT(1)%T1, which is deallocated and overwritten: $ valgrind ./test =3D=3D1651009=3D=3D Invalid read of size 8 =3D=3D1651009=3D=3D at 0x40251D: __test_module_MOD_t1_get_next (in test) =3D=3D1651009=3D=3D by 0x403678: MAIN__ (in test) =3D=3D1651009=3D=3D by 0x4036D0: main (in test) =3D=3D1651009=3D=3D Address 0x4e92d48 is 8 bytes inside a block of size 16= free'd =3D=3D1651009=3D=3D at 0x48399AB: free (vg_replace_malloc.c:538) =3D=3D1651009=3D=3D by 0x402876: __test_module_MOD_t1_destructor (in tes= t) =3D=3D1651009=3D=3D by 0x401812: __test_module_MOD___final_test_module_T= 1 (in test) =3D=3D1651009=3D=3D by 0x4035CF: MAIN__ (in test) =3D=3D1651009=3D=3D by 0x4036D0: main (in test) =3D=3D1651009=3D=3D Block was alloc'd at =3D=3D1651009=3D=3D at 0x483877F: malloc (vg_replace_malloc.c:307) =3D=3D1651009=3D=3D by 0x4026AF: __test_module_MOD_t1_set_n_next (in tes= t) =3D=3D1651009=3D=3D by 0x402466: __test_module_MOD_t2_constructor (in te= st) =3D=3D1651009=3D=3D by 0x402E93: MAIN__ (in test) =3D=3D1651009=3D=3D by 0x4036D0: main (in test) The corresponding part of the output of $ objdump -S ./test | less is attached. The final-subroutine call which incorrectly deallocates memory happens at 4035cd, between the calls of __test_module_MOD_t3_constructor and __test_module_MOD_t1_set_n_next. Thus, the finalization seems to happen for the temporary variable allocated as the result of T3() call, which is assig= ned then to X3, and the memory corresponding to CLASS(T1_POINTER), ALLOCATABLE :: NEXT(:) is probably the same for that temporary variable and X3 (in contradiction w= ith 10.2.1.3.13 item (2) of Fortran 2018?). May be related to the fix of bug 80524.=