https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110548
--- Comment #1 from Andrew Benson <abensonca at gcc dot gnu.org> ---
This still fails with 16.2.1 20261115 and trunk (17.0.0 20261115). Here is a
smaller test case (no finalizer is needed):
module taskerMod
type :: helper
end type helper
type :: tasker
integer :: depth=-1
contains
procedure :: compute => taskerCompute
end type tasker
contains
recursive subroutine taskerCompute(self,helper_)
class(tasker), intent(inout) :: self
class(helper), intent(inout), optional :: helper_
!$omp atomic
self%depth=self%depth+1
write (*,*) "DEPTH ",self%depth
if (self%depth < 3) then
!$omp task untied
call self%compute(helper_)
!$omp end task
end if
end subroutine taskerCompute
end module taskerMod
program testTasks
use :: taskerMod
type(tasker) :: tasker_
tasker_=tasker(0)
!$omp parallel
!$omp single
!$omp taskgroup
!$omp task untied
call tasker_%compute()
!$omp end task
!$omp end taskgroup
!$omp end single
!$omp end parallel
write (*,*) "COMPLETED"
end program testTasks
$ gfortran -g -fopenmp pr110548.f90 && OMP_NUM_THREADS=4 ./a.out
DEPTH 1
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 0x150e60e3fb2f in ???
#1 0x40154f in __taskermod_MOD_taskercompute._omp_cpyfn.1
at pr110548.f90:17
#2 0x150e6114cf9f in GOMP_task
at libgomp/task.c:644
#3 0x40130f in __taskermod_MOD_taskercompute
at pr110548.f90:17
The crash is specific to an absent *polymorphic* optional argument. helper_ is
a dummy argument in an orphaned task, so it is implicitly firstprivate. With
16.2.1 and 17.0:
helper_ declared as implicit firstprivate firstprivate(helper_)
type(helper) works works
class(helper) segfault segfault
So gfortran already handles an absent optional argument in FIRSTPRIVATE (the
copy is simply not present), and handles a present polymorphic argument, but
crashes when copying an absent polymorphic one: the segfault is in the task's
copy function (_omp_cpyfn.1), which presumably does not check for presence
before copying the class object.
shared(helper_) on the inner task avoids the crash.