<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/106021>106021</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang][OpenMP] Compilation error when declarations within threadprivate directive and explicit declarations
</td>
</tr>
<tr>
<th>Labels</th>
<td>
openmp,
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ohno-fj
</td>
</tr>
</table>
<pre>
```
Version of flang-new : 20.0.0(3496245ed3d0b4d24444260da77dcdb93512fb5a/AArch64
```
Variables defined with `threadprivate` directive and `explicit declaration` result in a compilation-time error.
When `threadprivate` directive is removed, the compilation succeeds
The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.
snggy156_.f90:
```fortran
subroutine s1
integer omp_get_thread_num
save p1,x1
!$omp threadprivate (p1)
!$omp threadprivate (x1)
integer x1
procedure(ss1),pointer::p1
interface
subroutine ss1(i)
end subroutine ss1
subroutine ss2(i)
end subroutine ss2
end interface
!$omp parallel private(k)
if (omp_get_thread_num() ==1) then
p1=> ss1
else
p1=> ss2
end if
call p1(k)
if (omp_get_thread_num() ==1) then
if (k/=1) print *,101
else
if (k/=2) print *,102
endif
!$omp end parallel
end subroutine s1
program main
call s1
print *,'pass'
end program main
subroutine ss1(i)
i=1
end subroutine ss1
subroutine ss2(i)
i=2
end subroutine ss2
```
```
$ flang-new -fopenmp snggy156_1.f90
error: Semantic errors in snggy156_.f90
./snggy156_.f90:6:11: error: The type of 'x1' has already been implicitly declared
integer x1
^^
./snggy156_.f90:3:11: Implicit declaration of 'x1'
save p1,x1
^^
./snggy156_.f90:7:27: error: The interface for procedure 'p1' has already been declared
procedure(ss1),pointer::p1
^^
./snggy156_.f90:3:8: Implicit declaration of 'p1'
save p1,x1
^^
$
```
```
$ gfortran -fopenmp snggy156_.f90; ./a.out
pass
$
```
```
$ ifort -qopenmp -diag-disable=10448 snggy156_.f90
snggy156_.f90(6): error #6415: This name cannot be assigned this data type because it conflicts with prior uses of the name.
[X1]
integer x1
----------^
snggy156_.f90(7): error #6406: Conflicting attributes or multiple declaration of name. [P1]
procedure(ss1),pointer::p1
--------------------------^
snggy156_.f90(16): error #6424: This name has already been used as an external subroutine name. [SS1]
p1=> ss1
----------^
snggy156_.f90(16): error #6796: The variable must have the TARGET attribute or be a subobject of an object with the TARGET at
tribute, or it must have the POINTER attribute. [SS1]
p1=> ss1
----------^
snggy156_.f90(18): error #6424: This name has already been used as an external subroutine name. [SS2]
p1=> ss2
----------^
snggy156_.f90(18): error #6796: The variable must have the TARGET attribute or be a subobject of an object with the TARGET at
tribute, or it must have the POINTER attribute. [SS2]
p1=> ss2
----------^
snggy156_.f90(20): error #6419: This scalar name is invalid in this context. [P1]
call p1(k)
-------^
compilation aborted for snggy156_.f90 (code 1)
$
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUV02P27wR_jX0ZWBDGn1YPvjg_fCL99AmSBZtbwtKGtlMKFIlKe_uvy8oybZsa7Npmh5eY4GFyCHnmWeGD4fcWrFTRGuW3LHkYcZbt9dmrfdKz6tvs1yXb2uWBsNf8MCCzT_IWKEV6AoqydVurugFWLQBDBbBImCYRfEqxTihMiqDPC4xjuMY06Dky2VZlPkqSkKs8oQz3G42ptincb_zlaPBHTeC55IslFQJRSW8CLcHlgZub4iXjREH7oilAZTCUOHEgYCr0lvQayNFIRyUVEhuuBNaeUNDtpUOhAIOha4bIbupuRM1ARmjzQKgd__PPakPnAkLhmp9oJLhPbg9jfcE2xYFUWnHMT3tCSotpX4RagfcULfKkXXQGL0zvPY7bY_s-o8_Km2c4aoLTfiPsReGW3qlou089tEtxg6t2u3ewiR9XlSrgEWbK76HvQfbNje6dUIR2LAfAhDK0Y4M6Lp53pF77ul4Vm19tLD8QNCEDO9fh1UMQ4axrhu4IA8YZt5u9aHV69nqjOD1hKkxuqCyNcQws7azxftGe0PjY4w2zdG2G6t4Qce1ADCO06_OxMgbAJAqr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