[flang-commits] [flang] [flang][OpenMP] Lower DO and SIMD variants in metadirectives (PR #210810)
via flang-commits
flang-commits at lists.llvm.org
Wed Jul 29 21:49:47 PDT 2026
================
@@ -1352,6 +1358,14 @@ void OmpStructureChecker::Enter(const parser::OpenMPDeclarativeConstruct &x) {
EnterDirectiveNest(DeclarativeNest);
}
+void OmpStructureChecker::Enter(const parser::OpenACCDeclarativeConstruct &) {
----------------
MattPD wrote:
The new `Enter(parser::OpenACCDeclarativeConstruct)` and `Enter(parser::OpenACCRoutineConstruct)` hooks diagnose the OpenACC cases, but plain Fortran reaches the same abort. A `FORMAT` statement between the metadirective and its loop is accepted by `-fsyntax-only` and then aborts in lowering:
```fortran
subroutine fmt_sib(n, a)
integer :: n, a(n), i
!$omp metadirective when(implementation={vendor(llvm)}: do) otherwise(nothing)
100 format(1x,i0)
do i = 1, n
a(i) = i
end do
end subroutine
```
```
not yet implemented: loop-associated METADIRECTIVE without associated DO (OpenMP.cpp:6316)
```
Two conditions combine:
- `FORMAT` is legal in a specification part, so the parser classifies the metadirective as an `OpenMPDeclarativeConstruct` there. `Enter(parser::ExecutionPartConstruct)` then never sees an interposed construct.
- `FORMAT` also produces an evaluation of its own, which `spliceAssociatedDoEval` does not skip. It skips only end statements and `parser::CompilerDirective`.
`-fdebug-dump-pft` shows the difference against an interposed `DATA` statement, which is equally legal in a specification part but lowers cleanly. With `FORMAT`:
```
OpenMPDeclarativeConstruct
FormatStmt: 100 format(1x,i0)
<<DoConstruct>> -> 4
```
With `DATA`:
```
OpenMPDeclarativeConstruct
<<DoConstruct>> -> 4
```
So specification-part legality alone is not the discriminator. The construct also has to produce an evaluation of its own, which is what puts it between the metadirective and the loop. `ENTRY` meets both conditions and behaves like `FORMAT`, while an ordinary assignment is diagnosed correctly.
Would deriving the semantic check and the splice from one shared predicate close the category at once? `FORMAT` looks like it should join the skip list, whereas `ENTRY` is a real entry point, so a diagnostic may be the right answer there.
https://github.com/llvm/llvm-project/pull/210810
More information about the flang-commits
mailing list