https://github.com/ddpagan created 
https://github.com/llvm/llvm-project/pull/190470

In OpenMP 6.0, the 'local' clause was added to the declare_target directive. 
Variables listed in the 'local' clause are considered to be device-local. In 
addition, a new map clause restriction was added:
  A device-local variable must not appear as a list item in a map clause.
See OpenMP 6.0 specification section 7.9.6, map Clause, Restrictions, p. 386.

Testing:
  - New error messages test for device-local variables defined in 
declare_target local clauses (device-local) used in map clauses.
  - ninja check-openmp

>From 71cfbf42673fd7e45dfa086b456864d28a714af1 Mon Sep 17 00:00:00 2001
From: Dave Pagan <[email protected]>
Date: Sat, 4 Apr 2026 10:26:39 -0500
Subject: [PATCH] [clang][OpenMP] declare_target/local clause variable can't be
 in map clause

In OpenMP 6.0, the 'local' clause was added to the declare_target
directive. Variables listed in the 'local' clause are considered to be
device-local. In addition, a new map clause restriction was added:
  A device-local variable must not appear as a list item in a map clause.
See OpenMP 6.0 specification section 7.9.6, map Clause, Restrictions,
p. 386.

Testing:
  - New error messages test for device-local variables defined in
    declare_target local clauses (device-local) used in map clauses.
  - ninja check-openmp
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 ++
 clang/lib/Sema/SemaOpenMP.cpp                    | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eddf9c50033e1..3ff1f3ce00dcc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12401,6 +12401,8 @@ def err_omp_no_clause_for_directive : Error<
   "expected at least one %0 clause for '#pragma omp %1'">;
 def err_omp_threadprivate_in_clause : Error<
   "threadprivate variables are not allowed in '%0' clause">;
+def err_omp_device_local_in_clause : Error<
+  "device-local variable %0 is not allowed in '%1' clause">;
 def err_omp_wrong_ordered_loop_count : Error<
   "the parameter of the 'ordered' clause must be greater than or equal to the 
parameter of the 'collapse' clause">;
 def note_collapse_loop_count : Note<
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index fada37ba45755..73cbc7a428661 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -23301,6 +23301,21 @@ static void checkMappableExpressionList(
       continue;
     }
 
+    // OpenMP 6.0 [7.9.6, map Clause, Restrictions, p. 386]
+    // A device-local variable must not appear as a list item in a map clause.
+    if (VD && CKind == OMPC_map) {
+      if (std::optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res =
+              OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) {
+        if (*Res == OMPDeclareTargetDeclAttr::MT_Local) {
+          if (NoDiagnose)
+            continue;
+          SemaRef.Diag(ELoc, diag::err_omp_device_local_in_clause)
+              << VD << getOpenMPClauseNameForDiag(CKind);
+          continue;
+        }
+      }
+    }
+
     // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9]
     //  A list item cannot appear in both a map clause and a data-sharing
     //  attribute clause on the same construct.

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to