The following MWE (it is still rather complex, unfortunately) causes a segfault when using the NVIDIA compiler (it works fine with GNU, Intel, FLANG):
!> Minimal standalone example to reproduce the segfault
module wrapper_type_mod
implicit none
type, abstract :: WriterAbstract
contains
procedure(init_interface), deferred :: initialize
procedure :: write_geo
end type WriterAbstract
type, extends(WriterAbstract) :: WriterBinary
contains
procedure :: initialize => writer_binary_initialize
end type WriterBinary
type :: SimpleFile
class(WriterAbstract), allocatable :: xml_writer
contains
procedure :: initialize => simple_initialize
end type SimpleFile
abstract interface
integer function init_interface(this)
import WriterAbstract
class(WriterAbstract), intent(inout) :: this
end function init_interface
end interface
! Wrapper type
type :: WrapperType
type(SimpleFile) :: myfile
contains
procedure :: write => wrapper_write
end type WrapperType
contains
integer function simple_initialize(this) result(ierr)
class(SimpleFile), intent(inout) :: this
print*, "simple_initialize"
allocate(WriterBinary :: this%xml_writer)
ierr = this%xml_writer%initialize()
end function simple_initialize
integer function writer_binary_initialize(this) result(ierr)
class(WriterBinary), intent(inout) :: this
print*, "writer_binary_initialize"
ierr = 0
end function writer_binary_initialize
integer function write_geo(this, n, x) result(ierr)
class(WriterAbstract), intent(inout) :: this
integer, intent(in) :: n
real, intent(in) :: x(1:)
print*, "Writing geo"
ierr = 0
end function write_geo
subroutine wrapper_write(this, val)
class(WrapperType), intent(inout) :: this
real, intent(in) :: val
integer :: ierr
! real :: x(2) ! NOTE: No problem
real, allocatable :: x(:) ! NOTE: Causes segfaults
allocate(x(1:2))
x = 0.0
print*, "wrapper_write" ! 89703 lines of: wrapper_write
! simple_initialize
! writer_binary
! print*, "wrapper_write with val = ", val ! Instant segfault after writer_binary_initialize
ierr = this%myfile%initialize()
if (allocated(this%myfile%xml_writer)) then
ierr = this%myfile%xml_writer%write_geo(n=size(x), x=x)
endif
deallocate(x)
end subroutine wrapper_write
end module wrapper_type_mod
program minimal_test
use wrapper_type_mod
implicit none
type(WrapperType) :: wrapper
call wrapper%write(val=1.0)
end program minimal_test
on my local machine this causes an infinite recursion of:
wrapper_write
simple_initialize
writer_binary_initialize
wrapper_write
simple_initialize
writer_binary_initialize
untill, after 89703 lines of output, it segfaults. When replacing allocatable, x(:) by a x(2) the segfault disappears.