[Flang][OpenMP] Incorrect output for a threadprivate namelist group
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Summary
When a *namelist-group-object* is specified in a `threadprivate` directive, a WRITE statement produces incorrect output for the namelist group.
### Reproducer
* test.f90
```fortran
use omp_lib
integer,save :: TID
!$OMP threadprivate(TID)
namelist /NML/ TID
call omp_set_num_threads(4)
!$OMP PARALLEL
!$omp critical
TID=omp_get_thread_num()
print *,'thread_num=',omp_get_thread_num(),'TID=',TID
write(*,NML)
!$omp end critical
!$OMP END PARALLEL
end
```
* commands
```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git b51054818b78dc395cd4d33f17cfb6e98a36a76d)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang -fopenmp test.f90 && ./a.out
thread_num= 0 TID= 0
&NML TID= 0/
thread_num= 3 TID= 3
&NML TID= 0/
thread_num= 1 TID= 1
&NML TID= 0/
thread_num= 2 TID= 2
&NML TID= 0/
```
## 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 && ./a.out
thread_num= 0 TID= 0
&NML
TID=0 ,
/
thread_num= 3 TID= 3
&NML
TID=3 ,
/
thread_num= 1 TID= 1
&NML
TID=1 ,
/
thread_num= 2 TID= 2
&NML
TID=2 ,
/
```
* 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 && ./a.out
thread_num= 2 TID= 2
&NML
TID = 2
/
thread_num= 0 TID= 0
&NML
TID = 0
/
thread_num= 3 TID= 3
&NML
TID = 3
/
thread_num= 1 TID= 1
&NML
TID = 1
/
```
Contributor guide
Assessment
This issue has not been assessed yet.