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

            Bug ID: 123254
           Summary: OpenACC: SIGSEGV in GOACC_parallel_keyed when using
                    present() clause for derived type dummy argument
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: albert at tugraz dot at
  Target Milestone: ---

current trunk; repo base upstream/master at
769041822723208bf85a91ac409b9b0bdae3fff0 (2025-12-22)

  COLLECT_GCC=/opt/gcc16/bin/gfortran
 
COLLECT_LTO_WRAPPER=/opt/gcc16/libexec/gcc/x86_64-pc-linux-gnu/16.0.0/lto-wrapper
  OFFLOAD_TARGET_NAMES=nvptx-none
  Target: x86_64-pc-linux-gnu
  Thread model: posix
  gcc version 16.0.0 20251222 (experimental) (GCC)

When a derived type is mapped with !$acc enter data copyin(p), then passed to a
subroutine as a dummy argument, using present(s) in the subroutine causes
SIGSEGV
in GOACC_parallel_keyed. The crash occurs in both host and device modes.

Reproducer:

program mre
    use, intrinsic :: iso_fortran_env, only: dp => real64
    implicit none

    type :: params_t
        real(dp) :: scale
    end type params_t

    type(params_t) :: p
    real(dp) :: x(100), y(100)
    integer :: i

    p%scale = 2.0d0
    x = [(real(i, dp), i = 1, 100)]
    y = 0.0d0

    !$acc enter data copyin(p)
   call eval(p, x, y)
    !$acc exit data delete(p)

    print *, "y(1) =", y(1)

contains

    subroutine eval(s, xv, yv)
        type(params_t), intent(in) :: s
        real(dp), intent(in) :: xv(:)
        real(dp), intent(inout) :: yv(:)
        integer :: j

        !$acc parallel loop copy(yv) copyin(xv) present(s)
        do j = 1, size(xv)
            yv(j) = s%scale * xv(j)
        end do
    end subroutine

end program mre


Build and run:
  gfortran -O2 -fopenacc -foffload=nvptx-none mre.f90 -o mre
  ACC_DEVICE_TYPE=host ./mre

Output:
  Program received signal SIGSEGV: Segmentation fault - invalid memory
reference.
  #2  GOACC_parallel_keyed at ../../../../gcc/libgomp/oacc-parallel.c:201

Expected: Program prints y(1) = 2.0
Actual: SIGSEGV crash

Note: The same code works when the parallel loop is in the main program (not a
subroutine).
The bug is specific to using present() on a derived type dummy argument.

Reply via email to