diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -10121,14 +10121,14 @@ DSAStack->getTaskgroupReductionRef(), DSAStack->isCancelRegion()); } -/// detach and mergeable clauses are mutially exclusive, check for it. -static bool checkDetachMergeableClauses(Sema &S, - ArrayRef Clauses) { +/// Find and diagnose mutually exclusive clause kinds. +static bool checkMutuallyExclusiveClauses( + Sema &S, ArrayRef Clauses, + ArrayRef MutuallyExclusiveClauses) { const OMPClause *PrevClause = nullptr; bool ErrorFound = false; for (const OMPClause *C : Clauses) { - if (C->getClauseKind() == OMPC_detach || - C->getClauseKind() == OMPC_mergeable) { + if (llvm::is_contained(MutuallyExclusiveClauses, C->getClauseKind())) { if (!PrevClause) { PrevClause = C; } else if (PrevClause->getClauseKind() != C->getClauseKind()) { @@ -10153,7 +10153,8 @@ // OpenMP 5.0, 2.10.1 task Construct // If a detach clause appears on the directive, then a mergeable clause cannot // appear on the same directive. - if (checkDetachMergeableClauses(*this, Clauses)) + if (checkMutuallyExclusiveClauses(*this, Clauses, + {OMPC_detach, OMPC_mergeable})) return StmtError(); auto *CS = cast(AStmt); @@ -11457,28 +11458,6 @@ CancelRegion); } -static bool checkGrainsizeNumTasksClauses(Sema &S, - ArrayRef Clauses) { - const OMPClause *PrevClause = nullptr; - bool ErrorFound = false; - for (const OMPClause *C : Clauses) { - if (C->getClauseKind() == OMPC_grainsize || - C->getClauseKind() == OMPC_num_tasks) { - if (!PrevClause) - PrevClause = C; - else if (PrevClause->getClauseKind() != C->getClauseKind()) { - S.Diag(C->getBeginLoc(), diag::err_omp_clauses_mutually_exclusive) - << getOpenMPClauseName(C->getClauseKind()) - << getOpenMPClauseName(PrevClause->getClauseKind()); - S.Diag(PrevClause->getBeginLoc(), diag::note_omp_previous_clause) - << getOpenMPClauseName(PrevClause->getClauseKind()); - ErrorFound = true; - } - } - } - return ErrorFound; -} - static bool checkReductionClauseWithNogroup(Sema &S, ArrayRef Clauses) { const OMPClause *ReductionClause = nullptr; @@ -11529,7 +11508,8 @@ // OpenMP, [2.9.2 taskloop Construct, Restrictions] // The grainsize clause and num_tasks clause are mutually exclusive and may // not appear on the same taskloop directive. - if (checkGrainsizeNumTasksClauses(*this, Clauses)) + if (checkMutuallyExclusiveClauses(*this, Clauses, + {OMPC_grainsize, OMPC_num_tasks})) return StmtError(); // OpenMP, [2.9.2 taskloop Construct, Restrictions] // If a reduction clause is present on the taskloop directive, the nogroup @@ -11577,7 +11557,8 @@ // OpenMP, [2.9.2 taskloop Construct, Restrictions] // The grainsize clause and num_tasks clause are mutually exclusive and may // not appear on the same taskloop directive. - if (checkGrainsizeNumTasksClauses(*this, Clauses)) + if (checkMutuallyExclusiveClauses(*this, Clauses, + {OMPC_grainsize, OMPC_num_tasks})) return StmtError(); // OpenMP, [2.9.2 taskloop Construct, Restrictions] // If a reduction clause is present on the taskloop directive, the nogroup @@ -11615,7 +11596,8 @@ // OpenMP, [2.9.2 taskloop Construct, Restrictions] // The grainsize clause and num_tasks clause are mutually exclusive and may // not appear on the same taskloop directive. - if (checkGrainsizeNumTasksClauses(*this, Clauses)) + if (checkMutuallyExclusiveClauses(*this, Clauses, + {OMPC_grainsize, OMPC_num_tasks})) return StmtError(); // OpenMP, [2.9.2 taskloop Construct, Restrictions] // If a reduction clause is present on the taskloop directive, the nogroup @@ -11663,7 +11645,8 @@ // OpenMP, [2.9.2 taskloop Construct, Restrictions] // The grainsize clause and num_tasks clause are mutually exclusive and may // not appear on the same taskloop directive. - if (checkGrainsizeNumTasksClauses(*this, Clauses)) + if (checkMutuallyExclusiveClauses(*this, Clauses, + {OMPC_grainsize, OMPC_num_tasks})) return StmtError(); // OpenMP, [2.9.2 taskloop Construct, Restrictions] // If a reduction clause is present on the taskloop directive, the nogroup @@ -11720,7 +11703,8 @@ // OpenMP, [2.9.2 taskloop Construct, Restrictions] // The grainsize clause and num_tasks clause are mutually exclusive and may // not appear on the same taskloop directive. - if (checkGrainsizeNumTasksClauses(*this, Clauses)) + if (checkMutuallyExclusiveClauses(*this, Clauses, + {OMPC_grainsize, OMPC_num_tasks})) return StmtError(); // OpenMP, [2.9.2 taskloop Construct, Restrictions] // If a reduction clause is present on the taskloop directive, the nogroup @@ -11787,7 +11771,8 @@ // OpenMP, [2.9.2 taskloop Construct, Restrictions] // The grainsize clause and num_tasks clause are mutually exclusive and may // not appear on the same taskloop directive. - if (checkGrainsizeNumTasksClauses(*this, Clauses)) + if (checkMutuallyExclusiveClauses(*this, Clauses, + {OMPC_grainsize, OMPC_num_tasks})) return StmtError(); // OpenMP, [2.9.2 taskloop Construct, Restrictions] // If a reduction clause is present on the taskloop directive, the nogroup