https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110548
Bug ID: 110548 Summary: Segfault with optional argument and OpenMP tasks Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: abensonca at gcc dot gnu.org Target Milestone: --- The following shows a segfault at run time resulting from use of an optional argument in a function with OpenMP tasks: module taskerMod type :: helper end type helper type :: tasker integer :: depth=-1 contains final :: taskerDestruct procedure :: compute => taskerCompute end type tasker contains subroutine taskerDestruct(self) !$ use :: OMP_Lib implicit none type(tasker), intent(inout) :: self write (0,*) "DESTRUCT FROM DEPTH ",self%depth !$ ," : ",omp_get_thread_num() return end subroutine taskerDestruct recursive subroutine taskerCompute(self,helper_) !$ use :: OMP_Lib implicit none class(tasker), intent(inout) :: self class(helper), intent(inout), optional :: helper_ !$omp atomic self%depth=self%depth+1 write (0,*) "DEPTH ",self%depth !$ ," : ",omp_get_thread_num() if (self%depth < 3) then !$omp task untied call self%compute(helper_) !$omp end task end if return end subroutine taskerCompute end module taskerMod program testTasks use :: taskerMod implicit none type(tasker) :: tasker_ type(helper) :: helper_ 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 end program testTasks $ gfortran test1.F90 -fopenmp $ ./a.out DESTRUCT FROM DEPTH -1 DEPTH 1 Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x2ac99289a1ef in ??? #1 0x401840 in ??? #2 0x2ac9925a9606 in GOMP_task at ../../../gcc-git/libgomp/task.c:644 #3 0x401588 in ??? #4 0x40197b in ??? #5 0x2ac9925a77a4 in gomp_barrier_handle_tasks at ../../../gcc-git/libgomp/task.c:1650 #6 0x2ac9925b058f in gomp_team_barrier_wait_end at ../../../gcc-git/libgomp/config/linux/bar.c:116 #7 0x2ac9925aeffc in gomp_team_end at ../../../gcc-git/libgomp/team.c:956 #8 0x401692 in ??? #9 0x4016cd in ??? #10 0x2ac992886d0c in ??? #11 0x401128 in ??? Segmentation fault This appears to be due to the optional argument, helper_. If it is present in the initial call, i.e.: call tasker_%compute(helper_) then this runs without a segfault. This happens with versions 12.0.0, 13.0.1, and the current HEAD of the GCC git repo.