gcc/libgomp/testsuite/libgomp.oacc-fortran/optional-data-enter-exit.f90
Tobias Burnus 6e4d01d61f [OpenMP/OpenACC/Fortran] Fix mapping of optional (present|absent) arguments
2019-12-06  Tobias Burnus  <tobias@codesourcery.com>
            Kwok Cheung Yeung <kcy@codesourcery.com>

        gcc/fortran/
        * trans-openmp.c (gfc_build_conditional_assign,
        gfc_build_conditional_assign_expr): New static functions.
        (gfc_omp_finish_clause, gfc_trans_omp_clauses): Handle mapping of
        absent optional arguments and fix mapping of present optional args.

        gcc/
        * omp-low.c (lower_omp_target): For optional arguments, deref once
        more to obtain the type.

        libgomp/
        * oacc-mem.c (update_dev_host, gomp_acc_insert_pointer): Just return
        if input it a NULL pointer.
        * testsuite/libgomp.oacc-c-c++-common/lib-43.c: Remove; dependent on
        diagnostic of NULL pointer.
        * testsuite/libgomp.oacc-c-c++-common/lib-47.c: Ditto.
        * testsuite/libgomp.fortran/optional-map.f90: New.
        * testsuite/libgomp.fortran/use_device_addr-1.f90
        (test_dummy_opt_callee_1_absent): New.
        (test_dummy_opt_call_1): Call it.
        * testsuite/libgomp.fortran/use_device_addr-2.f90: Likewise.
        * testsuite/libgomp.fortran/use_device_addr-3.f90: Likewise.
        * testsuite/libgomp.fortran/use_device_addr-4.f90: Likewise.
        * testsuite/libgomp.oacc-fortran/optional-cache.f95: New.
        * testsuite/libgomp.oacc-fortran/optional-data-copyin-by-value.f90: New.
        * testsuite/libgomp.oacc-fortran/optional-data-copyin.f90: New.
        * testsuite/libgomp.oacc-fortran/optional-data-copyout.f90: New.
        * testsuite/libgomp.oacc-fortran/optional-data-enter-exit.f90: New.
        * testsuite/libgomp.oacc-fortran/optional-declare.f90: New.
        * testsuite/libgomp.oacc-fortran/optional-firstprivate.f90: New.
        * testsuite/libgomp.oacc-fortran/optional-host_data.f90: New.
        * testsuite/libgomp.oacc-fortran/optional-nested-calls.f90: New.
        * testsuite/libgomp.oacc-fortran/optional-private.f90: New.
        * testsuite/libgomp.oacc-fortran/optional-reduction.f90: New.
        * testsuite/libgomp.oacc-fortran/optional-update-device.f90: New.
        * testsuite/libgomp.oacc-fortran/optional-update-host.f90: New.


Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com>

From-SVN: r279043
2019-12-06 14:06:53 +01:00

92 lines
1.7 KiB
Fortran

! Test OpenACC unstructured enter data/exit data regions with optional
! arguments.
! { dg-do run }
program test
implicit none
integer, parameter :: n = 64
integer :: a(n), b(n), c(n), res(n)
integer :: x, y, z, r, i
do i = 1, n
a(i) = i
b(i) = n - i + 1
c(i) = i * 3
end do
res = test_array(a)
do i = 1, n
if (res(i) .ne. a(i)) stop 1
end do
res = test_array(a, b)
do i = 1, n
if (res(i) .ne. a(i) * b(i)) stop 2
end do
res = test_array(a, b, c)
do i = 1, n
if (res(i) .ne. a(i) * b(i) + c(i)) stop 3
end do
x = 7
y = 3
z = 11
r = test_int(x)
if (r .ne. x) stop 4
r = test_int(x, y)
if (r .ne. x * y) stop 5
r = test_int(x, y, z)
if (r .ne. x * y + z) stop 6
contains
function test_array(a, b, c)
integer :: a(n)
integer, optional :: b(n), c(n)
integer :: test_array(n), res(n)
!$acc enter data copyin(a, b, c) create(res)
!$acc parallel loop
do i = 1, n
res(i) = a(i)
end do
!$acc parallel loop
do i = 1, n
if (present(b)) then
res(i) = res(i) * b(i)
end if
end do
!$acc parallel loop
do i = 1, n
if (present(c)) then
res(i) = res(i) + c(i)
end if
end do
!$acc exit data copyout(res) delete(a, b, c)
test_array = res
end function test_array
function test_int(a, b, c)
integer :: a
integer, optional :: b, c
integer :: test_int, res
!$acc enter data copyin(a, b, c) create(res)
!$acc parallel present(a, b, c, res)
res = a
if (present(b)) res = res * b
if (present(c)) res = res + c
!$acc end parallel
!$acc exit data copyout(res) delete(a, b, c)
test_int = res
end function test_int
end program test