<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64133>64133</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[OpenMP] Unused external variables are emitted when declared on the target
</td>
</tr>
<tr>
<th>Labels</th>
<td>
openmp
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jhuber6
</td>
</tr>
</table>
<pre>
The following code snippet will cause the external variable `a` to be emitted in the IR even though it is not used. See also the godbolt link, https://godbolt.org/z/M5MsrnbnM.
```c
extern int a;
#pragma omp declare target to(a) device_type(host)
int main() { return 0; }
```
The standard semantics maintain that unused extern variables will not be emitted. This is important for linking as linking in a static library that defines `a` will be extracted even though it's unused.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxck0-PszYQxj_NcBm9yDEJCQcOm0aReohatdtzNeABvDU2sodst5--ArJ_3pUQ2GKYZ_x7Higl23vmGg5nOFwymmUIsX4Z5oZjmTXBvNXPA2MXnAuv1vfYBsOYvJ0mFny1zmFLc2KUgZH_FY6eHN4pWmocI5SKoFQoARtGHq0IG7R-Lf_1D-Q7L-sw9wNaQZvQB8E5scnxT2Ykl8Ja2wfTBCforP8H9C84iEwJiifQV9DXx9s8xB709T_Q19vhlqJv_C0HdQH1BKXarnbbb6Oi9YIExflRpIspUj8ShnFCw62jyCgUexaUAPpEoCs0fLct_y1vE4M-DSEJ6OrRYb0vXUeyHvRpqYfjGSPLHD0qKM4Ix8u3obbtAjoJeUPRYOKRvNg2rZ2EVmYkOPuFzgP1B-i0WbHA--Sc4_Ng0wLVjlOIQl6wC3FluFhJ6WNpPdKiLbZFZ5tI8W2TM9xZz-nDyFWmWa2O1C5m_mwh6GN6zJhnpi5MVVSUcb0rK1VU5WmnsqFudh2zaiviPZetMZXpurZTjVKFrqqOMltrpQt11OXutFc7le9bpY-nkqui6w5HdYS94pGsy527j4vtmU1p5rrc74oic9SwS2umtQ4T-3ECrZd8x3r54Ecz9wn2ytkk6bOFWHHrn_DbxP72Oxwu-NdX2l-CnXBJxnueXwf273ExGLZ0b7HJ5ujqb2G1MsxN3oYR9HURfzx-TDG8cCugr-thEujrep7_AwAA__8luDNU">