[clang] [flang] [llvm] [clang][flang][OpenMP] Fix context selector matching and scoring (PR #224431)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 3 03:13:45 PDT 2026
================
@@ -7633,6 +7675,18 @@ static void genMetadirective(lower::AbstractConverter &converter,
}
}
+ if (!hasLoopAssociatedCandidate &&
+ llvm::any_of(reachableVariantSpecs, [](const auto *spec) {
+ return spec && hasDirectiveAssociation(spec->DirId(),
+ llvm::omp::Association::Block);
+ }))
+ associatedBlockEval = spliceAssociatedEval<parser::BlockConstruct>(
----------------
MattPD wrote:
A BLOCK associated with a metadirective is not part of the metadirective's parse tree. `visitAllSymbols(eval, ...)` in TARGET implicit-map collection and `collectSymbolsWithDynamicSubstring` still walk only that parse tree, so they miss variables referenced in the BLOCK.
You can reproduce this by saving the following to `repro.f90` and running `flang -fc1 -fopenmp -fopenmp-version=52 -emit-hlfir -module-dir /tmp repro.f90 -o -`:
```fortran
subroutine s(x)
integer :: x
!$omp metadirective when(implementation={vendor(llvm)}: target)
block
x = x + 1
end block
end subroutine
```
At 1850727, FIR verification fails with `'fir.load' op using value defined outside the region`. A directly written TARGET and a `begin metadirective` selecting TARGET both capture `x` and compile. At 9d79b83, Flang compiles the input but leaves the BLOCK outside an empty TARGET. The selection here is static, so the failure differs from the [runtime-selection failure](https://github.com/llvm/llvm-project/pull/224431#issuecomment-5840331662) reported earlier.
Could both symbol walks include the spliced BLOCK evaluation before the selected TARGET is lowered?
https://github.com/llvm/llvm-project/pull/224431
More information about the cfe-commits
mailing list