https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123483

            Bug ID: 123483
           Summary: Duplicated finalization for derived type with
                    allocatable and finalizable components
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: abensonca at gcc dot gnu.org
  Target Milestone: ---

Created attachment 63281
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63281&action=edit
minimal working example

Using the current trunk, gfortran produces a duplicated call to a finalizer in
cases where a derived type has components, one or more of which are
allocatable, and one or more of which are finalizable. (The bug occurs only if
the derived type is an extension of another type, which has defined
assignment.) This breaks reference counting of shared resources.

In the attached test case the reference count output should end at a value of
1, but with current trunk is decremented to zero. (In a real-world example
using reference counting this would result in a shared resource being
prematurely freed.)

 assignment - begin
 workConstructor - begin
 resourceManagerConstructor            1
 resourceManagerAssign            2
 resourceManagerDestructor            1
 workConstructor - end
 baseAssignment
 resourceManagerAssign            2
 resourceManagerDestructor            1
 resourceManagerDestructor            0  <---- note the second destructor call
here
 assignment - end


Compiling the test case using ifort instead gives:

 assignment - begin
 workConstructor - begin
 resourceManagerConstructor            1
 resourceManagerAssign            2
 resourceManagerDestructor            1
 workConstructor - end
 baseAssignment
 resourceManagerAssign            2
 resourceManagerDestructor            1
 assignment - end

as expected.

Reply via email to