[flang][OpenMP] Assertion failure on DECLARE TARGET naming a namelist group or a derived type
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
(Issue created with the help of AI while investigating another flang failure.)
### Summary
`!$omp declare target(...)` crashes flang with an assertion failure when the item named
is a **namelist group** or a **derived type**. Both are invalid `DECLARE TARGET` items, so
flang should emit a semantic diagnostic; instead it aborts.
### Reproducers
Namelist:
```fortran
! namelist group
program p
real :: x, y
namelist /n/ x, y
!$omp declare target(n)
end program
```
Derived type:
```fortran
! derived type name
program p
type :: t
integer :: i
end type
!$omp declare target(t)
end program
```
```console
$ flang -fopenmp -c repro.f90
```
### Actual behaviour
```
flang: llvm-project/flang/lib/Semantics/resolve-directives.cpp:2407:
auto Fortran::semantics::OmpAttributeVisitor::Pre(const parser::OmpDeclareTargetDirective &)
::(anonymous class)::operator()(auto &) const [d:auto = Fortran::semantics::NamelistDetails]:
Assertion `(std::is_base_of_v) && "Unexpected details type"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ ...
Stack dump:
0. Program arguments: flang -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -fopenmp ... -x f95 repro.f90
#11 Fortran::semantics::OmpAttributeVisitor::Pre(Fortran::parser::OmpDeclareTargetDirective const&)
#12 ParseTreeVisitorLookupScope::Walk(...)
...
#18 Fortran::semantics::ResolveOmpParts(Fortran::semantics::SemanticsContext&,
Fortran::parser::ProgramUnit const&)
#19 Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::ProgramUnit const&)
```
The derived-type case is the same assertion with `[d:auto = Fortran::semantics::DerivedTypeDetails]`.
### Expected behaviour
A semantic error, as flang already produces for other invalid `DECLARE TARGET` items —
e.g. a module name or a statement function are both diagnosed cleanly today.
### Scope
Reproduces with every clause spelling and every OpenMP version:
| variant | result |
|---|---|
| `declare target(n)` | assertion failure |
| `declare target to(n)` | assertion failure |
| `declare target link(n)` | assertion failure |
| `declare target enter(n)` | assertion failure |
| `-fopenmp-version=45 / 50 / 51 / 52 / 60` | assertion failure in all |
Which symbol kinds reach the crash:
| `DECLARE TARGET` item | behaviour |
|---|---|
| namelist group | **assertion failure** (`NamelistDetails`) |
| derived type name | **assertion failure** (`DerivedTypeDetails`) |
| module name | diagnosed correctly |
| statement function | diagnosed correctly |
| variable / named constant / common block | accepted |
### Regression range
Introduced by 270a6a8f6742:
```
270a6a8f6742 [flang][OpenMP] Store DECLARE_TARGET information in WithOmpDeclarative (#201103)
```
`git blame` attributes the `assert` and its enclosing `else` to that commit.
### Notes
- Only assertions-enabled builds abort.
- Verified against two independently built compilers from different upstream `main`
bases, both of which reproduce identically.
Contributor guide
Research direction
Start with flang/lib/Semantics/resolve-directives.cpp at OmpAttributeVisitor::Pre for OmpDeclareTargetDirective, then run the provided namelist and derived-type reproducers with flang -fopenmp -c. Done means both cases produce semantic diagnostics instead of assertion failures, across the listed DECLARE TARGET spellings and OpenMP versions.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100