llvm-c166/offload/test/offloading/fortran/map-zero-size-array.f90
agozillon 7e89dcfba2
[Flang][OpenMP] Support mapping of zero-sized arrays (#208133)
Whilst there is no data in theory to map with a zero sized array, the
Fortran OpenMP specification considers the case of a zero sized array
being mapped to device as the data being present on device. This
includes both the data and the descriptor, and it should fundamentlaly
work as a zero-sized array would on device with the respective Fortran
functions for presence and size checking etc.

We can't actually map a nullptr to device and expect it to be present in
current OpenMP (for good reason), however, thankfully, a zero sized
array isn't actually a nullptr, it is a descriptor contianing an
allocated 1-byte of data. So, we can map this to device, alongside the
descriptor and then the zero sized array is correctlly on device for all
intents and purposes. This case is notably different from a
non-allocated or non-zero sized array so we can do this without shooting
ourselves in the foot.
2026-07-11 01:03:33 +02:00

24 lines
714 B
Fortran
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

! OpenMP offloading test that checks we correctly map zero sized arrays
! allowing subsequent presence checks to pass. This is legal in Fortran
! as zero sized arrays are a little bit different to the scenario where
! we have a not present argument or something that's not been allocated
! at all.
! REQUIRES: flang, amdgpu
! RUN: %libomptarget-compile-fortran-run-and-check-generic
program main
integer, allocatable :: array(:)
allocate(array(0))
!$omp target enter data map(to: array) 
! Despite there technically being no data, the
! presence check should legally return true here
! and not fail.
!$omp target map(present, alloc: array)
!$omp end target
print *, "PASS"
end program
! CHECK: PASS