<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/82949>82949</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang][OpenMP] Incorrect execution result when common block name is specified in copyin clause
</td>
</tr>
<tr>
<th>Labels</th>
<td>
openmp,
flang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ohno-fj
</td>
</tr>
</table>
<pre>
```
Version of flang-new : 19.0.0(dd7386d85f11cf6ad911b9827c7018fb08c6c205)
```
When `common block` is specified in `copyin` clause, the execution result is incorrect.
The copyin directive appears to be invalid.
The above program is the first program (ompgal036_5.f90).
If a statement referencing an array declared in `common block` is added to `parallel do` construct with `copyin` clause that specifies `common block`, the execution result is correct.
The above program is the second program (ompgal036_52.f90).
The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.
ompgal036_5.f90:
```fortran
program main
integer err
real,dimension(2):: a, b, c
common /blk/ a, b
!$omp threadprivate(/blk/)
a = (/(i,i=1,2)/)
b = (/(i*(i+1)/2,i=1,2)/)
c = 0
!$omp parallel do private(sum), copyin(/blk/)
do i=1, 2
sum = i
call sub(sum, i, c(i))
end do
!$omp end parallel do
err = 0
do i=1, 2
if(c(i) .ne. b(i)) err = err+1
end do
if(err .ne. 0) then
write(6,*) "NG"
else
write(6,*) "OK"
end if
end program main
subroutine sub(sum, i, c)
real,dimension(2):: a, b
common /blk/ a, b
real c
!$omp threadprivate(/blk/)
c = b(i)-a(i)+sum
write(6,*) "sub : b(",i,") = ",b(i), " a(",i,") = ", a(i)
end subroutine sub
```
```
$ export OMP_NUM_THREADS=2; flang-new -fopenmp ompgal036_5.f90; ./a.out
sub : b( 1 ) = 1. a( 1 ) = 1.
sub : b( 2 ) = 0. a( 2 ) = 0.
NG
$
```
```
$ export OMP_NUM_THREADS=2; gfortran -fopenmp ompgal036_5.f90; ./a.out
sub : b( 1 ) = 1.00000000 a( 1 ) = 1.00000000
sub : b( 2 ) = 3.00000000 a( 2 ) = 2.00000000
OK
$
```
```
$ export OMP_NUM_THREADS=2; ifort -qopenmp -diag-disable=10448 ompgal036_5.f90; ./a.out
sub : b( 1 ) = 1.000000 a( 1 ) = 1.000000
sub : b( 2 ) = 3.000000 a( 2 ) = 2.000000
OK
$
```
ompgal036_52.f90:
```fortran
program main
integer err
real,dimension(2):: a, b, c
common /blk/ a, b
!$omp threadprivate(/blk/)
a = (/(i,i=1,2)/)
b = (/(i*(i+1)/2,i=1,2)/)
c = 0
!$omp parallel do private(sum), copyin(/blk/)
do i=1, 2
write(6,*) "main : b(",i,") = ",b(i), " a(",i,") = ", a(i) ! add
sum = i
call sub(sum, i, c(i))
end do
!$omp end parallel do
err = 0
do i=1, 2
if(c(i) .ne. b(i)) err = err+1
end do
if(err .ne. 0) then
write(6,*) "NG"
else
write(6,*) "OK"
end if
end program main
subroutine sub(sum, i, c)
real,dimension(2):: a, b
common /blk/ a, b
real c
!$omp threadprivate(/blk/)
c = b(i)-a(i)+sum
write(6,*) "sub : b(",i,") = ",b(i), " a(",i,") = ", a(i)
end subroutine sub
```
```
$ export OMP_NUM_THREADS=2; flang-new -fopenmp ompgal036_52.f90; ./a.out
main : b( 1 ) = 1. a( 1 ) = 1.
sub : b( 1 ) = 1. a( 1 ) = 1.
main : b( 2 ) = 3. a( 2 ) = 2.
sub : b( 2 ) = 3. a( 2 ) = 2.
OK
$
```
```
$ export OMP_NUM_THREADS=2; gfortran -fopenmp ompgal036_52.f90; ./a.out
main : b( 1 ) = 1.00000000 a( 1 ) = 1.00000000
sub : b( 1 ) = 1.00000000 a( 1 ) = 1.00000000
main : b( 2 ) = 3.00000000 a( 2 ) = 2.00000000
sub : b( 2 ) = 3.00000000 a( 2 ) = 2.00000000
OK
$
```
```
$ export OMP_NUM_THREADS=2; ifort -qopenmp -diag-disable=10448 ompgal036_52.f90; ./a.out
main : b( 1 ) = 1.000000 a( 1 ) = 1.000000
sub : b( 1 ) = 1.000000 a( 1 ) = 1.000000
main : b( 2 ) = 3.000000 a( 2 ) = 2.000000
sub : b( 2 ) = 3.000000 a( 2 ) = 2.000000
OK
$
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWF1v2zoP_jXKDRHDpuPUvshFm7zZOwxbh3N2zrkcZJtOtNmSjyS3278_kD8SJ3U_1q1ALxYULkyTj8iHpESIGyN2kmjFoisWbWa8sXulV2ov1bz4MktV_n3Fln7_52-Yf_k3aSOUBFVAUXK5m0u6BRZeQpB4vuczjPP8IoyXeRwVQZAVS54nQZAmMV5kF34QF6kfZ8sM_Yhh0kGerfDPniSwpZ-pqlIS0lJlX9nSB2HA1JSJQlAOolepvwvpPmYlbwwxXIPdE9A3yhrr3NRkmtI6WyEzpTVl1oNunU97gg4AcuE-iBsCXtfEtQGrICUQ8oaXIvdgZMJTdUNQa7XTvHLAbsFCaGMPQoaxquodL_1w-TnyisRnmHh9sO3zbQEcjOWWKpIWNBWkSWZC7oBL4Frz75BTVnI9ivUOHTzPKXeusqVfc83LkkrIVcuHksbqJrNwK-x-iiuwe24PjJqJJR5ic4LLSWIMZUrm9zCDU9QcAQtVluq25URTi2bpyLLzbjtUoHt5UyhttaNP5iDcC2SqqkXJne8Mt-dxnCx7nrDw8qw4e_ROOsRTcdFLAIS0tCMNpPUg0sRLhutcVCRN60SMruzDS9cx3Hmdukc2GPQZYLhNy68Mt4NO5woGDBeqqsHuNfG81uKGW2IYH_QPPQXAgYUb6D4yjAXDtWDhJmC4bn04UU7vKF92_66CThcfNM9ac__czVFNwtFZ01QtwLrvvnv8zxUMCwIOQgAwTdWuJkayjJclmCYd0NcgOlrbGJIRKsncdciZo046bqBBWetxYNM-iYJhPKwEniTP5XRY94DhqsKxOeEHdBhOszV3LeHKfaisWy1a4pYM121iEmCIH94wPPBCpaERH9MW1-_GFm2TdG806tBjRXdP06RaNVZImiY4-aFaf0qZd1BDT_xY0XeFOPA_54dEXDm3e6VpdkyTQnuQpS12V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