Skip to content

Commit 9d90cf2

Browse files
committed
[OPENMP5.1] Initial support for message clause.
1 parent 96c037e commit 9d90cf2

File tree

17 files changed

+199
-19
lines changed

17 files changed

+199
-19
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,72 @@ class OMPSeverityClause final : public OMPClause {
17221722
}
17231723
};
17241724

1725+
/// This represents 'message' clause in the '#pragma omp error' directive
1726+
///
1727+
/// \code
1728+
/// #pragma omp error message("GNU compiler required.")
1729+
/// \endcode
1730+
/// In this example directive '#pragma omp error' has simple
1731+
/// 'message' clause with user error message of "GNU compiler required.".
1732+
class OMPMessageClause final : public OMPClause {
1733+
friend class OMPClauseReader;
1734+
1735+
/// Location of '('
1736+
SourceLocation LParenLoc;
1737+
1738+
// Expression of the 'message' clause.
1739+
Stmt *MessageString = nullptr;
1740+
1741+
/// Set message string of the clause.
1742+
void setMessageString(Expr *MS) { MessageString = MS; }
1743+
1744+
/// Sets the location of '('.
1745+
void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1746+
1747+
public:
1748+
/// Build 'message' clause with message string argument
1749+
///
1750+
/// \param A Argument of the clause (message string).
1751+
/// \param StartLoc Starting location of the clause.
1752+
/// \param LParenLoc Location of '('.
1753+
/// \param EndLoc Ending location of the clause.
1754+
OMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc,
1755+
SourceLocation EndLoc)
1756+
: OMPClause(llvm::omp::OMPC_message, StartLoc, EndLoc),
1757+
LParenLoc(LParenLoc), MessageString(MS) {}
1758+
1759+
/// Build an empty clause.
1760+
OMPMessageClause()
1761+
: OMPClause(llvm::omp::OMPC_message, SourceLocation(), SourceLocation()) {
1762+
}
1763+
1764+
/// Returns the locaiton of '('.
1765+
SourceLocation getLParenLoc() const { return LParenLoc; }
1766+
1767+
/// Returns message string of the clause.
1768+
Expr *getMessageString() const { return cast_or_null<Expr>(MessageString); }
1769+
1770+
child_range children() {
1771+
return child_range(&MessageString, &MessageString + 1);
1772+
}
1773+
1774+
const_child_range children() const {
1775+
return const_child_range(&MessageString, &MessageString + 1);
1776+
}
1777+
1778+
child_range used_children() {
1779+
return child_range(child_iterator(), child_iterator());
1780+
}
1781+
1782+
const_child_range used_children() const {
1783+
return const_child_range(const_child_iterator(), const_child_iterator());
1784+
}
1785+
1786+
static bool classof(const OMPClause *T) {
1787+
return T->getClauseKind() == llvm::omp::OMPC_message;
1788+
}
1789+
};
1790+
17251791
/// This represents 'schedule' clause in the '#pragma omp ...' directive.
17261792
///
17271793
/// \code

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,6 +3320,12 @@ bool RecursiveASTVisitor<Derived>::VisitOMPSeverityClause(OMPSeverityClause *) {
33203320
return true;
33213321
}
33223322

3323+
template <typename Derived>
3324+
bool RecursiveASTVisitor<Derived>::VisitOMPMessageClause(OMPMessageClause *C) {
3325+
TRY_TO(TraverseStmt(C->getMessageString()));
3326+
return true;
3327+
}
3328+
33233329
template <typename Derived>
33243330
bool
33253331
RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,8 @@ def err_omp_unexpected_directive : Error<
13421342
"unexpected OpenMP directive %select{|'#pragma omp %1'}0">;
13431343
def err_omp_expected_punc : Error<
13441344
"expected ',' or ')' in '%0' %select{clause|directive}1">;
1345+
def warn_clause_expected_string : Warning<
1346+
"expected string literal in 'clause %0' - ignoring">, InGroup<IgnoredPragmas>;
13451347
def err_omp_unexpected_clause : Error<
13461348
"unexpected OpenMP clause '%0' in directive '#pragma omp %1'">;
13471349
def err_omp_immediate_directive : Error<

clang/include/clang/Sema/Sema.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11862,6 +11862,12 @@ class Sema final {
1186211862
SourceLocation LParenLoc,
1186311863
SourceLocation EndLoc);
1186411864

11865+
/// Called on well-formed 'message' clause.
11866+
/// passing string for message.
11867+
OMPClause *ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc,
11868+
SourceLocation LParenLoc,
11869+
SourceLocation EndLoc);
11870+
1186511871
/// Data used for processing a list of variables in OpenMP clauses.
1186611872
struct OpenMPVarListDataTy final {
1186711873
Expr *DepModOrTailExpr = nullptr;

clang/lib/AST/OpenMPClause.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
154154
case OMPC_atomic_default_mem_order:
155155
case OMPC_at:
156156
case OMPC_severity:
157+
case OMPC_message:
157158
case OMPC_device_type:
158159
case OMPC_match:
159160
case OMPC_nontemporal:
@@ -255,6 +256,7 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C)
255256
case OMPC_atomic_default_mem_order:
256257
case OMPC_at:
257258
case OMPC_severity:
259+
case OMPC_message:
258260
case OMPC_device_type:
259261
case OMPC_match:
260262
case OMPC_nontemporal:
@@ -1796,6 +1798,11 @@ void OMPClausePrinter::VisitOMPSeverityClause(OMPSeverityClause *Node) {
17961798
<< ")";
17971799
}
17981800

1801+
void OMPClausePrinter::VisitOMPMessageClause(OMPMessageClause *Node) {
1802+
OS << "message(\""
1803+
<< cast<StringLiteral>(Node->getMessageString())->getString() << "\")";
1804+
}
1805+
17991806
void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
18001807
OS << "schedule(";
18011808
if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {

clang/lib/AST/StmtProfile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,11 @@ void OMPClauseProfiler::VisitOMPAtClause(const OMPAtClause *C) {}
534534

535535
void OMPClauseProfiler::VisitOMPSeverityClause(const OMPSeverityClause *C) {}
536536

537+
void OMPClauseProfiler::VisitOMPMessageClause(const OMPMessageClause *C) {
538+
if (C->getMessageString())
539+
Profiler->VisitStmt(C->getMessageString());
540+
}
541+
537542
void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
538543
VistOMPClauseWithPreInit(C);
539544
if (auto *S = C->getChunkSize())

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6514,6 +6514,7 @@ static void emitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind,
65146514
case OMPC_atomic_default_mem_order:
65156515
case OMPC_at:
65166516
case OMPC_severity:
6517+
case OMPC_message:
65176518
case OMPC_device_type:
65186519
case OMPC_match:
65196520
case OMPC_nontemporal:

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,6 +3192,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
31923192
case OMPC_filter:
31933193
case OMPC_partial:
31943194
case OMPC_align:
3195+
case OMPC_message:
31953196
// OpenMP [2.5, Restrictions]
31963197
// At most one num_threads clause can appear on the directive.
31973198
// OpenMP [2.8.1, simd construct, Restrictions]
@@ -3217,6 +3218,8 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
32173218
// OpenMP 5.1, 2.3.6 dispatch Construct, Restrictions.
32183219
// At most one novariants clause can appear on a dispatch directive.
32193220
// At most one nocontext clause can appear on a dispatch directive.
3221+
// OpenMP [5.1, error directive, Restrictions]
3222+
// At most one message clause can appear on the directive
32203223
if (!FirstClause) {
32213224
Diag(Tok, diag::err_omp_more_one_clause)
32223225
<< getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6721,6 +6721,7 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
67216721
case OMPC_when:
67226722
case OMPC_at:
67236723
case OMPC_severity:
6724+
case OMPC_message:
67246725
default:
67256726
llvm_unreachable("Unexpected clause");
67266727
}
@@ -11032,25 +11033,27 @@ StmtResult Sema::ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses,
1103211033
SourceLocation StartLoc,
1103311034
SourceLocation EndLoc,
1103411035
bool InExContext) {
11035-
auto AtClauses =
11036-
OMPExecutableDirective::getClausesOfKind<OMPAtClause>(Clauses);
11037-
const OMPAtClause *AtC = AtClauses.empty() ? nullptr : (*AtClauses.begin());
11036+
const OMPAtClause *AtC =
11037+
OMPExecutableDirective::getSingleClause<OMPAtClause>(Clauses);
1103811038

1103911039
if (AtC && !InExContext && AtC->getAtKind() == OMPC_AT_execution) {
1104011040
Diag(AtC->getAtKindKwLoc(), diag::err_omp_unexpected_execution_modifier);
1104111041
return StmtError();
1104211042
}
11043-
auto SeverityClauses =
11044-
OMPExecutableDirective::getClausesOfKind<OMPSeverityClause>(Clauses);
11043+
1104511044
const OMPSeverityClause *SeverityC =
11046-
SeverityClauses.empty() ? nullptr : (*SeverityClauses.begin());
11045+
OMPExecutableDirective::getSingleClause<OMPSeverityClause>(Clauses);
11046+
const OMPMessageClause *MessageC =
11047+
OMPExecutableDirective::getSingleClause<OMPMessageClause>(Clauses);
11048+
Expr *ME = MessageC ? MessageC->getMessageString() : nullptr;
1104711049

1104811050
if (!AtC || AtC->getAtKind() == OMPC_AT_compilation) {
1104911051
if (SeverityC && SeverityC->getSeverityKind() == OMPC_SEVERITY_warning)
1105011052
Diag(SeverityC->getSeverityKindKwLoc(), diag::warn_diagnose_if_succeeded)
11051-
<< "WARNING";
11053+
<< (ME ? cast<StringLiteral>(ME)->getString() : "WARNING");
1105211054
else
11053-
Diag(StartLoc, diag::err_diagnose_if_succeeded) << "ERROR";
11055+
Diag(StartLoc, diag::err_diagnose_if_succeeded)
11056+
<< (ME ? cast<StringLiteral>(ME)->getString() : "ERROR");
1105411057
if (!SeverityC || SeverityC->getSeverityKind() != OMPC_SEVERITY_warning)
1105511058
return StmtError();
1105611059
}
@@ -15131,6 +15134,9 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
1513115134
case OMPC_partial:
1513215135
Res = ActOnOpenMPPartialClause(Expr, StartLoc, LParenLoc, EndLoc);
1513315136
break;
15137+
case OMPC_message:
15138+
Res = ActOnOpenMPMessageClause(Expr, StartLoc, LParenLoc, EndLoc);
15139+
break;
1513415140
case OMPC_align:
1513515141
Res = ActOnOpenMPAlignClause(Expr, StartLoc, LParenLoc, EndLoc);
1513615142
break;
@@ -16121,6 +16127,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
1612116127
case OMPC_order:
1612216128
case OMPC_at:
1612316129
case OMPC_severity:
16130+
case OMPC_message:
1612416131
case OMPC_destroy:
1612516132
case OMPC_detach:
1612616133
case OMPC_inclusive:
@@ -16607,6 +16614,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause(
1660716614
case OMPC_uses_allocators:
1660816615
case OMPC_affinity:
1660916616
case OMPC_when:
16617+
case OMPC_message:
1661016618
default:
1661116619
llvm_unreachable("Clause is not allowed.");
1661216620
}
@@ -16742,6 +16750,18 @@ OMPClause *Sema::ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind,
1674216750
OMPSeverityClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1674316751
}
1674416752

16753+
OMPClause *Sema::ActOnOpenMPMessageClause(Expr *ME, SourceLocation StartLoc,
16754+
SourceLocation LParenLoc,
16755+
SourceLocation EndLoc) {
16756+
assert(ME && "NULL expr in Message clause");
16757+
if (!isa<StringLiteral>(ME)) {
16758+
Diag(ME->getBeginLoc(), diag::warn_clause_expected_string)
16759+
<< getOpenMPClauseName(OMPC_message);
16760+
return nullptr;
16761+
}
16762+
return new (Context) OMPMessageClause(ME, StartLoc, LParenLoc, EndLoc);
16763+
}
16764+
1674516765
OMPClause *Sema::ActOnOpenMPOrderClause(OpenMPOrderClauseKind Kind,
1674616766
SourceLocation KindKwLoc,
1674716767
SourceLocation StartLoc,
@@ -16955,6 +16975,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause(
1695516975
case OMPC_order:
1695616976
case OMPC_at:
1695716977
case OMPC_severity:
16978+
case OMPC_message:
1695816979
case OMPC_destroy:
1695916980
case OMPC_novariants:
1696016981
case OMPC_nocontext:
@@ -17213,6 +17234,7 @@ OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind,
1721317234
case OMPC_order:
1721417235
case OMPC_at:
1721517236
case OMPC_severity:
17237+
case OMPC_message:
1721617238
case OMPC_novariants:
1721717239
case OMPC_nocontext:
1721817240
case OMPC_detach:
@@ -17769,6 +17791,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause(OpenMPClauseKind Kind,
1776917791
case OMPC_order:
1777017792
case OMPC_at:
1777117793
case OMPC_severity:
17794+
case OMPC_message:
1777217795
case OMPC_destroy:
1777317796
case OMPC_novariants:
1777417797
case OMPC_nocontext:

clang/lib/Sema/TreeTransform.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,16 @@ class TreeTransform {
23802380
EndLoc);
23812381
}
23822382

2383+
/// Build a new OpenMP 'message' clause.
2384+
///
2385+
/// By default, performs semantic analysis to build the new OpenMP clause.
2386+
/// Subclasses may override this routine to provide different behavior.
2387+
OMPClause *RebuildOMPMessageClause(Expr *MS, SourceLocation StartLoc,
2388+
SourceLocation LParenLoc,
2389+
SourceLocation EndLoc) {
2390+
return getSema().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc, EndLoc);
2391+
}
2392+
23832393
/// Rebuild the operand to an Objective-C \@synchronized statement.
23842394
///
23852395
/// By default, performs semantic analysis to build the new statement.
@@ -9899,6 +9909,17 @@ TreeTransform<Derived>::TransformOMPSeverityClause(OMPSeverityClause *C) {
98999909
C->getLParenLoc(), C->getEndLoc());
99009910
}
99019911

9912+
template <typename Derived>
9913+
OMPClause *
9914+
TreeTransform<Derived>::TransformOMPMessageClause(OMPMessageClause *C) {
9915+
ExprResult E = getDerived().TransformExpr(C->getMessageString());
9916+
if (E.isInvalid())
9917+
return nullptr;
9918+
return getDerived().RebuildOMPMessageClause(
9919+
C->getMessageString(), C->getBeginLoc(), C->getLParenLoc(),
9920+
C->getEndLoc());
9921+
}
9922+
99029923
template <typename Derived>
99039924
OMPClause *
99049925
TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {

clang/lib/Serialization/ASTReader.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9955,6 +9955,9 @@ OMPClause *OMPClauseReader::readClause() {
99559955
case llvm::omp::OMPC_severity:
99569956
C = new (Context) OMPSeverityClause();
99579957
break;
9958+
case llvm::omp::OMPC_message:
9959+
C = new (Context) OMPMessageClause();
9960+
break;
99589961
case llvm::omp::OMPC_private:
99599962
C = OMPPrivateClause::CreateEmpty(Context, Record.readInt());
99609963
break;
@@ -10369,6 +10372,11 @@ void OMPClauseReader::VisitOMPSeverityClause(OMPSeverityClause *C) {
1036910372
C->setSeverityKindKwLoc(Record.readSourceLocation());
1037010373
}
1037110374

10375+
void OMPClauseReader::VisitOMPMessageClause(OMPMessageClause *C) {
10376+
C->setMessageString(Record.readSubExpr());
10377+
C->setLParenLoc(Record.readSourceLocation());
10378+
}
10379+
1037210380
void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) {
1037310381
C->setLParenLoc(Record.readSourceLocation());
1037410382
unsigned NumVars = C->varlist_size();

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7000,6 +7000,11 @@ void OMPClauseWriter::VisitOMPSeverityClause(OMPSeverityClause *C) {
70007000
Record.AddSourceLocation(C->getSeverityKindKwLoc());
70017001
}
70027002

7003+
void OMPClauseWriter::VisitOMPMessageClause(OMPMessageClause *C) {
7004+
Record.AddStmt(C->getMessageString());
7005+
Record.AddSourceLocation(C->getLParenLoc());
7006+
}
7007+
70037008
void OMPClauseWriter::VisitOMPNontemporalClause(OMPNontemporalClause *C) {
70047009
Record.push_back(C->varlist_size());
70057010
Record.AddSourceLocation(C->getLParenLoc());

0 commit comments

Comments
 (0)