[clang] [clang][OpenMP] 6.0: Add default clause support for 'target' directive (PR #162910)

David Pagan via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 14 10:04:04 PDT 2025


================
@@ -17309,21 +17346,40 @@ OMPClause *SemaOpenMP::ActOnOpenMPDefaultClause(
     return nullptr;
   }
 
-  switch (M) {
-  case OMP_DEFAULT_none:
-    DSAStack->setDefaultDSANone(MLoc);
-    break;
-  case OMP_DEFAULT_shared:
-    DSAStack->setDefaultDSAShared(MLoc);
-    break;
-  case OMP_DEFAULT_firstprivate:
-    DSAStack->setDefaultDSAFirstPrivate(MLoc);
-    break;
-  case OMP_DEFAULT_private:
-    DSAStack->setDefaultDSAPrivate(MLoc);
-    break;
-  default:
-    llvm_unreachable("DSA unexpected in OpenMP default clause");
+  if (getLangOpts().OpenMP >= 60 &&
+      DSAStack->getCurrentDirective() == OMPD_target) {
+    // OpenMP 6.0 (see page 224, lines 3-5) default Clause, Semantics
+    // If data-sharing-attribute is shared then the clause has no effect
+    // on a target construct; otherwise, its effect on a target construct is
+    // equivalent to specifying the defaultmap clause with the same
+    // data-sharing-attribute and variable-category.
+    if (M != OMP_DEFAULT_shared) {
+      auto [DefMapMod, DefMapKind] = getDefaultmapModifierAndKind(M, VCKind);
+      if (DefMapKind == OMPC_DEFAULTMAP_all) {
+        DSAStack->setDefaultDMAAttr(DefMapMod, OMPC_DEFAULTMAP_aggregate, MLoc);
+        DSAStack->setDefaultDMAAttr(DefMapMod, OMPC_DEFAULTMAP_scalar, MLoc);
+        DSAStack->setDefaultDMAAttr(DefMapMod, OMPC_DEFAULTMAP_pointer, MLoc);
+      } else {
+        DSAStack->setDefaultDMAAttr(DefMapMod, DefMapKind, MLoc);
+      }
+    }
+  } else {
+    switch (M) {
+    case OMP_DEFAULT_none:
+      DSAStack->setDefaultDSANone(MLoc);
+      break;
+    case OMP_DEFAULT_shared:
+      DSAStack->setDefaultDSAShared(MLoc);
+      break;
+    case OMP_DEFAULT_firstprivate:
+      DSAStack->setDefaultDSAFirstPrivate(MLoc);
+      break;
+    case OMP_DEFAULT_private:
+      DSAStack->setDefaultDSAPrivate(MLoc);
+      break;
+    default:
+      llvm_unreachable("DSA unexpected in OpenMP default clause");
+    }
----------------
ddpagan wrote:

Thanks for the review, @alexey-bataev. I'll work on merging this as you suggested. Note, though, per the original implementation of variable category for the 'default' clause, VCKind is always set to an appropriate value whatever version we're compiling with. If the version is not 6.0, the value defaults to all.

https://github.com/llvm/llvm-project/pull/162910


More information about the cfe-commits mailing list