@@ -9090,14 +9090,15 @@ void SemaOpenMP::ActOnOpenMPLoopInitialization(SourceLocation ForLoc,
9090
9090
isOpenMPSimdDirective(DKind)
9091
9091
? (DSAStack->hasMutipleLoops() ? OMPC_lastprivate : OMPC_linear)
9092
9092
: OMPC_private;
9093
+ auto IsOpenMPTaskloopDirective = [](OpenMPDirectiveKind DK) {
9094
+ return getLeafConstructsOrSelf(DK).back() == OMPD_taskloop;
9095
+ };
9093
9096
if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown &&
9094
9097
DVar.CKind != PredeterminedCKind && DVar.RefExpr &&
9095
9098
(getLangOpts().OpenMP <= 45 ||
9096
9099
(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) ||
9101
9102
isOpenMPDistributeDirective(DKind)) &&
9102
9103
!isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown &&
9103
9104
DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) &&
@@ -18600,14 +18601,22 @@ OMPClause *SemaOpenMP::ActOnOpenMPReductionClause(
18600
18601
// worksharing-loop construct, a worksharing-loop SIMD construct, a simd
18601
18602
// construct, a parallel worksharing-loop construct or a parallel
18602
18603
// 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
+ }
18611
18620
}
18612
18621
18613
18622
ReductionData RD(VarList.size(), Modifier);
0 commit comments