[Bug fortran/70863] [F03] Finalization of array of derived type causes segfault

janus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Dec 10 00:34:00 GMT 2016


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

--- Comment #2 from janus at gcc dot gnu.org ---
Slightly reduced test case:


module b_module
  implicit none
  type :: b
     character(len=4) :: name = "none"
   contains
     final :: destroy_b
  end type
contains
  impure elemental subroutine destroy_b (this)
    type(b), intent(inout) :: this
    print *, "destroying b: ", loc(this)
    print *, "       name = ", this%name
  end subroutine
end module


program main
  use b_module
  implicit none
  call f ()
contains
  subroutine f()
    type :: c
      type(b) :: object_b(2)
    end type
    type(c) :: x
    x%object_b(1)%name = "b(1)"
    x%object_b(2)%name = "b(2)"
    print *, 'loc of c     ', loc(x)
    print *, 'loc of b(1)  ', loc(x%object_b(1))
    print *, 'loc of b(2)  ', loc(x%object_b(2))
  end subroutine
end


Obviously the second destroyed object has the wrong address.


More information about the Gcc-bugs mailing list