<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57656>57656</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Failure to link with device code using assert
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          markdewing
      </td>
    </tr>
</table>

<pre>
    Code that uses `assert` in device regions fails to compile at the link step with the error:
```
nvlink error   : Undefined reference to '__assert_fail' in '/tmp/test_assert-da8852-nvptx64-nvidia-cuda-sm_61-108a4e.cubin'
```

The test code is
```
#include <cassert>

int main()
{
    int i = 1;
#pragma omp target
    assert(i > 0);
    return 0;
}
```
Compiled with
```
clang++  -O2 -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda  test_assert.cpp
```

This issue affects LLVM 15.  It compiles without complaint on LLVM 14 (and the assert triggers as expected if the value of `i` is changed to -1)
The same behavior happens with an AMD target (works with 14, fails to link on 15)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9U02PmzAQ_TVwGRGB-UoOHDbJrlRpV720vUYGD-AuGGSbbPvvOzYku4eokuXPmTdvZp7rSfytTpNAsD23sBg0EBQxNwa1pQ1IBQKvskHQ2MlJGWi5HAzYCZppnOWAQH62RxikegdjcYYPaXt_hVpPOkifgvgcxE8Etw1_VFfv4W0AgMzgpxLYSoWCgrWoUVFYChSw8nJZKV1cdDo7XrQE7MWOs5vR2M0kEny_z1mkrrP9U2S0SiF51CyCR2a8FEmUxHue4a5ZaqkcyCN26_yDknDQlCuVSJrHpiyVqhkWsgjSU7PVLn3-CiSVhZG7cPuAHbaX8rhuKHtwBpL8z5AE6fEOPGvejRyo0mC57tB-emxx2N65PUPscNMviBrtohXd3-HK80P-p7WPwvftoUUzcNUF7EgDIPrOIGqnGRWRum2ilZ2hBB7UHeBLf3bNPP-35NJQpc1CwmpbbKyB19dfb5DkO4Bv9qY649lOy3oxcFe_SW2mGWljz5XwIlyjgtWy61AbOgP-mQmYMpatN7nygcJNrZO-9Ko30PSUM5mQ_qLk3jMnCMNHhBp7fpWk3J7PVIGVDnAFT2_nrVWOxMek37e3JAvY6fP3ePET4yQn8BCrpChYmWVFXoaiSsUhPfDQSjtg9UIui8a7k0fbPqXX5WKk6rY8w0UPVW_tbNy_Yy80OrJf6h3ViQ7DcL0t0ayn31QHOvp6G9rkZZEXYV9lZZILhjGLW0ySnIlDEWdp0WKGgjd5Eg68xsFUQX4M8nMoKxYzFh_iQ1KmcV7uWMaKQ9zWtYh5JuosyGIk_Q87F3g36S7UledQL52hx0Eaaz4fKRfZKcQbPl-o17oauX4X-EHZhp5x5en-A8XZd5Y">