aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaOpenMP.cpp
diff options
context:
space:
mode:
authorRobert Imschweiler <robert.imschweiler@amd.com>2025-08-28 10:52:27 +0200
committerGitHub <noreply@github.com>2025-08-28 08:52:27 +0000
commitbaf9d2c35d37f8066c349964b0ef1988762844e7 (patch)
tree63c594cfc214e8fd85b98097b0009a1682e5b4d9 /clang/lib/Sema/SemaOpenMP.cpp
parentb0f8f526f5a903a68ff80943ceb50f6e64063ebd (diff)
downloadllvm-baf9d2c35d37f8066c349964b0ef1988762844e7.zip
llvm-baf9d2c35d37f8066c349964b0ef1988762844e7.tar.gz
llvm-baf9d2c35d37f8066c349964b0ef1988762844e7.tar.bz2
[OpenMP][clang] 6.0: num_threads strict (part 3: codegen) (#146405)
OpenMP 6.0 12.1.2 specifies the behavior of the strict modifier for the num_threads clause on parallel directives, along with the message and severity clauses. This commit implements necessary codegen changes.
Diffstat (limited to 'clang/lib/Sema/SemaOpenMP.cpp')
-rw-r--r--clang/lib/Sema/SemaOpenMP.cpp48
1 files changed, 36 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 8f666ce..9bbb84f 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -11097,22 +11097,27 @@ StmtResult SemaOpenMP::ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses,
return StmtError();
}
- const OMPSeverityClause *SeverityC =
- OMPExecutableDirective::getSingleClause<OMPSeverityClause>(Clauses);
- const OMPMessageClause *MessageC =
- OMPExecutableDirective::getSingleClause<OMPMessageClause>(Clauses);
- Expr *ME = MessageC ? MessageC->getMessageString() : nullptr;
-
if (!AtC || AtC->getAtKind() == OMPC_AT_compilation) {
+ const OMPSeverityClause *SeverityC =
+ OMPExecutableDirective::getSingleClause<OMPSeverityClause>(Clauses);
+ const OMPMessageClause *MessageC =
+ OMPExecutableDirective::getSingleClause<OMPMessageClause>(Clauses);
+ std::optional<std::string> SL =
+ MessageC ? MessageC->tryEvaluateString(getASTContext()) : std::nullopt;
+
+ if (MessageC && !SL)
+ Diag(MessageC->getMessageString()->getBeginLoc(),
+ diag::warn_clause_expected_string_literal)
+ << getOpenMPClauseNameForDiag(OMPC_message);
if (SeverityC && SeverityC->getSeverityKind() == OMPC_SEVERITY_warning)
Diag(SeverityC->getSeverityKindKwLoc(), diag::warn_diagnose_if_succeeded)
- << (ME ? cast<StringLiteral>(ME)->getString() : "WARNING");
+ << SL.value_or("WARNING");
else
- Diag(StartLoc, diag::err_diagnose_if_succeeded)
- << (ME ? cast<StringLiteral>(ME)->getString() : "ERROR");
+ Diag(StartLoc, diag::err_diagnose_if_succeeded) << SL.value_or("ERROR");
if (!SeverityC || SeverityC->getSeverityKind() != OMPC_SEVERITY_warning)
return StmtError();
}
+
return OMPErrorDirective::Create(getASTContext(), StartLoc, EndLoc, Clauses);
}
@@ -16464,13 +16469,32 @@ OMPClause *SemaOpenMP::ActOnOpenMPMessageClause(Expr *ME,
SourceLocation LParenLoc,
SourceLocation EndLoc) {
assert(ME && "NULL expr in Message clause");
- if (!isa<StringLiteral>(ME)) {
+ QualType Type = ME->getType();
+ if ((!Type->isPointerType() && !Type->isArrayType()) ||
+ !Type->getPointeeOrArrayElementType()->isAnyCharacterType()) {
Diag(ME->getBeginLoc(), diag::warn_clause_expected_string)
<< getOpenMPClauseNameForDiag(OMPC_message);
return nullptr;
}
- return new (getASTContext())
- OMPMessageClause(ME, StartLoc, LParenLoc, EndLoc);
+
+ Stmt *HelperValStmt = nullptr;
+
+ OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
+ OpenMPDirectiveKind CaptureRegion = getOpenMPCaptureRegionForClause(
+ DKind, OMPC_message, getLangOpts().OpenMP);
+ if (CaptureRegion != OMPD_unknown &&
+ !SemaRef.CurContext->isDependentContext()) {
+ ME = SemaRef.MakeFullExpr(ME).get();
+ llvm::MapVector<const Expr *, DeclRefExpr *> Captures;
+ ME = tryBuildCapture(SemaRef, ME, Captures).get();
+ HelperValStmt = buildPreInits(getASTContext(), Captures);
+ }
+
+ // Convert array type to pointer type if needed.
+ ME = SemaRef.DefaultFunctionArrayLvalueConversion(ME).get();
+
+ return new (getASTContext()) OMPMessageClause(
+ ME, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc);
}
OMPClause *SemaOpenMP::ActOnOpenMPOrderClause(