Currently, the gimplifier will incorrectly create implicit firstprivate
mappings for pointer variables. That's fine except when the pointer
points to a dummy argument. In which case, the gimplifier should check
the type of the value being pointed to before deciding on the type of
implicit mapping. This patch teaches the gimplifier to do that. This
corrects a bug where a dummy array gets implicitly transferred as
firstprivate instead of pcopy.

I've applied patch has been committed to gomp-4_0-branch.

Cesar
2015-09-22  Cesar Philippidis  <ce...@codesourcery.com>

	gcc/
	* gimplify.c (oacc_default_clause): Inspect pointer types when
	determining implicit data mappings.

	libgomp/
	* testsuite/libgomp.oacc-fortran/dummy-array.f90: New test.
	* testsuite/libgomp.oacc-fortran/reference-reductions.f90: New test.

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 914570b..6dc7df7 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -5948,7 +5948,8 @@ oacc_default_clause (struct gimplify_omp_ctx *ctx, tree decl, unsigned flags)
 	  {
 	    tree type = TREE_TYPE (decl);
 
-	    if (TREE_CODE (type) == REFERENCE_TYPE)
+	    if (TREE_CODE (type) == REFERENCE_TYPE
+		|| POINTER_TYPE_P (type))
 	      type = TREE_TYPE (type);
 	
 	    if (AGGREGATE_TYPE_P (type))
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/dummy-array.f90 b/libgomp/testsuite/libgomp.oacc-fortran/dummy-array.f90
new file mode 100644
index 0000000..e95563c
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/dummy-array.f90
@@ -0,0 +1,28 @@
+! Ensure that dummy arrays are transferred to the accelerator
+! via an implicit pcopy.
+
+! { dg-do run } 
+
+program main
+  integer, parameter :: n = 1000
+  integer :: a(n)
+  integer :: i
+
+  a(:) = -1
+
+  call dummy_array (a, n)
+  
+  do i = 1, n
+     if (a(i) .ne. i) call abort
+  end do
+end program main
+
+subroutine dummy_array (a, n)
+  integer a(n)
+
+  !$acc parallel loop num_gangs (100) gang
+  do i = 1, n
+     a(i) = i
+  end do
+  !$acc end parallel loop
+end subroutine
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/reference-reductions.f90 b/libgomp/testsuite/libgomp.oacc-fortran/reference-reductions.f90
new file mode 100644
index 0000000..a684d07
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/reference-reductions.f90
@@ -0,0 +1,38 @@
+! Test reductions on dummy arguments inside modules.
+
+! { dg-do run }
+
+module prm
+  implicit none
+
+contains
+
+subroutine param_reduction(var)
+  implicit none
+  integer(kind=8) :: var
+  integer      :: j,k
+
+!$acc parallel copy(var)
+!$acc loop reduction(+ : var) gang
+ do k=1,10
+!$acc loop vector reduction(+ : var)
+    do j=1,100
+     var = var + 1.0
+    enddo
+ enddo
+!$acc end parallel
+end subroutine param_reduction
+
+end module prm
+
+program test
+  use prm
+  implicit none
+
+  integer(8) :: r
+
+  r=10.0
+  call param_reduction (r)
+
+  if (r .ne. 1010) call abort ()
+end program test

Reply via email to