https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123280
Bug ID: 123280
Summary: [OpenACC/Fortran] acc_is_present fails for
assumed-shape dummy argument mapped by caller
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: ---
When an array is mapped to the device by a caller using OpenACC directives, and
then
passed to a subroutine as an assumed-shape dummy argument, acc_is_present()
inside
the subroutine fails to detect that the data is present on the device.
This is related to Bug 96080 (OpenACC/Fortran runtime library routines vs.
Fortran
'pointer'), but involves assumed-shape dummy arguments rather than pointer
variables.
Both issues stem from runtime library routines using descriptor address for
lookups
rather than the underlying data address.
OpenACC (>=2.6) spec (section 3.2) says acc_is_present "tests whether the
specified host data is present on the device." For an assumed-shape dummy
argument x(:), "the specified
host data" is the underlying array data, not the descriptor. Since the data IS
present
on the device, acc_is_present should return true.
Compile and run:
gfortran -fopenacc -foffload=nvptx-none -o mre mre.f90
./mre
Expected: Both tests print "PASS"
Actual: Test 2 prints "FAIL" - acc_is_present returns .false. for assumed-shape
dummy
Tested with GCC 16.0.0 20251223 (experimental) from master commit 61eb73a6396.
Minimal reproducer:
program mre
use openacc
implicit none
real, allocatable :: arr(:)
integer, parameter :: n = 100
allocate(arr(n))
arr = 1.0
! Map data to device
!$acc enter data copyin(arr)
! Test 1: Direct check - PASS
if (acc_is_present(arr)) then
print *, "Test 1 (direct): PASS"
else
print *, "Test 1 (direct): FAIL"
stop 1
end if
! Test 2: Check via subroutine with assumed-shape - FAIL
call check_present(arr)
!$acc exit data delete(arr)
contains
subroutine check_present(x)
real, intent(in) :: x(:) ! assumed-shape dummy argument
! This returns .false. even though the underlying data IS present
if (acc_is_present(x)) then
print *, "Test 2 (assumed-shape dummy): PASS"
else
print *, "Test 2 (assumed-shape dummy): FAIL"
stop 2
end if
end subroutine check_present
end program mre
nvfortran 25.11 correctly implements this - it dereferences the descriptor to
find
the underlying data address and returns true. GCC incorrectly looks up by
descriptor
address, so it cannot find the mapping created under a different variable name.