Files
clang-p2996/offload/test/offloading/fortran/optional-mapped-arguments.f90
agozillon b2c9a58b8f [Flang][OpenMP][MLIR] Check for presence of Box type before emitting store in MapInfoFinalization pass (#135477)
Currently we don't check for the presence of descriptor/BoxTypes before
emitting stores which lower to memcpys, the issue with this is that
users can have optional arguments, where they don't provide an input,
making the argument effectively null. This can still be mapped and this
causes issues at the moment as we'll emit a memcpy for function
arguments to store to a local variable for certain edge cases, when we
perform this memcpy on a null input, we cause a segfault at runtime.

The fix to this is to simply create a branch around the store that
checks if the data we're copying from is actually present. If it is, we
proceed with the store, if it isn't we skip it.
2025-04-14 17:15:56 +02:00

37 lines
930 B
Fortran

! OpenMP offloading test that checks we do not cause a segfault when mapping
! optional function arguments (present or otherwise). No results requiring
! checking other than that the program compiles and runs to completion with no
! error.
! REQUIRES: flang, amdgpu
! RUN: %libomptarget-compile-fortran-run-and-check-generic
module foo
implicit none
contains
subroutine test(I,A)
implicit none
real(4), optional, intent(inout) :: A(:)
integer(kind=4), intent(in) :: I
!$omp target data map(to: A) if (I>0)
!$omp end target data
!$omp target enter data map(to:A) if (I>0)
!$omp target exit data map(from:A) if (I>0)
end subroutine test
end module foo
program main
use foo
implicit none
real :: array(10)
call test(0)
call test(1)
call test(0, array)
call test(1, array)
print *, "PASSED"
end program main
! CHECK: PASSED