openacc: Fortran derived-type mapping fix
authorJulian Brown <julian@codesourcery.com>
Wed, 3 Jun 2020 21:25:19 +0000 (14:25 -0700)
committerJulian Brown <julian@codesourcery.com>
Thu, 9 Jul 2020 21:04:41 +0000 (14:04 -0700)
Fix a bug with mapping Fortran components which themselves have derived
types in the OpenACC 2.5+ manual deep-copy support.

2020-07-09  Julian Brown  <julian@codesourcery.com>

gcc/fortran/
* trans-openmp.c (gfc_trans_omp_clauses): Use 'inner' not 'decl' for
derived type members which themselves have derived types.

gcc/testsuite/
* gfortran.dg/goacc/mapping-tests-3.f90: New test.
* gfortran.dg/goacc/mapping-tests-4.f90: New test.

gcc/fortran/trans-openmp.c
gcc/testsuite/gfortran.dg/goacc/mapping-tests-3.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/goacc/mapping-tests-4.f90 [new file with mode: 0644]

index 22f8f96..38e141d 100644 (file)
@@ -2774,9 +2774,9 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses,
                        }
                      else
                        {
-                         OMP_CLAUSE_DECL (node) = decl;
+                         OMP_CLAUSE_DECL (node) = inner;
                          OMP_CLAUSE_SIZE (node)
-                           = TYPE_SIZE_UNIT (TREE_TYPE (decl));
+                           = TYPE_SIZE_UNIT (TREE_TYPE (inner));
                        }
                    }
                  else if (lastcomp->next
diff --git a/gcc/testsuite/gfortran.dg/goacc/mapping-tests-3.f90 b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-3.f90
new file mode 100644 (file)
index 0000000..890ca78
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-additional-options "-fdump-tree-gimple" }
+
+subroutine foo
+  type one
+    integer i, j
+  end type
+  type two
+    type(one) A, B
+  end type
+
+  type(two) x
+
+  !$acc enter data copyin(x%A)
+! { dg-final { scan-tree-dump-times "omp target oacc_enter_exit_data map\\(struct:x \\\[len: 1\\\]\\) map\\(to:x.a \\\[len: \[0-9\]+\\\]\\)" 1 "gimple" } }
+end
diff --git a/gcc/testsuite/gfortran.dg/goacc/mapping-tests-4.f90 b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-4.f90
new file mode 100644 (file)
index 0000000..17cc484
--- /dev/null
@@ -0,0 +1,17 @@
+subroutine foo
+  type one
+    integer i, j
+  end type
+  type two
+    type(one) A, B
+  end type
+
+  type(two) x
+
+! This is accepted at present, although it represents a probably-unintentional
+! overlapping subcopy.
+  !$acc enter data copyin(x%A, x%A%i)
+! But this raises an error.
+  !$acc enter data copyin(x%A, x%A%i, x%A%i)
+! { dg-error ".x.a.i. appears more than once in map clauses" "" { target *-*-* } .-1 }
+end