[Bug fortran/100743] New: Segmentation fault passing a polymorphic as an optional argument

jhaiduce at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon May 24 14:00:27 GMT 2021


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

            Bug ID: 100743
           Summary: Segmentation fault passing a polymorphic as an
                    optional argument
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jhaiduce at gmail dot com
  Target Milestone: ---

The following program crashes with a segmentation fault:

```
module my_exceptions

  implicit none

  type::error_container
  end type error_container

  type, abstract::base_exception
  end type base_exception

  type, extends(base_exception)::exception
  end type exception

contains

  function new_exception()
    type(exception)::new_exception
  end function new_exception

  subroutine throw(status,exc)
    type(error_container), intent(inout), optional::status
    class(base_exception)::exc
  end subroutine throw

  subroutine test_throw(status)
    class(error_container), intent(inout), optional::status

    call throw(status,new_exception())

  end subroutine test_throw

end module my_exceptions

program test
  use my_exceptions, ONLY: error_container, test_throw
  implicit none
  type(error_container)::status

  call test_throw()

end program test
```

It works as expected when compiled with ifort. With gfortran it produces a
segmentation fault. The problem occurs with multiple versions of gfortran (have
tried 4.9.4, 7.5.0, 10.2.0, 10.3.0, 11.1.0).

The segmentation fault does not occur if the optional status argument is
declared as non-polymorphic type (i.e. ```type(error_container)``` instead of
```class(error_container)```).


More information about the Gcc-bugs mailing list