================
@@ -17316,45 +17316,101 @@ OMPClause *SemaOpenMP::ActOnOpenMPDefaultClause(
         << getOpenMPClauseNameForDiag(OMPC_default);
     return nullptr;
   }
+  if (VCKind == OMPC_DEFAULT_VC_unknown) {
+    Diag(VCKindLoc, diag::err_omp_default_vc)
+        << getOpenMPSimpleClauseTypeName(OMPC_default, unsigned(M));
+    return nullptr;
+  }
+  bool IsTargetDefault = getLangOpts().OpenMP >= 60 &&
+                         DSAStack->getCurrentDirective() == OMPD_target;
 
+  // OpenMP 6.0, page 224, lines 3-4 default Clause, Semantics
+  // If data-sharing-attribute is shared then the clause has no effect
+  // on a target construct;
+  if (IsTargetDefault && M == OMP_DEFAULT_shared)
+    return nullptr;
+
+  OpenMPDefaultmapClauseModifier DefMapMod;
+  OpenMPDefaultmapClauseKind DefMapKind;
+  std::function<void(SourceLocation)> SetDefaultDSA;
+  std::function<void(SourceLocation)> SetDefaultDSAVC;
+  // default data-sharing-attribute
   switch (M) {
   case OMP_DEFAULT_none:
-    DSAStack->setDefaultDSANone(MLoc);
-    break;
-  case OMP_DEFAULT_shared:
-    DSAStack->setDefaultDSAShared(MLoc);
+    DefMapMod = OMPC_DEFAULTMAP_MODIFIER_none;
+    SetDefaultDSA = [&](SourceLocation MLoc) {
+      DSAStack->setDefaultDSANone(MLoc);
+    };
     break;
   case OMP_DEFAULT_firstprivate:
-    DSAStack->setDefaultDSAFirstPrivate(MLoc);
+    DefMapMod = OMPC_DEFAULTMAP_MODIFIER_firstprivate;
+    SetDefaultDSA = [&](SourceLocation MLoc) {
+      DSAStack->setDefaultDSAFirstPrivate(MLoc);
+    };
     break;
   case OMP_DEFAULT_private:
-    DSAStack->setDefaultDSAPrivate(MLoc);
+    DefMapMod = OMPC_DEFAULTMAP_MODIFIER_private;
+    SetDefaultDSA = [&](SourceLocation MLoc) {
+      DSAStack->setDefaultDSAPrivate(MLoc);
+    };
+    break;
+  case OMP_DEFAULT_shared:
+    assert(!IsTargetDefault && "DSA shared invalid with target directive");
+    SetDefaultDSA = [&](SourceLocation MLoc) {
+      DSAStack->setDefaultDSAShared(MLoc);
+    };
     break;
   default:
-    llvm_unreachable("DSA unexpected in OpenMP default clause");
+    llvm_unreachable("unexpected DSA in OpenMP default clause");
   }
-
+  // default variable-category
   switch (VCKind) {
   case OMPC_DEFAULT_VC_aggregate:
-    DSAStack->setDefaultDSAVCAggregate(VCKindLoc);
-    break;
-  case OMPC_DEFAULT_VC_all:
-    DSAStack->setDefaultDSAVCAll(VCKindLoc);
-    break;
-  case OMPC_DEFAULT_VC_allocatable:
-    DSAStack->setDefaultDSAVCAllocatable(VCKindLoc);
+    DefMapKind = OMPC_DEFAULTMAP_aggregate;
+    SetDefaultDSAVC = [&](SourceLocation VCKindLoc) {
+      DSAStack->setDefaultDSAVCAggregate(VCKindLoc);
+    };
     break;
   case OMPC_DEFAULT_VC_pointer:
-    DSAStack->setDefaultDSAVCPointer(VCKindLoc);
+    DefMapKind = OMPC_DEFAULTMAP_pointer;
+    SetDefaultDSAVC = [&](SourceLocation VCKindLoc) {
+      DSAStack->setDefaultDSAVCPointer(VCKindLoc);
+    };
     break;
   case OMPC_DEFAULT_VC_scalar:
-    DSAStack->setDefaultDSAVCScalar(VCKindLoc);
+    DefMapKind = OMPC_DEFAULTMAP_scalar;
+    SetDefaultDSAVC = [&](SourceLocation VCKindLoc) {
+      DSAStack->setDefaultDSAVCScalar(VCKindLoc);
+    };
+    break;
+  case OMPC_DEFAULT_VC_all:
+    DefMapKind = OMPC_DEFAULTMAP_all;
+    SetDefaultDSAVC = [&](SourceLocation VCKindLoc) {
+      DSAStack->setDefaultDSAVCAll(VCKindLoc);
+    };
     break;
   default:
-    Diag(VCKindLoc, diag::err_omp_default_vc)
-        << getOpenMPSimpleClauseTypeName(OMPC_default, unsigned(M));
+    llvm_unreachable("unexpected variable category in OpenMP default clause");
+  }
----------------
alexey-bataev wrote:

Why just not put this whole logic in lambda and call it, where required, 
instead of having std:function?

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

Reply via email to