aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseOpenMP.cpp
diff options
context:
space:
mode:
authorRobert Imschweiler <robert.imschweiler@amd.com>2025-06-24 21:12:40 +0200
committerGitHub <noreply@github.com>2025-06-24 21:12:40 +0200
commitf624ba2d9d2143a0c2679ee9792cf455f965adec (patch)
tree9972bd391d8473a37c3ea2219583f4d3aaac6c06 /clang/lib/Parse/ParseOpenMP.cpp
parent4d21da002a056c64231fb89ee9e4eba90080e9bb (diff)
downloadllvm-f624ba2d9d2143a0c2679ee9792cf455f965adec.zip
llvm-f624ba2d9d2143a0c2679ee9792cf455f965adec.tar.gz
llvm-f624ba2d9d2143a0c2679ee9792cf455f965adec.tar.bz2
[OpenMP][clang] 6.0: parsing/sema for num_threads 'strict' modifier (#145490)
Implement parsing and semantic analysis support for the optional 'strict' modifier of the num_threads clause. This modifier has been introduced in OpenMP 6.0, section 12.1.2. Note: this is basically 1:1 https://reviews.llvm.org/D138328.
Diffstat (limited to 'clang/lib/Parse/ParseOpenMP.cpp')
-rw-r--r--clang/lib/Parse/ParseOpenMP.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 78d3503..f694ae1 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -3196,7 +3196,8 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
if ((CKind == OMPC_ordered || CKind == OMPC_partial) &&
PP.LookAhead(/*N=*/0).isNot(tok::l_paren))
Clause = ParseOpenMPClause(CKind, WrongDirective);
- else if (CKind == OMPC_grainsize || CKind == OMPC_num_tasks)
+ else if (CKind == OMPC_grainsize || CKind == OMPC_num_tasks ||
+ CKind == OMPC_num_threads)
Clause = ParseOpenMPSingleExprWithArgClause(DKind, CKind, WrongDirective);
else
Clause = ParseOpenMPSingleExprClause(CKind, WrongDirective);
@@ -3981,6 +3982,33 @@ OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
Arg.push_back(OMPC_NUMTASKS_unknown);
KLoc.emplace_back();
}
+ } else if (Kind == OMPC_num_threads) {
+ // Parse optional <num_threads modifier> ':'
+ OpenMPNumThreadsClauseModifier Modifier =
+ static_cast<OpenMPNumThreadsClauseModifier>(getOpenMPSimpleClauseType(
+ Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok),
+ getLangOpts()));
+ if (getLangOpts().OpenMP >= 60) {
+ if (NextToken().is(tok::colon)) {
+ Arg.push_back(Modifier);
+ KLoc.push_back(Tok.getLocation());
+ // Parse modifier
+ ConsumeAnyToken();
+ // Parse ':'
+ ConsumeAnyToken();
+ } else {
+ if (Modifier == OMPC_NUMTHREADS_strict) {
+ Diag(Tok, diag::err_modifier_expected_colon) << "strict";
+ // Parse modifier
+ ConsumeAnyToken();
+ }
+ Arg.push_back(OMPC_NUMTHREADS_unknown);
+ KLoc.emplace_back();
+ }
+ } else {
+ Arg.push_back(OMPC_NUMTHREADS_unknown);
+ KLoc.emplace_back();
+ }
} else {
assert(Kind == OMPC_if);
KLoc.push_back(Tok.getLocation());
@@ -4004,7 +4032,8 @@ OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) ||
(Kind == OMPC_dist_schedule && DelimLoc.isValid()) ||
Kind == OMPC_if || Kind == OMPC_device ||
- Kind == OMPC_grainsize || Kind == OMPC_num_tasks;
+ Kind == OMPC_grainsize || Kind == OMPC_num_tasks ||
+ Kind == OMPC_num_threads;
if (NeedAnExpression) {
SourceLocation ELoc = Tok.getLocation();
ExprResult LHS(ParseCastExpression(CastParseKind::AnyCastExpr, false,