Files
gcc-reflection/libgomp/testsuite/libgomp.fortran/declare-target-link.f90
Tobias Burnus c99cdcab4f omp-offload.cc: Fix value-expr handling of 'declare target link' vars [PR115637]
As the PR and included testcase shows, replacing 'arr2' by its value expression
'*arr2$13$linkptr' failed for
  MEM <uint128_t> [(c_char * {ref-all})&arr2]
which left 'arr2' in the code as unknown symbol. Now expand the value expression
already in pass_omp_target_link::execute's process_link_var_op walk_gimple_stmt
walk - and don't rely on gimple_regimplify_operands.

	PR middle-end/115637

gcc/ChangeLog:

	* gimplify.cc (gimplify_body): Fix macro name in the comment.
	* omp-offload.cc (find_link_var_op): Rename to ...
	(process_link_var_op): ... this. Replace value expr.
	(pass_omp_target_link::execute): Update walk_gimple_stmt call.

libgomp/ChangeLog:

	* testsuite/libgomp.fortran/declare-target-link.f90: Uncomment
	now working code.

Co-authored-by: Richard Biener <rguenther@suse.de
2024-08-01 09:06:32 +02:00

114 lines
2.2 KiB
Fortran

! { dg-additional-options "-Wall" }
! PR fortran/115559
! PR middle-end/115637
module m
integer :: A
!$omp declare target link(A)
end module m
subroutine f
implicit none (type, external)
integer, save :: x, y ! { dg-warning "Unused variable 'y' declared" }
!$omp declare target link(x, y)
! note: y is not 'link' as gfortran doesn't regard it as used
x = 6
call ii
contains
subroutine k
!$omp declare target
use m
A = 5
end
subroutine ii
integer :: res
!$omp target map(x) map(from: res)
call k()
call ll()
res = get()
!$omp end target
! print *, res
if (res /= 6 + 7 + 5) &
stop 1
end
subroutine ll
!$omp declare target
x = x + 7
end
integer function get()
use m
!$omp declare target
get = x + A
end
end
subroutine sub
implicit none (type, external)
integer, save :: arr(100), arr2(1:4)
!$omp declare target link(arr,arr2)
call mapit
call device1
call re_mapit
call device2
contains
subroutine mapit
integer :: i
arr = [(i, i=1,100)]
!$omp target enter data map(to:arr(10:50)) map(alloc: arr2(1:4))
end subroutine
subroutine re_mapit
integer :: i
!$omp target exit data map(from:arr(10:50)) map(delete: arr2)
if (any (arr(1:9) /= [(i, i=1,9)])) stop 2
if (any (arr(10:50) /= [(3-10*i, i=10,50)])) stop 3
if (any (arr(51:100) /= [(i, i=51,100)])) stop 4
end subroutine
subroutine device1
integer :: res
!$omp target map(from:res)
res = run_device1()
!$omp end target
! print *, res
if (res /= -11436) stop 5
end
integer function run_device1()
!$omp declare target
integer :: i
run_device1 = -99
arr2 = [11,22,33,44]
if (any (arr(10:50) /= [(i, i=10,50)])) then
run_device1 = arr(11)
return
end if
run_device1 = sum(arr(10:13) + arr2)
do i = 10, 50
arr(i) = 3 - 10 * arr(i)
end do
run_device1 = run_device1 + sum(arr(15:50))
end
subroutine device2
end
integer function run_device2()
!$omp declare target
run_device2 = -99
end
end
use m
implicit none (type, external)
external f
external sub
!$omp target enter data map(alloc: A)
call f()
call sub
end