public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/107362] New: Segfault for recursive class
@ 2022-10-23  8:38 baradi09 at gmail dot com
  2022-10-23 19:31 ` [Bug fortran/107362] " anlauf at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: baradi09 at gmail dot com @ 2022-10-23  8:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107362
           Summary: Segfault for recursive class
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: baradi09 at gmail dot com
  Target Milestone: ---

When trying to build Fortuno (https://github.com/aradi/fortuno), our new
Fortran unit testing system, I encounter a segfault with GFortran. The problem
can be reduced to the following MWE:

[details: failureinfo.f90]
module fortuno_failureinfo
  implicit none

  type :: failure_info
    class(failure_info), allocatable :: previous
  end type failure_info

end module fortuno_failureinfo
[/details]

> gfortran -freport-bug -c failureinfo.f90 
gfortran: internal compiler error: Segmentation fault signal terminated program
f951
Please submit a full bug report, with preprocessed source.
See <https://github.com/conda-forge/ctng-compilers-feedstock/issues/new/choose>
for instructions.

Apparently, the problem is the "class(failure_info)" field within the derived
type. Turning it into "type(failure_info)" allows compilation.

I use GNU Fortran (conda-forge gcc 12.2.0-18) 12.2.0 on x86_64/Linux.

Thanks a lot for having a look at it in advance!

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

* [Bug fortran/107362] Segfault for recursive class
  2022-10-23  8:38 [Bug fortran/107362] New: Segfault for recursive class baradi09 at gmail dot com
@ 2022-10-23 19:31 ` anlauf at gcc dot gnu.org
  2022-10-31  9:47 ` federico.perini at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-10-23 19:31 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-10-23
           Keywords|                            |compile-time-hog,
                   |                            |ice-on-valid-code
     Ever confirmed|0                           |1

--- Comment #1 from anlauf at gcc dot gnu.org ---
This eats a lot of memory until virtual memory is exhausted.

Also likely a duplicate of pr106606.

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

* [Bug fortran/107362] Segfault for recursive class
  2022-10-23  8:38 [Bug fortran/107362] New: Segfault for recursive class baradi09 at gmail dot com
  2022-10-23 19:31 ` [Bug fortran/107362] " anlauf at gcc dot gnu.org
@ 2022-10-31  9:47 ` federico.perini at gmail dot com
  2022-10-31 13:02 ` [Bug fortran/107362] Internal compiler error " baradi09 at gmail dot com
  2022-11-01  8:45 ` federico.perini at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: federico.perini at gmail dot com @ 2022-10-31  9:47 UTC (permalink / raw)
  To: gcc-bugs

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

federico <federico.perini at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |federico.perini at gmail dot com

--- Comment #2 from federico <federico.perini at gmail dot com> ---
I'm getting the same issue on a recursive tree structure, I will post my
testcase here instead of opening a new bug. 
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,
Federico

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

* [Bug fortran/107362] Internal compiler error for recursive class
  2022-10-23  8:38 [Bug fortran/107362] New: Segfault for recursive class baradi09 at gmail dot com
  2022-10-23 19:31 ` [Bug fortran/107362] " anlauf at gcc dot gnu.org
  2022-10-31  9:47 ` federico.perini at gmail dot com
@ 2022-10-31 13:02 ` baradi09 at gmail dot com
  2022-11-01  8:45 ` federico.perini at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: baradi09 at gmail dot com @ 2022-10-31 13:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Bálint Aradi <baradi09 at gmail dot com> ---
> I'm getting the same issue on a recursive tree structure, I will post my
> testcase here instead of opening a new bug. 

I am not sure, whether the two bugs are identical. If I understand correctly,
you can compile the code and obtain the segfault during execution. In the case
demonstrated above, the compiler itself generates an ICE during the
compilation, so no executable code is generated at all. (I have changed the
title of the bug report to pronounce that more.)

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

* [Bug fortran/107362] Internal compiler error for recursive class
  2022-10-23  8:38 [Bug fortran/107362] New: Segfault for recursive class baradi09 at gmail dot com
                   ` (2 preceding siblings ...)
  2022-10-31 13:02 ` [Bug fortran/107362] Internal compiler error " baradi09 at gmail dot com
@ 2022-11-01  8:45 ` federico.perini at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: federico.perini at gmail dot com @ 2022-11-01  8:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from federico <federico.perini at gmail dot com> ---
OK I will report a new bug.

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

end of thread, other threads:[~2022-11-01  8:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-23  8:38 [Bug fortran/107362] New: Segfault for recursive class baradi09 at gmail dot com
2022-10-23 19:31 ` [Bug fortran/107362] " anlauf at gcc dot gnu.org
2022-10-31  9:47 ` federico.perini at gmail dot com
2022-10-31 13:02 ` [Bug fortran/107362] Internal compiler error " baradi09 at gmail dot com
2022-11-01  8:45 ` federico.perini at gmail dot com

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).