This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix default(none) with array parameters (PR fortran/59488)


Hi!

This patch makes Fortran array/derived parameters as well as
vtables predetermined shared.  For the standard proper those aren't
really variables at all, and as they are global vars, shared is
the best predetermination for them.

2014-10-10  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/59488
	* trans-openmp.c (gfc_omp_predetermined_sharing): Return
	OMP_CLAUSE_DEFAULT_SHARED for parameters or vtables.

	* gfortran.dg/gomp/pr59488-1.f90: New test.
	* gfortran.dg/gomp/pr59488-2.f90: New test.

--- gcc/fortran/trans-openmp.c.jj	2014-09-01 09:43:40.000000000 +0200
+++ gcc/fortran/trans-openmp.c	2014-10-10 10:15:00.426035513 +0200
@@ -135,6 +135,16 @@ gfc_omp_predetermined_sharing (tree decl
   if (GFC_DECL_RESULT (decl) && ! DECL_HAS_VALUE_EXPR_P (decl))
     return OMP_CLAUSE_DEFAULT_SHARED;
 
+  /* These are either array or derived parameters, or vtables.
+     In the former cases, the OpenMP standard doesn't consider them to be
+     variables at all (they can't be redefined), but they can nevertheless appear
+     in parallel/task regions and for default(none) purposes treat them as shared.
+     For vtables likely the same handling is desirable.  */
+  if (TREE_CODE (decl) == VAR_DECL
+      && TREE_READONLY (decl)
+      && TREE_STATIC (decl))
+    return OMP_CLAUSE_DEFAULT_SHARED;
+
   return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
 }
 
--- gcc/testsuite/gfortran.dg/gomp/pr59488-1.f90.jj	2014-10-10 10:06:38.231365699 +0200
+++ gcc/testsuite/gfortran.dg/gomp/pr59488-1.f90	2014-10-10 10:06:56.054036548 +0200
@@ -0,0 +1,13 @@
+! PR fortran/59488
+! { dg-do compile }
+! { dg-options "-fopenmp" }
+
+  implicit none
+  integer, parameter :: p(2) = (/ 11, 12 /)
+  integer :: r
+
+  !$omp parallel do default(none)
+  do r = 1, 2
+    print *, p(r)
+  end do
+end
--- gcc/testsuite/gfortran.dg/gomp/pr59488-2.f90.jj	2014-10-10 10:06:41.331308441 +0200
+++ gcc/testsuite/gfortran.dg/gomp/pr59488-2.f90	2014-10-10 10:08:07.000000000 +0200
@@ -0,0 +1,16 @@
+! PR fortran/59488
+! { dg-do compile }
+! { dg-options "-fopenmp" }
+
+  implicit none
+  type t
+    integer :: s1, s2, s3
+  end type
+  integer :: r
+  type(t), parameter :: u = t(1, 2, 3)
+
+  !$omp parallel do default(none)
+  do r = 1, 2
+    print *, u
+  end do
+end

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]