[flang-commits] [flang] [llvm] [flang][OpenMP] Track reachable metadirective replacements (PR #219014)
via flang-commits
flang-commits at lists.llvm.org
Wed Sep 9 19:47:40 PDT 2026
================
@@ -269,17 +270,19 @@ isVariantApplicableInContextHelper(const VariantMatchInfo &VMI,
TraitSet::construct &&
"Variant context is ill-formed!");
- // Verify the nesting.
+ // Verify the nesting. A failed match in match_any or match_none must not
+ // consume the remaining context, since a later selector property can
+ // still match.
+ unsigned SearchStart = ConstructIdx;
bool FoundInOrder = false;
while (!FoundInOrder && ConstructIdx != NoConstructTraits)
FoundInOrder = (Ctx.ConstructTraits[ConstructIdx++] == Property);
- if (ConstructMatches)
+ if (!FoundInOrder && MK != MK_ALL)
+ ConstructIdx = SearchStart;
+ if (ConstructMatches && FoundInOrder)
----------------
MattPD wrote:
Could construct scoring use the highest-valued ordered match before these scores determine semantic reachability? [OpenMP 5.2, section 7.3](https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5-2.pdf) requires that choice for repeated construct traits. In the reproducer, the inner PARALLEL gives the construct candidate score 3, which beats NOTHING's score 2. The greedy scan records the outer occurrence instead and leaves a tie.
Save this as `repro.f90` and run `flang -fc1 -fopenmp -fopenmp-version=52 -fsyntax-only repro.f90`. Revision `7f525837ea63` accepts it, while [the base revision](https://github.com/llvm/llvm-project/commit/89082772bed1ed16c0311b12147a96c35bb063d8) reports the COLLAPSE depth error. With only the outer PARALLEL region changed to TEAMS, both revisions report the error.
```fortran
subroutine repeated_parallel(n)
integer :: n, i
!$omp parallel
!$omp parallel
!$omp metadirective &
!$omp& when(user={condition(score(1): .true.)}: nothing) &
!$omp& when(construct={parallel}: simd collapse(2)) otherwise(nothing)
do i = 1, n
end do
!$omp end parallel
!$omp end parallel
end subroutine
```
https://github.com/llvm/llvm-project/pull/219014
More information about the flang-commits
mailing list