[Patch] OpenMP/Fortran: Error for groupprivate + threadprivate

Tobias Burnus <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
It seems to be uncontroversial that mixing groupprivate + threadprivate won't work.
And OpenMP spec issue 4663 also passed the first vote to restrict this.

Any comments before I commit the attached patch?

Tobias
groupprivate-threadprivate.diff (text/x-patch, 9.2 KB)
OpenMP/Fortran: Error for groupprivate + threadprivate

As OpenMP spec issue 4663 has been voted on, replace warning by error when
mixing threadprivate with groupprivate.

gcc/fortran/ChangeLog:

	* symbol.cc (gfc_check_conflict): Reject mixing OpenMP threadprivate 
	with groupprivate.
	* trans-common.cc (build_common_decl): Remove warning when mixing
	threadprivate with groupprivate.
	* trans-decl.cc (add_attributes_to_decl): Likewise.

gcc/testsuite/ChangeLog:

	* gfortran.dg/gomp/groupprivate-1.f90: Update test.
	* gfortran.dg/gomp/groupprivate-4.f90: Likewise.
	* gfortran.dg/gomp/groupprivate-6.f90: Likewise.
	* gfortran.dg/gomp/groupprivate-7.f90: Extend test.

 gcc/fortran/symbol.cc                             |  1 +
 gcc/fortran/trans-common.cc                       | 12 +-----------
 gcc/fortran/trans-decl.cc                         | 12 +-----------
 gcc/testsuite/gfortran.dg/gomp/groupprivate-1.f90 |  7 ++-----
 gcc/testsuite/gfortran.dg/gomp/groupprivate-4.f90 |  6 +-----
 gcc/testsuite/gfortran.dg/gomp/groupprivate-6.f90 |  8 ++++----
 gcc/testsuite/gfortran.dg/gomp/groupprivate-7.f90 | 19 +++++++++++++++++++
 7 files changed, 29 insertions(+), 36 deletions(-)

diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc
index 5a68f44ca63..5ff14e27b94 100644
--- a/gcc/fortran/symbol.cc
+++ b/gcc/fortran/symbol.cc
@@ -564,6 +564,7 @@ gfc_check_conflict (symbol_attribute *attr, const char *name, locus *where)
   conf (pointer, elemental);
   conf (pointer, codimension);
   conf (allocatable, elemental);
+  conf (threadprivate, omp_groupprivate);
 
   conf (in_common, automatic);
   conf (result, automatic);
diff --git a/gcc/fortran/trans-common.cc b/gcc/fortran/trans-common.cc
index 6c8bcd7c75c..4f68b64fb08 100644
--- a/gcc/fortran/trans-common.cc
+++ b/gcc/fortran/trans-common.cc
@@ -489,17 +489,7 @@ build_common_decl (gfc_common_head *com, tree union_type, bool is_init)
 	  omp_clauses = c;
 	}
       /* Also check trans-decl.cc when updating/removing the following;
-	 also update f95.c's gfc_gnu_attributes.
-	 For the warning, see also OpenMP spec issue 4663.  */
-      if (com->omp_groupprivate && com->threadprivate)
-	{
-	  /* Unset this flag; implicit 'declare target local(...)' remains.  */
-	  com->omp_groupprivate = 0;
-	  gfc_warning (OPT_Wopenmp,
-		       "Ignoring the %<groupprivate%> attribute for "
-		       "%<threadprivate%> common block %</%s/%> declared at %L",
-		       com->name, &com->where);
-	}
+	 also update f95.c's gfc_gnu_attributes.  */
       if (com->omp_groupprivate)
 	gfc_error ("Sorry, OMP GROUPPRIVATE not implemented, used by common "
 		   "block %</%s/%> declared at %L", com->name, &com->where);
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index ac675944aeb..851ccc45263 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1586,17 +1586,7 @@ add_attributes_to_decl (tree *decl_p, const gfc_symbol *sym)
     }
 
   /* Also check trans-common.cc when updating/removing the following;
-     also update f95.c's gfc_gnu_attributes.
-     For the warning, see also OpenMP spec issue 4663.  */
-  if (sym_attr.omp_groupprivate && sym_attr.threadprivate)
-    {
-      /* Unset this flag; implicit 'declare target local(...)' remains.  */
-      sym_attr.omp_groupprivate = 0;
-      gfc_warning (OPT_Wopenmp,
-		   "Ignoring the %<groupprivate%> attribute for "
-		   "%<threadprivate%> variable %qs declared at %L",
-		   sym->name, &sym->declared_at);
-    }
+     also update f95.c's gfc_gnu_attributes.  */
   if (sym_attr.omp_groupprivate)
     gfc_error ("Sorry, OMP GROUPPRIVATE not implemented, "
 	       "used by %qs declared at %L", sym->name, &sym->declared_at);
diff --git a/gcc/testsuite/gfortran.dg/gomp/groupprivate-1.f90 b/gcc/testsuite/gfortran.dg/gomp/groupprivate-1.f90
index f776c0875dd..1d9f5492d6a 100644
--- a/gcc/testsuite/gfortran.dg/gomp/groupprivate-1.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/groupprivate-1.f90
@@ -1,15 +1,14 @@
 module m
  implicit none
  integer :: ii
- integer :: x, y(20), z, v, u, k  ! { dg-warning "Ignoring the 'groupprivate' attribute for 'threadprivate' variable 'k' declared at .1. \\\[-Wopenmp\\\]" }
+ integer :: x, y(20), z, v, u, k
 ! { dg-error "Sorry, OMP GROUPPRIVATE not implemented, used by 'x' declared at .1." "" { target *-*-* } .-1 }
 ! { dg-error "Sorry, OMP GROUPPRIVATE not implemented, used by 'y' declared at .1." "" { target *-*-* } .-2 }
 ! { dg-error "Sorry, OMP GROUPPRIVATE not implemented, used by 'z' declared at .1." "" { target *-*-* } .-3 }
 ! { dg-error "Sorry, OMP GROUPPRIVATE not implemented, used by 'v' declared at .1." "" { target *-*-* } .-4 }
 ! { dg-error "Sorry, OMP GROUPPRIVATE not implemented, used by 'u' declared at .1." "" { target *-*-* } .-5 }
+! { dg-error "Sorry, OMP GROUPPRIVATE not implemented, used by 'k' declared at .1." "" { target *-*-* } .-6 }
 !
-! Note:Error different as 'groupprivate' flag is overwritten by 'threadprivate', cf. warning above.
-! { dg-error "Sorry, OMP DECLARE TARGET with LOCAL clause not implemented, used by 'k' declared at .1." "" { target *-*-* } .-8 }
  !$omp groupprivate(x, z) device_Type( any )
  !$omp declare target local(x) device_type ( any )
  !$omp declare target enter( ii) ,local(y), device_type ( host )
@@ -17,7 +16,5 @@ module m
  !$omp groupprivate(v) device_type (nohost )
  !$omp groupprivate(u)
 
- ! See also (currently unresolved) OpenMP Specification Issue 4663.
  !$omp groupprivate(k)
- !$omp threadprivate(k)
 end module
diff --git a/gcc/testsuite/gfortran.dg/gomp/groupprivate-4.f90 b/gcc/testsuite/gfortran.dg/gomp/groupprivate-4.f90
index 2a3a054483e..a980c1fa0bd 100644
--- a/gcc/testsuite/gfortran.dg/gomp/groupprivate-4.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/groupprivate-4.f90
@@ -9,8 +9,7 @@ module m
  common /b_z/ z  ! { dg-error "Sorry, OMP GROUPPRIVATE not implemented, used by common block '/b_z/' declared at .1." }
  common /b_v/ v  ! { dg-error "Sorry, OMP GROUPPRIVATE not implemented, used by common block '/b_v/' declared at .1." }
  common /b_u/ u  ! { dg-error "Sorry, OMP GROUPPRIVATE not implemented, used by common block '/b_u/' declared at .1." }
- common /b_k/ k  ! { dg-warning "Ignoring the 'groupprivate' attribute for 'threadprivate' common block '/b_k/' declared at .1. \\\[-Wopenmp\\\]" }
-! { dg-error "Sorry, OMP DECLARE TARGET with LOCAL clause not implemented, used by common block '/b_k/' declared at .1." "" { target *-*-* } .-1 }
+ common /b_k/ k  ! { dg-error "Sorry, OMP GROUPPRIVATE not implemented, used by common block '/b_k/' declared at .1." }
 
  !$omp groupprivate(/b_x/, /b_z/) device_Type( any )
  !$omp declare target local(/b_x/) device_type ( any )
@@ -18,8 +17,5 @@ module m
  !$omp groupprivate(/b_y/) device_type( host)
  !$omp groupprivate(/b_v/) device_type (nohost )
  !$omp groupprivate(/b_u/)
-
- ! See also (currently unresolved) OpenMP Specification Issue 4663.
  !$omp groupprivate(/b_k/)
- !$omp threadprivate(/b_k/)
 end module
diff --git a/gcc/testsuite/gfortran.dg/gomp/groupprivate-6.f90 b/gcc/testsuite/gfortran.dg/gomp/groupprivate-6.f90
index 6ae5b3dc59b..86813ecbcb1 100644
--- a/gcc/testsuite/gfortran.dg/gomp/groupprivate-6.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/groupprivate-6.f90
@@ -21,14 +21,14 @@ end
 subroutine dupl
   integer :: a,b,c,d
   integer :: u,v,w,x
-  common /b_a/ a
-  common /b_b/ b
+  common /b_a/ a ! { dg-error "THREADPRIVATE attribute conflicts with OpenMP GROUPPRIVATE attribute in 'a'" }
+  common /b_b/ b ! { dg-error "THREADPRIVATE attribute conflicts with OpenMP GROUPPRIVATE attribute in 'b'" }
   common /b_c/ c
   common /b_d/ d
 
   !$omp groupprivate(/b_a/,u,/b_a/) ! { dg-error "Duplicate OpenMP GROUPPRIVATE attribute specified" }
   !$omp groupprivate(v,/b_b/,v) ! { dg-error "Duplicate OpenMP GROUPPRIVATE attribute specified" }
 
-  !$omp threadprivate(/b_a/,u,/b_a/) ! { dg-error "Duplicate THREADPRIVATE attribute specified" }
-  !$omp threadprivate(v,/b_b/,v) ! { dg-error "Duplicate THREADPRIVATE attribute specified" }
+  !$omp threadprivate(/b_a/,u,/b_a/) ! { dg-error "THREADPRIVATE attribute conflicts with OpenMP GROUPPRIVATE attribute in 'a'" }
+  !$omp threadprivate(v,/b_b/,v) ! { dg-error "THREADPRIVATE attribute conflicts with OpenMP GROUPPRIVATE attribute in 'b'" }
 end
diff --git a/gcc/testsuite/gfortran.dg/gomp/groupprivate-7.f90 b/gcc/testsuite/gfortran.dg/gomp/groupprivate-7.f90
index 408009b3d68..0fce374e902 100644
--- a/gcc/testsuite/gfortran.dg/gomp/groupprivate-7.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/groupprivate-7.f90
@@ -18,4 +18,23 @@ common /com/ z
 !!$omp target enter data map(to : /com/) ! -> PR fortran/92730
 end
 
+subroutine g1
+integer, save :: x
+!$omp threadprivate(x)
+!$omp groupprivate(x)  ! { dg-error "THREADPRIVATE attribute conflicts with OpenMP GROUPPRIVATE attribute in 'x'" }
+end
+
+subroutine g2
+integer, save :: y
+!$omp groupprivate(y)
+!$omp threadprivate(y)  ! { dg-error "THREADPRIVATE attribute conflicts with OpenMP GROUPPRIVATE attribute in 'y'" }
+end
+
+subroutine h
+ ! Hmm, for some reasons, it is diagnosed twice ...
+ integer :: k
+ common /b_k/ k  ! { dg-error "THREADPRIVATE attribute conflicts with OpenMP GROUPPRIVATE attribute in 'k'" }
+ !$omp groupprivate(/b_k/)
+ !$omp threadprivate(/b_k/)  ! { dg-error "THREADPRIVATE attribute conflicts with OpenMP GROUPPRIVATE attribute in 'k'" }
+end
 end module
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.