]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenACC: Further attach/detach clause fixes for Fortran [PR109622]
authorJulian Brown <julian@codesourcery.com>
Fri, 28 Apr 2023 22:27:54 +0000 (22:27 +0000)
committerJulian Brown <julian@codesourcery.com>
Thu, 4 May 2023 11:52:18 +0000 (11:52 +0000)
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.

gcc/fortran/openmp.cc
gcc/fortran/trans-openmp.cc
gcc/testsuite/gfortran.dg/goacc/pr109622-5.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/goacc/pr109622-6.f90 [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-fortran/pr109622-2.f90 [moved from libgomp/testsuite/libgomp.fortran/pr109622-2.f90 with 63% similarity]
libgomp/testsuite/libgomp.oacc-fortran/pr109622-3.f90 [moved from libgomp/testsuite/libgomp.fortran/pr109622-3.f90 with 76% similarity]
libgomp/testsuite/libgomp.oacc-fortran/pr109622-4.f90 [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-fortran/pr109622.f90 [moved from libgomp/testsuite/libgomp.fortran/pr109622.f90 with 78% similarity]

index 86e451531a6c5fab756b478efa687c8d611c4299..81cdf1b42e586f481ed81a42e29e1136f90ad8b8 100644 (file)
@@ -7711,6 +7711,22 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
                                     &n->where);
                      }
                  }
+               if (openacc
+                   && list == OMP_LIST_MAP
+                   && (n->u.map_op == OMP_MAP_ATTACH
+                       || n->u.map_op == OMP_MAP_DETACH))
+                 {
+                   symbol_attribute attr;
+                   if (n->expr)
+                     attr = gfc_expr_attr (n->expr);
+                   else
+                     attr = n->sym->attr;
+                   if (!attr.pointer && !attr.allocatable)
+                     gfc_error ("%qs clause argument must be ALLOCATABLE or "
+                                "a POINTER at %L",
+                                (n->u.map_op == OMP_MAP_ATTACH) ? "attach"
+                                : "detach", &n->where);
+                 }
                if (lastref
                    || (n->expr
                        && (!resolved || n->expr->expr_type != EXPR_VARIABLE)))
index 6ee22faa836a3cd8d5fcd3aa457d262404e5d892..96aecdd1cb392eaf620d683c29bc05cd9ae70382 100644 (file)
@@ -3395,6 +3395,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses,
                          && (n->u.map_op == OMP_MAP_ATTACH
                              || n->u.map_op == OMP_MAP_DETACH))
                        {
+                         OMP_CLAUSE_DECL (node)
+                           = build_fold_addr_expr (OMP_CLAUSE_DECL (node));
                          OMP_CLAUSE_SIZE (node) = size_zero_node;
                          goto finalize_map_clause;
                        }
@@ -3520,8 +3522,10 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses,
                    {
                      /* Bare attach and detach clauses don't want any
                         additional nodes.  */
-                     if (n->u.map_op == OMP_MAP_ATTACH
-                         || n->u.map_op == OMP_MAP_DETACH)
+                     if ((n->u.map_op == OMP_MAP_ATTACH
+                          || n->u.map_op == OMP_MAP_DETACH)
+                         && (POINTER_TYPE_P (TREE_TYPE (inner))
+                             || GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (inner))))
                        {
                          if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (inner)))
                            {
diff --git a/gcc/testsuite/gfortran.dg/goacc/pr109622-5.f90 b/gcc/testsuite/gfortran.dg/goacc/pr109622-5.f90
new file mode 100644 (file)
index 0000000..59dbe9c
--- /dev/null
@@ -0,0 +1,44 @@
+! { dg-do compile }
+
+implicit none
+
+type t
+integer :: foo
+character(len=8) :: bar
+integer :: qux(5)
+end type t
+
+type(t) :: var
+
+var%foo = 3
+var%bar = "HELLOOMP"
+var%qux = (/ 1, 2, 3, 4, 5 /) 
+
+!$acc enter data copyin(var)
+
+!$acc enter data attach(var%foo)
+! { dg-error "'attach' clause argument must be ALLOCATABLE or a POINTER" "" { target *-*-* } .-1 }
+!$acc enter data attach(var%bar)
+! { dg-error "'attach' clause argument must be ALLOCATABLE or a POINTER" "" { target *-*-* } .-1 }
+!$acc enter data attach(var%qux)
+! { dg-error "'attach' clause argument must be ALLOCATABLE or a POINTER" "" { target *-*-* } .-1 }
+
+!$acc serial
+var%foo = 5
+var%bar = "GOODBYE!"
+var%qux = (/ 6, 7, 8, 9, 10 /)
+!$acc end serial
+
+!$acc exit data detach(var%qux)
+! { dg-error "'detach' clause argument must be ALLOCATABLE or a POINTER" "" { target *-*-* } .-1 }
+!$acc exit data detach(var%bar)
+! { dg-error "'detach' clause argument must be ALLOCATABLE or a POINTER" "" { target *-*-* } .-1 }
+!$acc exit data detach(var%foo)
+! { dg-error "'detach' clause argument must be ALLOCATABLE or a POINTER" "" { target *-*-* } .-1 }
+
+!$acc exit data copyout(var)
+
+if (var%foo.ne.5) stop 1
+if (var%bar.ne."GOODBYE!") stop 2
+
+end
diff --git a/gcc/testsuite/gfortran.dg/goacc/pr109622-6.f90 b/gcc/testsuite/gfortran.dg/goacc/pr109622-6.f90
new file mode 100644 (file)
index 0000000..256ab90
--- /dev/null
@@ -0,0 +1,8 @@
+! { dg-do compile }
+
+implicit none
+integer :: x
+!$acc enter data attach(x)
+! { dg-error "'attach' clause argument must be ALLOCATABLE or a POINTER" "" { target *-*-* } .-1 }
+
+end
similarity index 63%
rename from libgomp/testsuite/libgomp.fortran/pr109622-2.f90
rename to libgomp/testsuite/libgomp.oacc-fortran/pr109622-2.f90
index 8c5f373f39f7b5429d29e1eb4e74302d2a5c5d08..d3cbebea6892ae6db52d97dd7116db999e8a98f2 100644 (file)
@@ -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
similarity index 76%
rename from libgomp/testsuite/libgomp.fortran/pr109622-3.f90
rename to libgomp/testsuite/libgomp.oacc-fortran/pr109622-3.f90
index 3ee1b43a74642fbd4cc352c7a02434fd62834672..a25b1a8141431e730b141e4c4ad5603e32f007f2 100644 (file)
@@ -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
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/pr109622-4.f90 b/libgomp/testsuite/libgomp.oacc-fortran/pr109622-4.f90
new file mode 100644 (file)
index 0000000..3198a0b
--- /dev/null
@@ -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
similarity index 78%
rename from libgomp/testsuite/libgomp.fortran/pr109622.f90
rename to libgomp/testsuite/libgomp.oacc-fortran/pr109622.f90
index 5b8c4102f7687ddbbcf6a6716ad5767e5cdfff83..a17c4f627147b67c5495fa39e1489da725711930 100644 (file)
@@ -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