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

            Bug ID: 129004
           Summary: [OpenMP] Writes to an allocatable array function
                    result in a target region are lost
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jvdelisle at gcc dot gnu.org
  Target Milestone: ---

module m
contains
  function f (a) result (r)
    real(8), intent(in) :: a(:)
    real(8), allocatable :: r(:)
    integer :: i
    allocate (r, mold=a)
    !$omp target teams distribute parallel do
    do i = 1, size (a)
      r(i) = -a(i)
    end do
  end function
end module
program p
  use m
  real(8) :: a(5) = [1, 2, 3, 4, 5]
  if (any (f (a) /= -a)) stop 1
end program

$ gfortran -fopenmp pr.f90 && OMP_TARGET_OFFLOAD=mandatory ./a.out
STOP 1                          (the result is all 0.0)

The result comes back through the hidden __result argument, which is
DECL_ARTIFICIAL but not marked GFC_DECL_RESULT, so
gfc_omp_predetermined_mapping maps it 'to' and the device's writes
are never copied back.

Expected: the program completes.

Reply via email to