<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/139636>139636</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Flang OpenMP issue with copy private clauses on common blocks.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
scamp-nvidia
</td>
</tr>
</table>
<pre>
We believe the following section of code should work properly as it works with NVIDIA's nvfortran 25.3 and GNU's gfortran version 15.1.
```
Program main
implicit none
call test_common()
End Program main
subroutine test_common()
implicit none
common /vals/ val
integer, target :: targ
integer, pointer :: ptr
integer :: val
!$omp threadprivate (/vals/)
targ = 200
!$omp parallel private(ptr) shared(targ) default(none)
!$omp single
val = 300
ptr => targ ! set private pointer to shared storage
#ifdef NO_COMMON
!$omp end single copyprivate(val, ptr)
#else
!$omp end single copyprivate(/vals/, ptr)
#endif
if (.not. associated(ptr)) then
print *, "ERROR: ptr is not associated"
else
if (ptr == 200 .and. val == 300) then
print *, "SUCCESS"
else
print *, "FAILURE"
end if
end if
!$omp end parallel
end subroutine test_common
```
By default, the code tries to do a copyprviate on a common block at the end of an OpenMP region, but all but 1 thread get the wrong behavior.
```
scamp@milan2:/local/home/scamp/common_issue$ export OMP_NUM_THREADS=4
scamp@milan2:/local/home/scamp/common_issue$ flang test.F90 -fopenmp -o test
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
scamp@milan2:/local/home/scamp/common_issue$ ./test
SUCCESS
ERROR: ptr is not associated
ERROR: ptr is not associated
ERROR: ptr is not associated
scamp@milan2:/local/home/scamp/common_issue$ gfortran test.F90 -fopenmp -o test
scamp@milan2:/local/home/scamp/common_issue$ ./test
SUCCESS
SUCCESS
SUCCESS
SUCCESS
scamp@milan2:/local/home/scamp/common_issue$ nvfortran test.F90 -mp -o test
scamp@milan2:/local/home/scamp/common_issue$ ./test
SUCCESS
SUCCESS
SUCCESS
SUCCESS
```
This is all with almost the latest version of Flang:
```
scamp@milan2:/local/home/scamp/common_issue$ flang --version
flang version 21.0.0git (https://github.com/llvm/llvm-project 227328f6f6d32e93a6c3c0d3c82a7601f92f9abb)
```
As seen in the code, you can work around it by not using the common block, but it should work with the common block as well.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVk1v4zYQ_TX0ZWCBovylgw_aOG4XaJJFsukeA0oayexSpEBSSv3vC1KS7bhBt0UWKGDAEjWcN_M4bzjcWlErxC1ZfiLL3Yx37qDN1ha8aeeqF6Xgs1yXx-03hBylwB7BHRAqLaV-FaoGi4UTWoGuoNAlgj3oTpbwqs13aI1u0cgjcAvChTULr8Id4P73z7vPGWFrC6qvtHGGK2DLKAGuSvjl_jl8qqcvPRrrQeJlFEdAaOZ_Kzr-aPbF6NrwBhouFKEZgGhaKQrhQGmFYaXgUoJD614K3TRaEbYhLCU0u1UlXO0nNLNdbnTnhMJ3N72LEEyAsH3PpSVsDz2Xg61yWKMh7AYcNzU6IElGkiy8XVu02r-YyaR15tJiWp5cExYTttBNC-5gkJetET13CCHSKZAh5mDvEYEkO2CUXjloueFSooTRB2EbD85SsAdusCRsE-JlKZRY8U46wjYh-5GSsysrVC0HVnouA14y4rXO57Ajye0YC4vBoptAT-k7PcKCddrw2nsjLBFViRXcP7zcPNzdPdxf4aIqR2wodHs8J-Lp8tyGfAZPKC3-2-2XVF55UaWohgOqPOmR0i4Cbq0uBHeBtNGcpV45Q3kC-HyVA8Iy75Ewdvv4-PA4HjgIC0q7N25Y2HgKGibAE5_hSCHiqowm0ifeL6CvYZ-eb25un54m__AW4p0499nn354fby83qBJGDi4e37I61RahWSD5fXW9FfWn47nObkLXCQ3GGYHWl0epgY_n1HuSQKuwEFSYS118B-7CPg-pK-AKHlpUd1_AYC28mm8g7xz4zuD_41FD4BXq970arWrI8cB7oU30974T-iRZ0EZIrpiXJttLXfhi2x90g4TtBxO2H-J6EdZ2SNgC8M9WGwcPd19e7p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