public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/107489] New: Runtime segfault in finalization routine of derived type with allocatable components
@ 2022-11-01  8:46 federico.perini at gmail dot com
  2022-11-01 17:54 ` [Bug fortran/107489] " kargl at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: federico.perini at gmail dot com @ 2022-11-01  8:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107489
           Summary: Runtime segfault in finalization routine of derived
                    type with allocatable components
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: federico.perini at gmail dot com
  Target Milestone: ---

I'm getting the same issue on a recursive tree structure. 
I see a segfault in the default finalizer (I think it gets called when a
recursive type is returned as a function result).

I get the segfault on the default finalization routine with all gfortran
versions, 7.1 to 12.1. 

This is also potentially linked to bug 106606 (in this case, the class is not
polymorphic).

Test program (also see on godbolt at: https://godbolt.org/z/PxYGhM8j9)

module t
    type :: tree
        type(tree), allocatable :: node
    end type tree

    type :: container

        type(tree) :: root

    end type container

    contains

       type(container) function do_something() result(c)
           allocate(c%root%node)
           allocate(c%root%node%node)
           allocate(c%root%node%node%node)
       end function do_something

end module t


program test_function_output
   use t

   call create_and_finalize()

   contains

      subroutine create_and_finalize()
         type(container) :: c1,c2

         c1 = do_something()
         c2 = c1

         print *, 'allocated? 0 ',allocated(c1%root%node)
         print *, 'allocated? 1 ',allocated(c1%root%node%node)
         print *, 'allocated? 2 ',allocated(c1%root%node%node%node)
      end subroutine create_and_finalize


end program test_function_output

Thanks,
Federic

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/107489] Runtime segfault in finalization routine of derived type with allocatable components
  2022-11-01  8:46 [Bug fortran/107489] New: Runtime segfault in finalization routine of derived type with allocatable components federico.perini at gmail dot com
@ 2022-11-01 17:54 ` kargl at gcc dot gnu.org
  2022-11-02  1:15 ` jvdelisle at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: kargl at gcc dot gnu.org @ 2022-11-01 17:54 UTC (permalink / raw)
  To: gcc-bugs

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

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #1 from kargl at gcc dot gnu.org ---
Federic,  there was a small burst of work on finalization here

https://gcc.gnu.org/pipermail/fortran/2022-February/thread.html

I thought a patch was floating around in the fortran@gcc mailing list, but
could not find it.  You might ping the participants in the above thread if
anyone has made any progress.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/107489] Runtime segfault in finalization routine of derived type with allocatable components
  2022-11-01  8:46 [Bug fortran/107489] New: Runtime segfault in finalization routine of derived type with allocatable components federico.perini at gmail dot com
  2022-11-01 17:54 ` [Bug fortran/107489] " kargl at gcc dot gnu.org
@ 2022-11-02  1:15 ` jvdelisle at gcc dot gnu.org
  2022-11-08  3:00 ` jvdelisle at gcc dot gnu.org
  2022-11-08 16:35 ` [Bug fortran/107489] Insufficiently deep allocate/copy for simple assignment of derived types with recursive components pault at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2022-11-02  1:15 UTC (permalink / raw)
  To: gcc-bugs

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

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jvdelisle at gcc dot gnu.org

--- Comment #2 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
The patch is here:

https://gcc.gnu.org/pipermail/fortran/attachments/20220203/5c8a5980/attachment-0011.bin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/107489] Runtime segfault in finalization routine of derived type with allocatable components
  2022-11-01  8:46 [Bug fortran/107489] New: Runtime segfault in finalization routine of derived type with allocatable components federico.perini at gmail dot com
  2022-11-01 17:54 ` [Bug fortran/107489] " kargl at gcc dot gnu.org
  2022-11-02  1:15 ` jvdelisle at gcc dot gnu.org
@ 2022-11-08  3:00 ` jvdelisle at gcc dot gnu.org
  2022-11-08 16:35 ` [Bug fortran/107489] Insufficiently deep allocate/copy for simple assignment of derived types with recursive components pault at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2022-11-08  3:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
CCed Paul so he has this example.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/107489] Insufficiently deep allocate/copy for simple assignment of derived types with recursive components
  2022-11-01  8:46 [Bug fortran/107489] New: Runtime segfault in finalization routine of derived type with allocatable components federico.perini at gmail dot com
                   ` (2 preceding siblings ...)
  2022-11-08  3:00 ` jvdelisle at gcc dot gnu.org
@ 2022-11-08 16:35 ` pault at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pault at gcc dot gnu.org @ 2022-11-08 16:35 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
                 CC|                            |pault at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-11-08
            Summary|Runtime segfault in         |Insufficiently deep
                   |finalization routine of     |allocate/copy for simple
                   |derived type with           |assignment of derived types
                   |allocatable components      |with recursive components

--- Comment #4 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to kargl from comment #1)
> Federic,  there was a small burst of work on finalization here
> 
> https://gcc.gnu.org/pipermail/fortran/2022-February/thread.html
> 
> I thought a patch was floating around in the fortran@gcc mailing list, but
> could not find it.  You might ping the participants in the above thread if
> anyone has made any progress.

Please do not mix things up. There are no finalizable entities in the testcase,
since there are no final subroutines.

The "default finalization" that triggers this problem is the automatic
deallocation of allocatable entities on going out of scope.

For some reason, it is the assignment c2 = c1 that is the culprit. Evidently,
the allocation and assignment of the components is not going deep enough.

I have changed the title of the PR accordingly.

I have been triggered to complete the finalization work that I left off in
March but daytime work prevents me from picking anything else up for the time
being.

Thanks for the report

Paul

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-08 16:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01  8:46 [Bug fortran/107489] New: Runtime segfault in finalization routine of derived type with allocatable components federico.perini at gmail dot com
2022-11-01 17:54 ` [Bug fortran/107489] " kargl at gcc dot gnu.org
2022-11-02  1:15 ` jvdelisle at gcc dot gnu.org
2022-11-08  3:00 ` jvdelisle at gcc dot gnu.org
2022-11-08 16:35 ` [Bug fortran/107489] Insufficiently deep allocate/copy for simple assignment of derived types with recursive components pault at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).