llvm-project/flang/test/Semantics/OpenACC/acc-cache-validity.f90
khaki3 ff0220d236
[flang][acc] Allow orphaned acc cache directive (#184448)
While the spec allows the cache directive at the top of a loop body, the
directive has also been utilized at the top of an acc routine. This PR
removes the semantic check that rejects the cache directive outside of a
loop, allowing orphaned `!$acc cache` similar to CIR.

The OpenACC.md deviation document is updated to note this extension.
2026-03-04 09:41:48 -08:00

73 lines
1.7 KiB
Fortran

! RUN: %python %S/../test_errors.py %s %flang -fopenacc
! Check OpenACC clause validity for the following construct and directive:
! 2.10 Cache
program openacc_cache_validity
implicit none
type atype
real(8), dimension(10) :: arr
real(8) :: s
end type atype
integer :: i
integer, parameter :: N = 256
real(8), dimension(N, N) :: aa
type(atype) :: t
type(atype), dimension(10) :: ta
real(8), dimension(N) :: a
do i = 1, N
!$acc cache(a(i))
!$acc cache(a(1:2,3:4))
!$acc cache(a)
!$acc cache(readonly: a, aa)
!$acc cache(readonly: a(i), aa(i, i))
!$acc cache(t%arr)
!$acc cache(ta(1:2)%arr)
!$acc cache(ta(1:2)%arr(1:4))
!$acc cache(i)
!$acc cache(t%s)
!ERROR: Only array element or subarray are allowed in CACHE directive
!$acc cache(t)
!ERROR: Only array element or subarray are allowed in CACHE directive
!$acc cache(/i/)
!ERROR: The CACHE directive requires at least one of the bounds in the array section subscript triplet to be specified
!$acc cache(a(:))
!ERROR: The CACHE directive requires at least one of the bounds in the array section subscript triplet to be specified
!$acc cache(aa(:,:))
!ERROR: The CACHE directive does not support strided array sections
!$acc cache(a(1:10:2))
!ERROR: The CACHE directive does not support strided array sections
!$acc cache(aa(1:10:2, 1:5))
end do
!$acc cache(a)
call routine_with_cache()
contains
subroutine routine_with_cache()
real(8), dimension(N) :: local_arr
integer :: j
!$acc routine vector
!$acc cache(local_arr)
!$acc loop
do j = 1, N
local_arr(j) = a(j)
end do
end subroutine
end program openacc_cache_validity