From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 68A9D3861812; Mon, 11 Jan 2021 08:17:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68A9D3861812 From: "pault at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/64290] [F03] No finalization at deallocation of LHS Date: Mon, 11 Jan 2021 08:17:11 +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: 5.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: pault at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: pault at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc assigned_to attachments.created 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: Mon, 11 Jan 2021 08:17:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D64290 Paul Thomas changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pault at gcc dot gnu.org Assignee|unassigned at gcc dot gnu.org |pault at gcc dot gn= u.org --- Comment #2 from Paul Thomas --- Created attachment 49936 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D49936&action=3Dedit Initial fix for the PR Triggered by a recent thread on clf, I have made a first stab at this PR. T= his patch is thus far perfect and has the following regressions: FAIL: gfortran.dg/class_optional_1.f90 -O0 execution test FAIL: gfortran.dg/dynamic_dispatch_6.f03 -O1 execution test FAIL: gfortran.dg/finalize_15.f90 -O0 (internal compiler error) FAIL: gfortran.dg/finalize_25.f90 -O0 execution test FAIL: gfortran.dg/finalize_29.f08 -O0 execution test plus FAIL: gfortran.dg/prof/dynamic_dispatch_6.f03 execution, -fprofile-gener= ate -D_PROFILE_GENERATE which is not too bad for a first attempt. Note that for arrays, finalizatio= n is occurring before reallocation of the lhs contrary to the requirements of the standard. This test, based on the reporter's testcase, works as intended: module testmode implicit none type :: simple integer :: ind contains final :: destruct1, destruct2 end type simple integer :: check_scalar integer :: check_array(2) integer :: final_count =3D 0 contains subroutine destruct1(self) type(simple), intent(inout) :: self ! print *, "DESTRUCTING SCALAR", self%ind check_scalar =3D self%ind check_array =3D 0 final_count =3D final_count + 1 end subroutine destruct1 subroutine destruct2(self) type(simple), intent(inout) :: self(:) ! print *, "DESTRUCTING ARRAY", self%ind check_scalar =3D 0 check_array =3D self%ind final_count =3D final_count + 1 end subroutine destruct2 subroutine test (cnt, scalar, array, off) integer :: cnt integer :: scalar integer :: array(:) integer :: off if (final_count .ne. cnt) stop 1 + off if (check_scalar .ne. scalar) stop 2 + off if (any (check_array .ne. array)) stop 3 + off end subroutine test end module testmode program test_final use testmode implicit none type(simple), allocatable :: myres, myres2 type(simple), allocatable :: myarray(:) type(simple) :: thyres =3D simple(21), thyres2 =3D simple(22) allocate(myres) allocate(myres2) myres%ind =3D 1 myres2%ind =3D 2 myres =3D myres2 call test(1, 1, [0,0], 10) allocate(myarray(2)) myarray%ind =3D [42, 43] myarray =3D [thyres, thyres2] call test(2, 0, [42,43], 20) thyres2 =3D simple(99) call test(3, 22, [0,0], 30) thyres =3D thyres2 call test(4, 21, [0,0], 40) deallocate (myres, myres2) call test(6, 2, [0,0], 100) deallocate (myarray) call test(7, 0, [21,22], 200) end program test_final Paul=