]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP/Fortran: Error for groupprivate + threadprivate
authorTobias Burnus <tburnus@baylibre.com>
Wed, 18 Feb 2026 09:05:39 +0000 (10:05 +0100)
committerTobias Burnus <tburnus@baylibre.com>
Wed, 18 Feb 2026 09:05:39 +0000 (10:05 +0100)
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
gcc/fortran/trans-common.cc
gcc/fortran/trans-decl.cc
gcc/testsuite/gfortran.dg/gomp/groupprivate-1.f90
gcc/testsuite/gfortran.dg/gomp/groupprivate-4.f90
gcc/testsuite/gfortran.dg/gomp/groupprivate-6.f90
gcc/testsuite/gfortran.dg/gomp/groupprivate-7.f90

index 5a68f44ca635969ca541e4be823c632820527f91..5ff14e27b942d3af828117f7ece41e790623a0b9 100644 (file)
@@ -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);
index 6c8bcd7c75c266d018fa2aefbd467167aeac76ac..4f68b64fb08f15b18b645f989b1c331dc3873555 100644 (file)
@@ -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);
index ac675944aeb3c8bb30270681dbcb53f79e876e36..851ccc45263f8e4e48be10b89607aa32261c8a3e 100644 (file)
@@ -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);
index f776c0875dd0bc4923edfb4cda58fa876cf505f9..1d9f5492d6af275a24edc1b7d8e0b99b702fdb28 100644 (file)
@@ -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
index 2a3a054483e8e8c77c00b2168bc55ab9a272436f..a980c1fa0bd6422093fdbe757fb9bc91165340dd 100644 (file)
@@ -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
index 6ae5b3dc59b14be4fc531beeae4a1fdd3301f715..86813ecbcb12062a8e3c0aa42d502931693c8a20 100644 (file)
@@ -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
index 408009b3d688fd24a786ec5f79a366dfdef2b81e..0fce374e9021259c5d36e9c10b20e4990ffd2eb0 100644 (file)
@@ -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