OpenACC: Further attach/detach clause fixes for Fortran [PR109622]

This patch moves several tests introduced by the following patch:

  https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616939.html
  commit r14-325-gcacf65d74463600815773255e8b82b4043432bd7

into the proper location for OpenACC testing (thanks to Thomas for
spotting my mistake!), and also fixes a few additional problems --
missing diagnostics for non-pointer attaches, and a case where a pointer
was incorrectly dereferenced. Tests are also adjusted for vector-length
warnings on nvidia accelerators.

2023-04-29  Julian Brown  <julian@codesourcery.com>

	PR fortran/109622

gcc/fortran/
	* openmp.cc (resolve_omp_clauses): Add diagnostic for
	non-pointer/non-allocatable attach/detach.
	* trans-openmp.cc (gfc_trans_omp_clauses): Remove dereference for
	pointer-to-scalar derived type component attach/detach.  Fix
	attach/detach handling for descriptors.

gcc/testsuite/
	* gfortran.dg/goacc/pr109622-5.f90: New test.
	* gfortran.dg/goacc/pr109622-6.f90: New test.

libgomp/
	* testsuite/libgomp.fortran/pr109622.f90: Move test...
	* testsuite/libgomp.oacc-fortran/pr109622.f90: ...to here. Ignore
	vector length warning.
	* testsuite/libgomp.fortran/pr109622-2.f90: Move test...
	* testsuite/libgomp.oacc-fortran/pr109622-2.f90: ...to here.  Add
	missing copyin/copyout variable. Ignore vector length warnings.
	* testsuite/libgomp.fortran/pr109622-3.f90: Move test...
	* testsuite/libgomp.oacc-fortran/pr109622-3.f90: ...to here.  Ignore
	vector length warnings.
	* testsuite/libgomp.oacc-fortran/pr109622-4.f90: New test.

(cherry picked from commit 0a26a42b237bada32165e61867a2bf4461c5fab2)
This commit is contained in:
Julian Brown
2023-04-28 22:27:54 +00:00
parent fa7c4ab365
commit a4cc474b15
8 changed files with 132 additions and 4 deletions
@@ -1,5 +1,7 @@
! { dg-do run }
implicit none
type t
integer :: foo
integer, pointer :: bar
@@ -13,18 +15,19 @@ var%bar => tgt
var%foo = 99
tgt = 199
!$acc enter data copyin(var)
!$acc enter data copyin(var, tgt)
!$acc enter data attach(var%bar)
!$acc serial
! { dg-warning "using .vector_length \\(32\\)., ignoring 1" "" { target openacc_nvidia_accel_selected } .-1 }
var%foo = 5
var%bar = 7
!$acc end serial
!$acc exit data detach(var%bar)
!$acc exit data copyout(var)
!$acc exit data copyout(var, tgt)
if (var%foo.ne.5) stop 1
if (tgt.ne.7) stop 2
@@ -1,5 +1,7 @@
! { dg-do run }
implicit none
type t
integer :: foo
integer, pointer :: bar(:)
@@ -18,6 +20,7 @@ tgt = 199
!$acc enter data attach(var%bar)
!$acc serial
! { dg-warning "using .vector_length \\(32\\)., ignoring 1" "" { target openacc_nvidia_accel_selected } .-1 }
var%foo = 5
var%bar = 7
!$acc end serial
@@ -0,0 +1,47 @@
! { dg-do run }
use openacc
implicit none
type t
integer :: foo
character(len=8), pointer :: bar
character(len=4), allocatable :: qux
end type t
type(t) :: var
character(len=8), target :: tgt
allocate(var%qux)
var%bar => tgt
var%foo = 99
tgt = "Octopus!"
var%qux = "Fish"
!$acc enter data copyin(var, tgt)
! Avoid automatic attach (i.e. with "enter data")
call acc_copyin (var%qux)
!$acc enter data attach(var%bar, var%qux)
!$acc serial
! { dg-warning "using .vector_length \\(32\\)., ignoring 1" "" { target openacc_nvidia_accel_selected } .-1 }
var%foo = 5
var%bar = "Plankton"
var%qux = "Pond"
!$acc end serial
!$acc exit data detach(var%bar, var%qux)
call acc_copyout (var%qux)
!$acc exit data copyout(var, tgt)
if (var%foo.ne.5) stop 1
if (tgt.ne."Plankton") stop 2
if (var%qux.ne."Pond") stop 3
end
@@ -1,5 +1,7 @@
! { dg-do run }
implicit none
type t
integer :: value
type(t), pointer :: chain
@@ -18,6 +20,7 @@ nullify(var2%chain)
!$acc enter data attach(var%chain)
!$acc serial
! { dg-warning "using .vector_length \\(32\\)., ignoring 1" "" { target openacc_nvidia_accel_selected } .-1 }
var%value = 5
var%chain%value = 7
!$acc end serial