Skip to content

Commit ee91aeb

Browse files
committed
implement feedback
1 parent d039caa commit ee91aeb

File tree

3 files changed

+20
-32
lines changed

3 files changed

+20
-32
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,10 +1874,6 @@ class OMPMessageClause final : public OMPClause {
18741874
// Expression of the 'message' clause.
18751875
Stmt *MessageString = nullptr;
18761876

1877-
// The message as a StringLiteral in case it is as string literal. This might
1878-
// be needed during compile time.
1879-
StringLiteral *MessageStringLiteral = nullptr;
1880-
18811877
/// Set message string of the clause.
18821878
void setMessageString(Expr *MS) { MessageString = MS; }
18831879

@@ -1891,14 +1887,10 @@ class OMPMessageClause final : public OMPClause {
18911887
/// \param StartLoc Starting location of the clause.
18921888
/// \param LParenLoc Location of '('.
18931889
/// \param EndLoc Ending location of the clause.
1894-
/// \param MessageStringLiteral The message as a StringLiteral in case it is
1895-
/// as string literal. This might be needed during compile time.
18961890
OMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc,
1897-
SourceLocation EndLoc,
1898-
StringLiteral *MessageStringLiteral = nullptr)
1891+
SourceLocation EndLoc)
18991892
: OMPClause(llvm::omp::OMPC_message, StartLoc, EndLoc),
1900-
LParenLoc(LParenLoc), MessageString(MS),
1901-
MessageStringLiteral(MessageStringLiteral) {}
1893+
LParenLoc(LParenLoc), MessageString(MS) {}
19021894

19031895
/// Build an empty clause.
19041896
OMPMessageClause()
@@ -1911,9 +1903,12 @@ class OMPMessageClause final : public OMPClause {
19111903
/// Returns message string of the clause.
19121904
Expr *getMessageString() const { return cast_or_null<Expr>(MessageString); }
19131905

1914-
// Returns the source message as a string literal in case it has been a string
1915-
// literal. Otherwise, return null.
1916-
StringLiteral *getAsStringLiteral() const { return MessageStringLiteral; }
1906+
/// Try to evaluate the message string at compile time.
1907+
std::optional<std::string> tryEvaluateString(ASTContext &Ctx) const {
1908+
if (Expr *MessageExpr = getMessageString())
1909+
return MessageExpr->tryEvaluateString(Ctx);
1910+
return std::nullopt;
1911+
}
19171912

19181913
child_range children() {
19191914
return child_range(&MessageString, &MessageString + 1);

clang/lib/AST/OpenMPClause.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,7 @@ void OMPClausePrinter::VisitOMPSeverityClause(OMPSeverityClause *Node) {
19641964

19651965
void OMPClausePrinter::VisitOMPMessageClause(OMPMessageClause *Node) {
19661966
OS << "message(";
1967-
if (StringLiteral *SL = Node->getAsStringLiteral())
1967+
if (StringLiteral *SL = dyn_cast<StringLiteral>(Node->getMessageString()))
19681968
OS << "\"" << SL->getString() << "\"";
19691969
else if (Expr *E = Node->getMessageString())
19701970
E->printPretty(OS, nullptr, Policy);

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11078,26 +11078,27 @@ StmtResult SemaOpenMP::ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses,
1107811078
return StmtError();
1107911079
}
1108011080

11081-
const OMPSeverityClause *SeverityC =
11082-
OMPExecutableDirective::getSingleClause<OMPSeverityClause>(Clauses);
11083-
const OMPMessageClause *MessageC =
11084-
OMPExecutableDirective::getSingleClause<OMPMessageClause>(Clauses);
11085-
1108611081
if (!AtC || AtC->getAtKind() == OMPC_AT_compilation) {
11087-
StringLiteral *SL = MessageC ? MessageC->getAsStringLiteral() : nullptr;
11082+
const OMPSeverityClause *SeverityC =
11083+
OMPExecutableDirective::getSingleClause<OMPSeverityClause>(Clauses);
11084+
const OMPMessageClause *MessageC =
11085+
OMPExecutableDirective::getSingleClause<OMPMessageClause>(Clauses);
11086+
std::optional<std::string> SL =
11087+
MessageC ? MessageC->tryEvaluateString(getASTContext()) : std::nullopt;
11088+
1108811089
if (MessageC && !SL)
1108911090
Diag(MessageC->getMessageString()->getBeginLoc(),
1109011091
diag::warn_clause_expected_string_literal)
1109111092
<< getOpenMPClauseNameForDiag(OMPC_message);
1109211093
if (SeverityC && SeverityC->getSeverityKind() == OMPC_SEVERITY_warning)
1109311094
Diag(SeverityC->getSeverityKindKwLoc(), diag::warn_diagnose_if_succeeded)
11094-
<< (SL ? SL->getString() : "WARNING");
11095+
<< SL.value_or("WARNING");
1109511096
else
11096-
Diag(StartLoc, diag::err_diagnose_if_succeeded)
11097-
<< (SL ? SL->getString() : "ERROR");
11097+
Diag(StartLoc, diag::err_diagnose_if_succeeded) << SL.value_or("ERROR");
1109811098
if (!SeverityC || SeverityC->getSeverityKind() != OMPC_SEVERITY_warning)
1109911099
return StmtError();
1110011100
}
11101+
1110111102
return OMPErrorDirective::Create(getASTContext(), StartLoc, EndLoc, Clauses);
1110211103
}
1110311104

@@ -16457,20 +16458,12 @@ OMPClause *SemaOpenMP::ActOnOpenMPMessageClause(Expr *ME,
1645716458
return nullptr;
1645816459
}
1645916460

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-
1646816461
// Convert array type to pointer type if needed.
1646916462
if (Type->isArrayType())
1647016463
ME = SemaRef.DefaultFunctionArrayConversion(ME).get();
1647116464

1647216465
return new (getASTContext())
16473-
OMPMessageClause(ME, StartLoc, LParenLoc, EndLoc, SL);
16466+
OMPMessageClause(ME, StartLoc, LParenLoc, EndLoc);
1647416467
}
1647516468

1647616469
OMPClause *SemaOpenMP::ActOnOpenMPOrderClause(

0 commit comments

Comments
 (0)