Skip to content

Commit a1dfe15

Browse files
authored
[clang][OpenMP] Simplify check for taskloop in `ActOnOpenMPLoopInitia… (#98633)
…lization` Replace the explicit list of compound directives ending with taskloop with checking for the last leaf construct.
1 parent 4ed0f84 commit a1dfe15

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9090,14 +9090,15 @@ void SemaOpenMP::ActOnOpenMPLoopInitialization(SourceLocation ForLoc,
90909090
isOpenMPSimdDirective(DKind)
90919091
? (DSAStack->hasMutipleLoops() ? OMPC_lastprivate : OMPC_linear)
90929092
: OMPC_private;
9093+
auto IsOpenMPTaskloopDirective = [](OpenMPDirectiveKind DK) {
9094+
return getLeafConstructsOrSelf(DK).back() == OMPD_taskloop;
9095+
};
90939096
if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown &&
90949097
DVar.CKind != PredeterminedCKind && DVar.RefExpr &&
90959098
(getLangOpts().OpenMP <= 45 ||
90969099
(DVar.CKind != OMPC_lastprivate && DVar.CKind != OMPC_private))) ||
9097-
((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop ||
9098-
DKind == OMPD_master_taskloop || DKind == OMPD_masked_taskloop ||
9099-
DKind == OMPD_parallel_master_taskloop ||
9100-
DKind == OMPD_parallel_masked_taskloop ||
9100+
((isOpenMPWorksharingDirective(DKind) ||
9101+
IsOpenMPTaskloopDirective(DKind) ||
91019102
isOpenMPDistributeDirective(DKind)) &&
91029103
!isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown &&
91039104
DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) &&
@@ -18600,14 +18601,22 @@ OMPClause *SemaOpenMP::ActOnOpenMPReductionClause(
1860018601
// worksharing-loop construct, a worksharing-loop SIMD construct, a simd
1860118602
// construct, a parallel worksharing-loop construct or a parallel
1860218603
// worksharing-loop SIMD construct.
18603-
if (Modifier == OMPC_REDUCTION_inscan &&
18604-
(DSAStack->getCurrentDirective() != OMPD_for &&
18605-
DSAStack->getCurrentDirective() != OMPD_for_simd &&
18606-
DSAStack->getCurrentDirective() != OMPD_simd &&
18607-
DSAStack->getCurrentDirective() != OMPD_parallel_for &&
18608-
DSAStack->getCurrentDirective() != OMPD_parallel_for_simd)) {
18609-
Diag(ModifierLoc, diag::err_omp_wrong_inscan_reduction);
18610-
return nullptr;
18604+
// [5.2:136:1-4] A reduction clause with the inscan reduction-modifier may
18605+
// only appear on a worksharing-loop construct, a simd construct or a
18606+
// combined or composite construct for which any of the aforementioned
18607+
// constructs is a constituent construct and distribute is not a constituent
18608+
// construct.
18609+
if (Modifier == OMPC_REDUCTION_inscan) {
18610+
SmallVector<OpenMPDirectiveKind, 4> LeafOrComposite;
18611+
ArrayRef<OpenMPDirectiveKind> CurrentLOC = getLeafOrCompositeConstructs(
18612+
DSAStack->getCurrentDirective(), LeafOrComposite);
18613+
bool Valid = llvm::any_of(CurrentLOC, [](OpenMPDirectiveKind DK) {
18614+
return llvm::is_contained({OMPD_for, OMPD_simd, OMPD_for_simd}, DK);
18615+
});
18616+
if (!Valid) {
18617+
Diag(ModifierLoc, diag::err_omp_wrong_inscan_reduction);
18618+
return nullptr;
18619+
}
1861118620
}
1861218621

1861318622
ReductionData RD(VarList.size(), Modifier);

0 commit comments

Comments
 (0)