[flang-commits] [flang] [flang][OpenMP] Add semantic checks for two DECLARE VARIANT restrictions (PR #209528)
Abid Qadeer via flang-commits
flang-commits at lists.llvm.org
Wed Jul 15 03:59:50 PDT 2026
abidh wrote:
> Do we intend these restrictions to be checked across program units for external procedures? For example:
>
> ```fortran
> subroutine s1
> real, external :: b1, v
> !$omp declare variant (b1:v) match (construct={parallel})
> end
> subroutine s2
> real, external :: b2, v
> !$omp declare variant (b2:v) match (construct={do})
> end
> subroutine s3
> real, external :: b3, v
> !$omp declare variant (v:b3) match (construct={parallel})
> end
> ```
>
> Each local declaration of v has a different Symbol, so this appears to be accepted currently. Is this case supported, or is cross-program-unit checking intentionally out of scope?
Yes, the cross-program-unit checking for external procedures is out of scope here. This isn't a new inconsistency: the only pre-existing declare-variant check that is cross-directive, the duplicate-pairing check ("Variant 'X' was already specified for 'Y' in another DECLARE VARIANT directive"), already has exactly this limitation.
```
subroutine s1
real, external :: b, v
!$omp declare variant (b:v) match (construct={parallel})
end
subroutine s2
real, external :: b, v
!$omp declare variant (b:v) match (construct={parallel}) ! same pair, not flagged as duplicate
end
```
There's also a fundamental limitation that external procedures are usually defined in separate compilations, so this restriction can't be enforced in general. It could only ever catch the case where the units happen to share a source file.
If you think closing this gap within-a-file is worthwhile, I can try to do that in a follow-up PR for both this case and the duplicate case I described above. It may not be trivial though as these externals share only a name (no common symbol), so it would likely need name-based matching rather than the symbol comparison.
https://github.com/llvm/llvm-project/pull/209528
More information about the flang-commits
mailing list