@@ -11082,15 +11082,19 @@ StmtResult SemaOpenMP::ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses,
1108211082      OMPExecutableDirective::getSingleClause<OMPSeverityClause>(Clauses);
1108311083  const OMPMessageClause *MessageC =
1108411084      OMPExecutableDirective::getSingleClause<OMPMessageClause>(Clauses);
11085-   Expr *ME = MessageC ? MessageC->getMessageString() : nullptr;
1108611085
1108711086  if (!AtC || AtC->getAtKind() == OMPC_AT_compilation) {
11087+     StringLiteral *SL = MessageC ? MessageC->getAsStringLiteral() : nullptr;
11088+     if (MessageC && !SL)
11089+       Diag(MessageC->getMessageString()->getBeginLoc(),
11090+            diag::warn_clause_expected_string_literal)
11091+           << getOpenMPClauseNameForDiag(OMPC_message);
1108811092    if (SeverityC && SeverityC->getSeverityKind() == OMPC_SEVERITY_warning)
1108911093      Diag(SeverityC->getSeverityKindKwLoc(), diag::warn_diagnose_if_succeeded)
11090-           << (ME  ? cast<StringLiteral>(ME) ->getString() : "WARNING");
11094+           << (SL  ? SL ->getString() : "WARNING");
1109111095    else
1109211096      Diag(StartLoc, diag::err_diagnose_if_succeeded)
11093-           << (ME  ? cast<StringLiteral>(ME) ->getString() : "ERROR");
11097+           << (SL  ? SL ->getString() : "ERROR");
1109411098    if (!SeverityC || SeverityC->getSeverityKind() != OMPC_SEVERITY_warning)
1109511099      return StmtError();
1109611100  }
@@ -16445,13 +16449,28 @@ OMPClause *SemaOpenMP::ActOnOpenMPMessageClause(Expr *ME,
1644516449                                                SourceLocation LParenLoc,
1644616450                                                SourceLocation EndLoc) {
1644716451  assert(ME && "NULL expr in Message clause");
16448-   if (!isa<StringLiteral>(ME)) {
16452+   QualType Type = ME->getType();
16453+   if ((!Type->isPointerType() && !Type->isArrayType()) ||
16454+       !Type->getPointeeOrArrayElementType()->isAnyCharacterType()) {
1644916455    Diag(ME->getBeginLoc(), diag::warn_clause_expected_string)
1645016456        << getOpenMPClauseNameForDiag(OMPC_message);
1645116457    return nullptr;
1645216458  }
16459+ 
16460+   // If the string is a string literal, save it in case it is later needed
16461+   // during compile time.  Also consider a const char pointer to a string
16462+   // literal. This is necessary for template instantiations where the string
16463+   // literal is not passed directly and we only get a const char pointer to it.
16464+   StringLiteral *SL = dyn_cast<StringLiteral>(
16465+       isa<ImplicitCastExpr>(ME) ? cast<ImplicitCastExpr>(ME)->getSubExpr()
16466+                                 : ME);
16467+ 
16468+   // Convert array type to pointer type if needed.
16469+   if (Type->isArrayType())
16470+     ME = SemaRef.DefaultFunctionArrayConversion(ME).get();
16471+ 
1645316472  return new (getASTContext())
16454-       OMPMessageClause(ME, StartLoc, LParenLoc, EndLoc);
16473+       OMPMessageClause(ME, StartLoc, LParenLoc, EndLoc, SL );
1645516474}
1645616475
1645716476OMPClause *SemaOpenMP::ActOnOpenMPOrderClause(
0 commit comments