Skip to content

Commit a58af26

Browse files
committed
implement feedback
1 parent 4859f0d commit a58af26

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
@@ -11097,26 +11097,27 @@ StmtResult SemaOpenMP::ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses,
1109711097
return StmtError();
1109811098
}
1109911099

11100-
const OMPSeverityClause *SeverityC =
11101-
OMPExecutableDirective::getSingleClause<OMPSeverityClause>(Clauses);
11102-
const OMPMessageClause *MessageC =
11103-
OMPExecutableDirective::getSingleClause<OMPMessageClause>(Clauses);
11104-
1110511100
if (!AtC || AtC->getAtKind() == OMPC_AT_compilation) {
11106-
StringLiteral *SL = MessageC ? MessageC->getAsStringLiteral() : nullptr;
11101+
const OMPSeverityClause *SeverityC =
11102+
OMPExecutableDirective::getSingleClause<OMPSeverityClause>(Clauses);
11103+
const OMPMessageClause *MessageC =
11104+
OMPExecutableDirective::getSingleClause<OMPMessageClause>(Clauses);
11105+
std::optional<std::string> SL =
11106+
MessageC ? MessageC->tryEvaluateString(getASTContext()) : std::nullopt;
11107+
1110711108
if (MessageC && !SL)
1110811109
Diag(MessageC->getMessageString()->getBeginLoc(),
1110911110
diag::warn_clause_expected_string_literal)
1111011111
<< getOpenMPClauseNameForDiag(OMPC_message);
1111111112
if (SeverityC && SeverityC->getSeverityKind() == OMPC_SEVERITY_warning)
1111211113
Diag(SeverityC->getSeverityKindKwLoc(), diag::warn_diagnose_if_succeeded)
11113-
<< (SL ? SL->getString() : "WARNING");
11114+
<< SL.value_or("WARNING");
1111411115
else
11115-
Diag(StartLoc, diag::err_diagnose_if_succeeded)
11116-
<< (SL ? SL->getString() : "ERROR");
11116+
Diag(StartLoc, diag::err_diagnose_if_succeeded) << SL.value_or("ERROR");
1111711117
if (!SeverityC || SeverityC->getSeverityKind() != OMPC_SEVERITY_warning)
1111811118
return StmtError();
1111911119
}
11120+
1112011121
return OMPErrorDirective::Create(getASTContext(), StartLoc, EndLoc, Clauses);
1112111122
}
1112211123

@@ -16476,20 +16477,12 @@ OMPClause *SemaOpenMP::ActOnOpenMPMessageClause(Expr *ME,
1647616477
return nullptr;
1647716478
}
1647816479

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-
1648716480
// Convert array type to pointer type if needed.
1648816481
if (Type->isArrayType())
1648916482
ME = SemaRef.DefaultFunctionArrayConversion(ME).get();
1649016483

1649116484
return new (getASTContext())
16492-
OMPMessageClause(ME, StartLoc, LParenLoc, EndLoc, SL);
16485+
OMPMessageClause(ME, StartLoc, LParenLoc, EndLoc);
1649316486
}
1649416487

1649516488
OMPClause *SemaOpenMP::ActOnOpenMPOrderClause(

0 commit comments

Comments
 (0)