[flang][OpenMP] Standalone metadirective accepts a block-associated variant without a diagnostic
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Flang accepts a standalone `metadirective` whose selected variant is block-associated. Lowering then evaluates the variant's clause operands but emits no region.
```fortran
subroutine standalone_np(x)
integer :: x
integer :: f
external :: f
!$omp metadirective when(implementation={vendor(llvm)}: parallel num_threads(f())) otherwise(nothing)
x = 1
end subroutine
```
`-fsyntax-only` accepts this. At `-emit-hlfir` the output contains `fir.call @_QPf` and no `omp.parallel`.
OpenMP 5.2 [7.4.3] gives the standalone `metadirective` `Association: none`. OpenMP 5.2 [7.4] restricts metadirectives so that replacement of the metadirective with the directive variant of any dynamic replacement candidate must result in a conforming OpenMP program. Replacing this metadirective with `parallel` yields an unpaired `parallel`, which flang rejects when written directly:
```
error: Expected OpenMP END PARALLEL directive
```
The metadirective spelling should be rejected on the same grounds.
Flang already enforces the converse direction. OpenMP 5.2 [7.4.4] requires every variant of a `begin metadirective` to have a paired end directive, and flang diagnoses a violation:
```
error: A directive in BEGIN METADIRECTIVE should have a corresponding end-directive
```
The check in `flang/lib/Semantics/check-omp-variant.cpp` that rejects a non-associating variant in the delimited form has no counterpart rejecting a block-associated variant in the standalone form.
This is not tied to any in-flight patch. It reproduces identically on separate builds.
Contributor guide
Research direction
Start with the standalone Fortran reproducer and confirm that -fsyntax-only accepts it while -emit-hlfir evaluates f() without emitting a region. Inspect flang/lib/Semantics/check-omp-variant.cpp, especially the existing check for non-associating variants in the delimited form. Add the corresponding standalone diagnostic and a regression test showing that a block-associated variant is rejected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100