Skip to content

Commit 0ce801f

Browse files
authored
[clang][OpenMP] Implement isOpenMPExecutableDirective (#97089)
What is considered "executable" in clang differs slightly from the OpenMP's "executable" category. In addition to the executable category, subsidiary directives, and OMPD_error are considered executable. Implement a function that performs that check.
1 parent 101a936 commit 0ce801f

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

clang/include/clang/Basic/OpenMPKinds.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,14 @@ bool needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind);
368368
/// is restricted only to memory order clauses of "OMPC_acquire",
369369
/// "OMPC_relaxed" and "OMPC_seq_cst".
370370
bool checkFailClauseParameter(OpenMPClauseKind FailClauseParameter);
371+
372+
/// Checks if the specified directive is considered as "executable". This
373+
/// combines the OpenMP categories of "executable" and "subsidiary", plus
374+
/// any other directives that should be treated as executable.
375+
/// \param DKind Specified directive.
376+
/// \return true - if the above condition is met for this directive
377+
/// otherwise - false.
378+
bool isOpenMPExecutableDirective(OpenMPDirectiveKind DKind);
371379
}
372380

373381
#endif

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,13 @@ bool clang::needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind) {
702702
DKind == OMPD_target_parallel_loop;
703703
}
704704

705+
bool clang::isOpenMPExecutableDirective(OpenMPDirectiveKind DKind) {
706+
if (DKind == OMPD_error)
707+
return true;
708+
Category Cat = getDirectiveCategory(DKind);
709+
return Cat == Category::Executable || Cat == Category::Subsidiary;
710+
}
711+
705712
void clang::getOpenMPCaptureRegions(
706713
SmallVectorImpl<OpenMPDirectiveKind> &CaptureRegions,
707714
OpenMPDirectiveKind DKind) {

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,10 +2397,8 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
23972397
StmtResult Parser::ParseOpenMPExecutableDirective(
23982398
ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
23992399
bool ReadDirectiveWithinMetadirective) {
2400-
assert((DKind == OMPD_error ||
2401-
getDirectiveCategory(DKind) == Category::Executable ||
2402-
getDirectiveCategory(DKind) == Category::Subsidiary) &&
2403-
"Directive with an unexpected category");
2400+
assert(isOpenMPExecutableDirective(DKind) && "Unexpected directive category");
2401+
24042402
bool HasAssociatedStatement = true;
24052403
Association Assoc = getDirectiveAssociation(DKind);
24062404

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6357,6 +6357,8 @@ StmtResult SemaOpenMP::ActOnOpenMPExecutableDirective(
63576357
OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
63586358
Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc,
63596359
OpenMPDirectiveKind PrevMappedDirective) {
6360+
assert(isOpenMPExecutableDirective(Kind) && "Unexpected directive category");
6361+
63606362
StmtResult Res = StmtError();
63616363
OpenMPBindClauseKind BindKind = OMPC_BIND_unknown;
63626364
llvm::SmallVector<OMPClause *> ClausesWithoutBind;

0 commit comments

Comments
 (0)