https://gcc.gnu.org/g:1284cefa89b2579c0a91134d8f5d93ef7f2b66f3

commit r16-7067-g1284cefa89b2579c0a91134d8f5d93ef7f2b66f3
Author: Tobias Burnus <[email protected]>
Date:   Tue Jan 27 13:05:27 2026 +0100

    Fortran/OpenMP: Reject device-local var in MAP clause
    
    gcc/fortran/ChangeLog:
    
            * openmp.cc (resolve_omp_clauses): Reject groupprivate/device-local
            variables in MAP clauses.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/gomp/groupprivate-7.f90: New test.

Diff:
---
 gcc/fortran/openmp.cc                             |  6 ++++++
 gcc/testsuite/gfortran.dg/gomp/groupprivate-7.f90 | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 5823ac41fa51..af3cb54ad561 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -9890,6 +9890,12 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses 
*omp_clauses,
                                     &n->where);
                      }
                  }
+               if (list == OMP_LIST_MAP
+                   && (n->sym->attr.omp_groupprivate
+                       || n->sym->attr.omp_declare_target_local))
+                 gfc_error ("%qs argument to MAP clause at %L must not be a "
+                            "device-local variable, including GROUPPRIVATE",
+                            n->sym->name, &n->where);
                if (openacc
                    && list == OMP_LIST_MAP
                    && (n->u.map.op == OMP_MAP_ATTACH
diff --git a/gcc/testsuite/gfortran.dg/gomp/groupprivate-7.f90 
b/gcc/testsuite/gfortran.dg/gomp/groupprivate-7.f90
new file mode 100644
index 000000000000..408009b3d688
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/groupprivate-7.f90
@@ -0,0 +1,21 @@
+module m
+implicit none
+integer :: x
+!$omp declare target local(x)
+contains
+subroutine f
+integer, save :: y
+integer  :: z
+common /com/ z
+
+! A variable that is a groupprivate variable or a device-local variable must
+! not appear as a list item in a map clause.
+
+!$omp groupprivate(y)
+!$omp groupprivate(/com/)
+!$omp target enter data map(x) ! { dg-error "'x' argument to MAP clause at .1. 
must not be a device-local variable, including GROUPPRIVATE" }
+!$omp target enter data map(y) ! { dg-error "'y' argument to MAP clause at .1. 
must not be a device-local variable, including GROUPPRIVATE" }
+!!$omp target enter data map(to : /com/) ! -> PR fortran/92730
+end
+
+end module

Reply via email to