diff mbox series

[1/9,OpenACC] Fortran derived-type mapping fix

Message ID 54822b42a9e8e1d04d447ba5276ed6c7510e51d7.1592343756.git.julian@codesourcery.com
State New
Headers show
Series Refcounting and manual deep copy improvements | expand

Commit Message

Julian Brown June 16, 2020, 10:38 p.m. UTC
This is a slightly-updated version of the patch sent here, with some of
Thomas's suggestions incorporated:

 https://gcc.gnu.org/pipermail/gcc-patches/2020-June/547407.html

I'm still assuming this is approved, but including for completeness.

Julian

ChangeLog

	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                      |  4 ++--
 .../gfortran.dg/goacc/mapping-tests-3.f90       | 15 +++++++++++++++
 .../gfortran.dg/goacc/mapping-tests-4.f90       | 17 +++++++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/mapping-tests-3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/mapping-tests-4.f90
diff mbox series

Patch

diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
index 7e2f6256c43..02c40fdc660 100644
--- a/gcc/fortran/trans-openmp.c
+++ b/gcc/fortran/trans-openmp.c
@@ -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
index 00000000000..890ca781967
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-3.f90
@@ -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
index 00000000000..17cc4841d4e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-4.f90
@@ -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