@@ -11101,15 +11101,19 @@ StmtResult SemaOpenMP::ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses,
1110111101 OMPExecutableDirective::getSingleClause<OMPSeverityClause>(Clauses);
1110211102 const OMPMessageClause *MessageC =
1110311103 OMPExecutableDirective::getSingleClause<OMPMessageClause>(Clauses);
11104- Expr *ME = MessageC ? MessageC->getMessageString() : nullptr;
1110511104
1110611105 if (!AtC || AtC->getAtKind() == OMPC_AT_compilation) {
11106+ StringLiteral *SL = MessageC ? MessageC->getAsStringLiteral() : nullptr;
11107+ if (MessageC && !SL)
11108+ Diag(MessageC->getMessageString()->getBeginLoc(),
11109+ diag::warn_clause_expected_string_literal)
11110+ << getOpenMPClauseNameForDiag(OMPC_message);
1110711111 if (SeverityC && SeverityC->getSeverityKind() == OMPC_SEVERITY_warning)
1110811112 Diag(SeverityC->getSeverityKindKwLoc(), diag::warn_diagnose_if_succeeded)
11109- << (ME ? cast<StringLiteral>(ME) ->getString() : "WARNING");
11113+ << (SL ? SL ->getString() : "WARNING");
1111011114 else
1111111115 Diag(StartLoc, diag::err_diagnose_if_succeeded)
11112- << (ME ? cast<StringLiteral>(ME) ->getString() : "ERROR");
11116+ << (SL ? SL ->getString() : "ERROR");
1111311117 if (!SeverityC || SeverityC->getSeverityKind() != OMPC_SEVERITY_warning)
1111411118 return StmtError();
1111511119 }
@@ -16464,13 +16468,28 @@ OMPClause *SemaOpenMP::ActOnOpenMPMessageClause(Expr *ME,
1646416468 SourceLocation LParenLoc,
1646516469 SourceLocation EndLoc) {
1646616470 assert(ME && "NULL expr in Message clause");
16467- if (!isa<StringLiteral>(ME)) {
16471+ QualType Type = ME->getType();
16472+ if ((!Type->isPointerType() && !Type->isArrayType()) ||
16473+ !Type->getPointeeOrArrayElementType()->isAnyCharacterType()) {
1646816474 Diag(ME->getBeginLoc(), diag::warn_clause_expected_string)
1646916475 << getOpenMPClauseNameForDiag(OMPC_message);
1647016476 return nullptr;
1647116477 }
16478+
16479+ // If the string is a string literal, save it in case it is later needed
16480+ // during compile time. Also consider a const char pointer to a string
16481+ // literal. This is necessary for template instantiations where the string
16482+ // literal is not passed directly and we only get a const char pointer to it.
16483+ StringLiteral *SL = dyn_cast<StringLiteral>(
16484+ isa<ImplicitCastExpr>(ME) ? cast<ImplicitCastExpr>(ME)->getSubExpr()
16485+ : ME);
16486+
16487+ // Convert array type to pointer type if needed.
16488+ if (Type->isArrayType())
16489+ ME = SemaRef.DefaultFunctionArrayConversion(ME).get();
16490+
1647216491 return new (getASTContext())
16473- OMPMessageClause(ME, StartLoc, LParenLoc, EndLoc);
16492+ OMPMessageClause(ME, StartLoc, LParenLoc, EndLoc, SL );
1647416493}
1647516494
1647616495OMPClause *SemaOpenMP::ActOnOpenMPOrderClause(
0 commit comments