mirror of
https://github.com/siemens-mobile-hacks/llvm-c166.git
synced 2026-11-25 21:45:57 +00:00
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.
24 lines
714 B
Fortran
24 lines
714 B
Fortran
! 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
|