<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60739>60739</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang][OpenMP] Assertion failure while lowering code with Threadprivate construct
</td>
</tr>
<tr>
<th>Labels</th>
<td>
openmp,
flang:ir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kiranchandramohan
</td>
</tr>
</table>
<pre>
Compiling the following code leads to an assertion failure. Code contains threadprivate variables in modules that are used in nested subroutines.
GDB backtrace shows that the Threadprivate value obtained in OpenMP.cpp:297 is not defined.
```
297 mlir::Value symOriThreadprivateValue = converter.getSymbolAddress(sym);
298 mlir::Operation *op = symOriThreadprivateValue.getDefiningOp();
```
**Reproducer**
```
module tpmod
real :: val = 2.0
!$omp threadprivate(val)
end module
subroutine tptest
use tpmod
call tps()
contains
subroutine tps()
!$omp parallel
val = 1.0
!$omp end parallel
end subroutine
end subroutine
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VE-PqzYQ_zTmMnoI7ASSAwd2UXqqtmqr3gc8AfcZ27JNov32lSHZbKLXCBE8M_79Gf_BENRoiBq2f2P7LsMlTtY3P5VHM0xopMfZTmiy3srP5t3OTmllRogTwdlqba9pNFhJoAllgGgBDWAI5KOyBs6o9OIph_dUM1gTUZkAcfKE0nl1wUhwQa-w1xRAGZitXNJnnDACeoIlkEwJQyGShLD03i5RGQo5KzpWtNv7t-4Nehx-Ro8DQZjs9YaRtP79wqcXAtsnLRv2hyPz-x_54BwTLT_WoAIYG0HSOZXciari9qzDVHf_zVp5Jlom2n9W8PA5f3j1RLslmOhSGy7kI_l8pPjX59xb3UrpKQTGD-FzZvzIxNud5PALkg9HHtcGM95at6L-H2Ui6ZIPZcYPx_jhO_yLpdubp-dPct7KZSC_jX85YVstiG62cosAeEINm87U6lUcz4t7mvGS8Z2d3fMuYPxwQZ20rXVk5G0rfFf2WHyILlKId9AlvIgYUGuILtz8rtH79rvXPKE9VaZuP3Q69Kg16UcOvoyVD2PfpyT5r9NS7EH5sPka-2pxJhshj-KIGTVlVVeirgtRZVNT0-5c11W1L-q6KHi5kzicz5WsDsd-QC4y1fCCi5QpeVmXVY5SHo59VfKjEH1ZFGxX0IxK51pf5tz6MVMhLNRURS2OmcaedFgvBc6tIzM7xjnj74zzs0YzMtEqn0L7LvNNwvjRL2Ngu0KrEMMDNaqo19vltE7bd2z_th02tu-gfb0n4DopTaDtlfzXzXJVcXo5wYM1IfpliJAtXjdTTOsnWsZPjJ9GFaelzwc7M35KSm5_P5y3_9IQGT-tZgPjp9XvfwEAAP__HBGSTQ">