@@ -15509,9 +15509,6 @@ OMPClause *SemaOpenMP::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
1550915509 case OMPC_final:
1551015510 Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc);
1551115511 break;
15512- case OMPC_num_threads:
15513- Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc);
15514- break;
1551515512 case OMPC_safelen:
1551615513 Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc);
1551715514 break;
@@ -15565,6 +15562,7 @@ OMPClause *SemaOpenMP::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
1556515562 break;
1556615563 case OMPC_grainsize:
1556715564 case OMPC_num_tasks:
15565+ case OMPC_num_threads:
1556815566 case OMPC_device:
1556915567 case OMPC_if:
1557015568 case OMPC_default:
@@ -15911,10 +15909,41 @@ isNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, OpenMPClauseKind CKind,
1591115909 return true;
1591215910}
1591315911
15914- OMPClause *SemaOpenMP::ActOnOpenMPNumThreadsClause(Expr *NumThreads,
15915- SourceLocation StartLoc,
15916- SourceLocation LParenLoc,
15917- SourceLocation EndLoc) {
15912+ static std::string getListOfPossibleValues(OpenMPClauseKind K, unsigned First,
15913+ unsigned Last,
15914+ ArrayRef<unsigned> Exclude = {}) {
15915+ SmallString<256> Buffer;
15916+ llvm::raw_svector_ostream Out(Buffer);
15917+ unsigned Skipped = Exclude.size();
15918+ for (unsigned I = First; I < Last; ++I) {
15919+ if (llvm::is_contained(Exclude, I)) {
15920+ --Skipped;
15921+ continue;
15922+ }
15923+ Out << "'" << getOpenMPSimpleClauseTypeName(K, I) << "'";
15924+ if (I + Skipped + 2 == Last)
15925+ Out << " or ";
15926+ else if (I + Skipped + 1 != Last)
15927+ Out << ", ";
15928+ }
15929+ return std::string(Out.str());
15930+ }
15931+
15932+ OMPClause *SemaOpenMP::ActOnOpenMPNumThreadsClause(
15933+ OpenMPNumThreadsClauseModifier Modifier, Expr *NumThreads,
15934+ SourceLocation StartLoc, SourceLocation LParenLoc,
15935+ SourceLocation ModifierLoc, SourceLocation EndLoc) {
15936+ assert((ModifierLoc.isInvalid() || getLangOpts().OpenMP >= 60) &&
15937+ "Unexpected num_threads modifier in OpenMP < 60.");
15938+
15939+ if (ModifierLoc.isValid() && Modifier == OMPC_NUMTHREADS_unknown) {
15940+ std::string Values = getListOfPossibleValues(OMPC_num_threads, /*First=*/0,
15941+ OMPC_NUMTHREADS_unknown);
15942+ Diag(ModifierLoc, diag::err_omp_unexpected_clause_value)
15943+ << Values << getOpenMPClauseNameForDiag(OMPC_num_threads);
15944+ return nullptr;
15945+ }
15946+
1591815947 Expr *ValExpr = NumThreads;
1591915948 Stmt *HelperValStmt = nullptr;
1592015949
@@ -15935,8 +15964,9 @@ OMPClause *SemaOpenMP::ActOnOpenMPNumThreadsClause(Expr *NumThreads,
1593515964 HelperValStmt = buildPreInits(getASTContext(), Captures);
1593615965 }
1593715966
15938- return new (getASTContext()) OMPNumThreadsClause(
15939- ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc);
15967+ return new (getASTContext())
15968+ OMPNumThreadsClause(Modifier, ValExpr, HelperValStmt, CaptureRegion,
15969+ StartLoc, LParenLoc, ModifierLoc, EndLoc);
1594015970}
1594115971
1594215972ExprResult SemaOpenMP::VerifyPositiveIntegerConstantInClause(
@@ -16301,26 +16331,6 @@ OMPClause *SemaOpenMP::ActOnOpenMPSimpleClause(
1630116331 return Res;
1630216332}
1630316333
16304- static std::string getListOfPossibleValues(OpenMPClauseKind K, unsigned First,
16305- unsigned Last,
16306- ArrayRef<unsigned> Exclude = {}) {
16307- SmallString<256> Buffer;
16308- llvm::raw_svector_ostream Out(Buffer);
16309- unsigned Skipped = Exclude.size();
16310- for (unsigned I = First; I < Last; ++I) {
16311- if (llvm::is_contained(Exclude, I)) {
16312- --Skipped;
16313- continue;
16314- }
16315- Out << "'" << getOpenMPSimpleClauseTypeName(K, I) << "'";
16316- if (I + Skipped + 2 == Last)
16317- Out << " or ";
16318- else if (I + Skipped + 1 != Last)
16319- Out << ", ";
16320- }
16321- return std::string(Out.str());
16322- }
16323-
1632416334OMPClause *SemaOpenMP::ActOnOpenMPDefaultClause(DefaultKind Kind,
1632516335 SourceLocation KindKwLoc,
1632616336 SourceLocation StartLoc,
@@ -16693,8 +16703,14 @@ OMPClause *SemaOpenMP::ActOnOpenMPSingleExprWithArgClause(
1669316703 static_cast<OpenMPNumTasksClauseModifier>(Argument.back()), Expr,
1669416704 StartLoc, LParenLoc, ArgumentLoc.back(), EndLoc);
1669516705 break;
16696- case OMPC_final:
1669716706 case OMPC_num_threads:
16707+ assert(Argument.size() == 1 && ArgumentLoc.size() == 1 &&
16708+ "Modifier for num_threads clause and its location are expected.");
16709+ Res = ActOnOpenMPNumThreadsClause(
16710+ static_cast<OpenMPNumThreadsClauseModifier>(Argument.back()), Expr,
16711+ StartLoc, LParenLoc, ArgumentLoc.back(), EndLoc);
16712+ break;
16713+ case OMPC_final:
1669816714 case OMPC_safelen:
1669916715 case OMPC_simdlen:
1670016716 case OMPC_sizes:
0 commit comments