[Flang][OpenMP] Incorrect semantic error for threadprivate directives in internal procedures
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Summary
Flang incorrectly reports a semantic error when a variable is not explicitly defined but is specified in a `threadprivate` directive.
### Reproducer
* test.f90
```fortran
subroutine s
contains
subroutine sss()
save
!$omp threadprivate(i)
end subroutine sss
end subroutine s
```
* commands
```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git 5347264191e74840adc740db1aa41b7a9d33670a)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 -fopenmp -c
error: Semantic errors in test.f90
test.f90:5:23: error: Implicitly typed local entity 'i' not allowed in specification expression
!$omp threadprivate(i)
^
test.f90:5:23: error: A variable that appears in a THREADPRIVATE directive must be declared in the scope of a module or have the SAVE attribute, either explicitly or implicitly
!$omp threadprivate(i)
^
```
## Non-problematic Conditions
The issue does not occur under the following conditions:
* Defining the variable explicitly.
* Converting the internal procedure into an external procedure.
## Other Compilers
* GFortran
```console
$ gfortran --version
GNU Fortran (GCC) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gfortran test.f90 -fopenmp -c
$
```
* Intel Fortran
```console
$ ifx --version
ifx (IFX) 2025.3.2 20260112
Copyright (C) 1985-2026 Intel Corporation. All rights reserved.
$ ifx -O0 test.f90 -qopenmp -c
$
```
Contributor guide
Research direction
Start by reproducing the failure from the issue's test.f90 example with Flang and -fopenmp. Trace the semantic handling of the internal procedure's threadprivate directive and compare it with the explicitly declared and external-procedure cases. Done means the reproducer compiles without the incorrect semantic errors while the relevant invalid cases remain diagnosed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100