| Issue |
244759
|
| Summary |
[flang][OpenMP] `construct={simd}` without properties matches outside SIMD
|
| Labels |
flang
|
| Assignees |
|
| Reporter |
chichunchen
|
Flang ignores a `construct={simd}` selector that has no properties. A DECLARE VARIANT or METADIRECTIVE alternative that requires SIMD is therefore selected everywhere, including outside any SIMD construct.
SIMD is the only `construct` selector that is also a predefined trait selector name, because it accepts clause properties such as `simd(simdlen(4))`. Without properties, the parser produces `OmpTraitSelectorName::Value::Simd` instead of a directive name. The semantic code that records the required construct traits (`flang/lib/Semantics/openmp-utils.cpp`) handles only directive names, so the selector adds no requirement.
OpenMP 5.2 §7.1 and 6.0 §9.1 match `construct={simd}` only when SIMD is in the construct trait set, which means the call has to be inside a SIMD construct.
### Reproducer
```fortran
module a
contains
subroutine simd_variant
end subroutine
subroutine simd_base
!$omp declare variant(simd_variant) match(construct={simd})
end subroutine
! Not inside SIMD: expected simd_base.
subroutine outside_simd()
call simd_base()
end subroutine
! Inside SIMD: expected simd_variant.
subroutine inside_simd(n)
integer :: n, i
!$omp simd
do i = 1, n
call simd_base()
end do
end subroutine
end module
```
```console
$ flang -fc1 -fopenmp -fopenmp-version=52 -emit-hlfir repro.f90 -o -
```
| Procedure | Expected | Actual |
|---|---|---|
| `outside_simd` | `simd_base` | `simd_variant` |
| `inside_simd` | `simd_variant` | `simd_variant`, but only because the selector is ignored |
A METADIRECTIVE `when(construct={simd}: ...)` clause goes through the same path and is affected in the same way.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs