@@ -17305,112 +17305,112 @@ OMPClause *SemaOpenMP::ActOnOpenMPSimpleClause(
1730517305 return Res;
1730617306}
1730717307
17308- static std::pair<OpenMPDefaultmapClauseModifier, OpenMPDefaultmapClauseKind>
17309- getDefaultmapModifierAndKind(llvm::omp::DefaultKind M,
17310- OpenMPDefaultClauseVariableCategory VCKind) {
17308+ OMPClause *SemaOpenMP::ActOnOpenMPDefaultClause(
17309+ llvm::omp::DefaultKind M, SourceLocation MLoc,
17310+ OpenMPDefaultClauseVariableCategory VCKind, SourceLocation VCKindLoc,
17311+ SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) {
17312+ if (M == OMP_DEFAULT_unknown) {
17313+ Diag(MLoc, diag::err_omp_unexpected_clause_value)
17314+ << getListOfPossibleValues(OMPC_default, /*First=*/0,
17315+ /*Last=*/unsigned(OMP_DEFAULT_unknown))
17316+ << getOpenMPClauseNameForDiag(OMPC_default);
17317+ return nullptr;
17318+ }
17319+ if (VCKind == OMPC_DEFAULT_VC_unknown) {
17320+ Diag(VCKindLoc, diag::err_omp_default_vc)
17321+ << getOpenMPSimpleClauseTypeName(OMPC_default, unsigned(M));
17322+ return nullptr;
17323+ }
17324+ bool IsTargetDefault = getLangOpts().OpenMP >= 60 &&
17325+ DSAStack->getCurrentDirective() == OMPD_target;
17326+
17327+ // OpenMP 6.0, page 224, lines 3-4 default Clause, Semantics
17328+ // If data-sharing-attribute is shared then the clause has no effect
17329+ // on a target construct;
17330+ if (IsTargetDefault && M == OMP_DEFAULT_shared)
17331+ return nullptr;
17332+
1731117333 OpenMPDefaultmapClauseModifier DefMapMod;
1731217334 OpenMPDefaultmapClauseKind DefMapKind;
17335+ std::function<void(SourceLocation)> SetDefaultDSA;
17336+ std::function<void(SourceLocation)> SetDefaultDSAVC;
17337+ // default data-sharing-attribute
1731317338 switch (M) {
1731417339 case OMP_DEFAULT_none:
1731517340 DefMapMod = OMPC_DEFAULTMAP_MODIFIER_none;
17341+ SetDefaultDSA = [&](SourceLocation MLoc) {
17342+ DSAStack->setDefaultDSANone(MLoc);
17343+ };
1731617344 break;
1731717345 case OMP_DEFAULT_firstprivate:
1731817346 DefMapMod = OMPC_DEFAULTMAP_MODIFIER_firstprivate;
17347+ SetDefaultDSA = [&](SourceLocation MLoc) {
17348+ DSAStack->setDefaultDSAFirstPrivate(MLoc);
17349+ };
1731917350 break;
1732017351 case OMP_DEFAULT_private:
1732117352 DefMapMod = OMPC_DEFAULTMAP_MODIFIER_private;
17353+ SetDefaultDSA = [&](SourceLocation MLoc) {
17354+ DSAStack->setDefaultDSAPrivate(MLoc);
17355+ };
17356+ break;
17357+ case OMP_DEFAULT_shared:
17358+ assert(!IsTargetDefault && "DSA shared invalid with target directive");
17359+ SetDefaultDSA = [&](SourceLocation MLoc) {
17360+ DSAStack->setDefaultDSAShared(MLoc);
17361+ };
1732217362 break;
1732317363 default:
1732417364 llvm_unreachable("unexpected DSA in OpenMP default clause");
1732517365 }
17366+ // default variable-category
1732617367 switch (VCKind) {
1732717368 case OMPC_DEFAULT_VC_aggregate:
1732817369 DefMapKind = OMPC_DEFAULTMAP_aggregate;
17370+ SetDefaultDSAVC = [&](SourceLocation VCKindLoc) {
17371+ DSAStack->setDefaultDSAVCAggregate(VCKindLoc);
17372+ };
1732917373 break;
1733017374 case OMPC_DEFAULT_VC_pointer:
1733117375 DefMapKind = OMPC_DEFAULTMAP_pointer;
17376+ SetDefaultDSAVC = [&](SourceLocation VCKindLoc) {
17377+ DSAStack->setDefaultDSAVCPointer(VCKindLoc);
17378+ };
1733217379 break;
1733317380 case OMPC_DEFAULT_VC_scalar:
1733417381 DefMapKind = OMPC_DEFAULTMAP_scalar;
17382+ SetDefaultDSAVC = [&](SourceLocation VCKindLoc) {
17383+ DSAStack->setDefaultDSAVCScalar(VCKindLoc);
17384+ };
1733517385 break;
1733617386 case OMPC_DEFAULT_VC_all:
1733717387 DefMapKind = OMPC_DEFAULTMAP_all;
17388+ SetDefaultDSAVC = [&](SourceLocation VCKindLoc) {
17389+ DSAStack->setDefaultDSAVCAll(VCKindLoc);
17390+ };
1733817391 break;
1733917392 default:
1734017393 llvm_unreachable("unexpected variable category in OpenMP default clause");
1734117394 }
17342- return std::make_pair(DefMapMod, DefMapKind);
17343- }
1734417395
17345- OMPClause *SemaOpenMP::ActOnOpenMPDefaultClause(
17346- llvm::omp::DefaultKind M, SourceLocation MLoc,
17347- OpenMPDefaultClauseVariableCategory VCKind, SourceLocation VCKindLoc,
17348- SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) {
17349- if (M == OMP_DEFAULT_unknown) {
17350- Diag(MLoc, diag::err_omp_unexpected_clause_value)
17351- << getListOfPossibleValues(OMPC_default, /*First=*/0,
17352- /*Last=*/unsigned(OMP_DEFAULT_unknown))
17353- << getOpenMPClauseNameForDiag(OMPC_default);
17354- return nullptr;
17355- }
17356-
17357- if (getLangOpts().OpenMP >= 60 &&
17358- DSAStack->getCurrentDirective() == OMPD_target) {
17359- // OpenMP 6.0 (see page 224, lines 3-5) default Clause, Semantics
17360- // If data-sharing-attribute is shared then the clause has no effect
17361- // on a target construct; otherwise, its effect on a target construct is
17362- // equivalent to specifying the defaultmap clause with the same
17363- // data-sharing-attribute and variable-category.
17364- if (M != OMP_DEFAULT_shared) {
17365- auto [DefMapMod, DefMapKind] = getDefaultmapModifierAndKind(M, VCKind);
17366- if (DefMapKind == OMPC_DEFAULTMAP_all) {
17367- DSAStack->setDefaultDMAAttr(DefMapMod, OMPC_DEFAULTMAP_aggregate, MLoc);
17368- DSAStack->setDefaultDMAAttr(DefMapMod, OMPC_DEFAULTMAP_scalar, MLoc);
17369- DSAStack->setDefaultDMAAttr(DefMapMod, OMPC_DEFAULTMAP_pointer, MLoc);
17370- } else {
17371- DSAStack->setDefaultDMAAttr(DefMapMod, DefMapKind, MLoc);
17372- }
17396+ // OpenMP 6.0, page 224, lines 4-5 default Clause, Semantics
17397+ // otherwise, its effect on a target construct is equivalent to
17398+ // specifying the defaultmap clause with the same data-sharing-attribute
17399+ // and variable-category.
17400+ if (IsTargetDefault) {
17401+ if (DefMapKind == OMPC_DEFAULTMAP_all) {
17402+ DSAStack->setDefaultDMAAttr(DefMapMod, OMPC_DEFAULTMAP_aggregate, MLoc);
17403+ DSAStack->setDefaultDMAAttr(DefMapMod, OMPC_DEFAULTMAP_scalar, MLoc);
17404+ DSAStack->setDefaultDMAAttr(DefMapMod, OMPC_DEFAULTMAP_pointer, MLoc);
17405+ } else {
17406+ DSAStack->setDefaultDMAAttr(DefMapMod, DefMapKind, MLoc);
1737317407 }
1737417408 } else {
17375- switch (M) {
17376- case OMP_DEFAULT_none:
17377- DSAStack->setDefaultDSANone(MLoc);
17378- break;
17379- case OMP_DEFAULT_shared:
17380- DSAStack->setDefaultDSAShared(MLoc);
17381- break;
17382- case OMP_DEFAULT_firstprivate:
17383- DSAStack->setDefaultDSAFirstPrivate(MLoc);
17384- break;
17385- case OMP_DEFAULT_private:
17386- DSAStack->setDefaultDSAPrivate(MLoc);
17387- break;
17388- default:
17389- llvm_unreachable("DSA unexpected in OpenMP default clause");
17390- }
17391- }
17392-
17393- switch (VCKind) {
17394- case OMPC_DEFAULT_VC_aggregate:
17395- DSAStack->setDefaultDSAVCAggregate(VCKindLoc);
17396- break;
17397- case OMPC_DEFAULT_VC_all:
17398- DSAStack->setDefaultDSAVCAll(VCKindLoc);
17399- break;
17400- case OMPC_DEFAULT_VC_allocatable:
17401- DSAStack->setDefaultDSAVCAllocatable(VCKindLoc);
17402- break;
17403- case OMPC_DEFAULT_VC_pointer:
17404- DSAStack->setDefaultDSAVCPointer(VCKindLoc);
17405- break;
17406- case OMPC_DEFAULT_VC_scalar:
17407- DSAStack->setDefaultDSAVCScalar(VCKindLoc);
17408- break;
17409- default:
17410- Diag(VCKindLoc, diag::err_omp_default_vc)
17411- << getOpenMPSimpleClauseTypeName(OMPC_default, unsigned(M));
17409+ // If earlier than OpenMP 6.0, or not a target directive, then set
17410+ // default DSA as before.
17411+ SetDefaultDSA(MLoc);
17412+ SetDefaultDSAVC(VCKindLoc);
1741217413 }
17413-
1741417414 return new (getASTContext())
1741517415 OMPDefaultClause(M, MLoc, VCKind, VCKindLoc, StartLoc, LParenLoc, EndLoc);
1741617416}
0 commit comments