This follow-up patch enables the "inheritance" of mappings for OpenACC
data constructs to work also for Fortran assumed-size arrays.
Otherwise, such arrays are (arguably, prematurely) bailed out on in the
Fortran front-end.

Tested alongside the previous patch with offloading to nvptx.

OK to apply?

Thanks,

Julian

2018-08-28  Julian Brown  <jul...@codesourcery.com>

        gcc/fortran/
        * trans-openmp.c (gfc_omp_finish_clause): Don't raise error for
        assumed-size array if present in a lexically-enclosing data construct.

        libgomp/
        * testsuite/libgomp.oacc-fortran/pr70828-4.f90: New test.
>From 9214ffc6bb2ac7cf023f4e62ca324b1a47123ffc Mon Sep 17 00:00:00 2001
From: Julian Brown <jul...@codesourcery.com>
Date: Tue, 28 Aug 2018 09:01:15 -0700
Subject: [PATCH 2/2] Assumed-size array fix

2018-08-28  Julian Brown  <jul...@codesourcery.com>

	gcc/fortran/
	* trans-openmp.c (gfc_omp_finish_clause): Don't raise error for
	assumed-size array if present in a lexically-enclosing data construct.

	libgomp/
	* testsuite/libgomp.oacc-fortran/pr70828-4.f90: New test.
---
 gcc/fortran/trans-openmp.c                         | 10 ++++---
 .../testsuite/libgomp.oacc-fortran/pr70828-4.f90   | 31 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/pr70828-4.f90

diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
index f038f4c..86be407 100644
--- a/gcc/fortran/trans-openmp.c
+++ b/gcc/fortran/trans-openmp.c
@@ -1045,9 +1045,13 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p)
 
   tree decl = OMP_CLAUSE_DECL (c);
 
-  /* Assumed-size arrays can't be mapped implicitly, they have to be
-     mapped explicitly using array sections.  */
-  if (TREE_CODE (decl) == PARM_DECL
+  /* Assumed-size arrays can't be mapped implicitly, they have to be mapped
+     explicitly using array sections.  An exception is if the array is
+     mapped explicitly in an enclosing data construct for OpenACC, in which
+     case we see GOMP_MAP_FORCE_PRESENT here and do not need to raise an
+     error.  */
+  if (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_PRESENT
+      && TREE_CODE (decl) == PARM_DECL
       && GFC_ARRAY_TYPE_P (TREE_TYPE (decl))
       && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (decl)) == GFC_ARRAY_UNKNOWN
       && GFC_TYPE_ARRAY_UBOUND (TREE_TYPE (decl),
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/pr70828-4.f90 b/libgomp/testsuite/libgomp.oacc-fortran/pr70828-4.f90
new file mode 100644
index 0000000..01da999
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/pr70828-4.f90
@@ -0,0 +1,31 @@
+! Subarrays declared on data construct: assumed-size array.
+
+subroutine s1(n, arr)
+  integer :: n
+  integer :: arr(*)
+
+  !$acc data copy(arr(5:n-10))
+  !$acc parallel loop
+  do i = 10, n - 10
+     arr(i) = i
+  end do
+  !$acc end parallel loop
+  !$acc end data
+end subroutine s1
+
+program test
+  integer, parameter :: n = 100
+  integer i, data(n)
+
+  data(:) = 0
+
+  call s1(n, data)
+
+  do i = 1, n
+     if ((i < 10 .or. i > n-10)) then
+        if ((data(i) .ne. 0)) call abort
+     else if (data(i) .ne. i) then
+        call abort
+     end if
+  end do
+end program test
-- 
1.8.1.1

Reply via email to