<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58735>58735</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missing UBSan check with call to constexpr function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
efriedma-quic
</td>
</tr>
</table>
<pre>
```
constexpr unsigned long shiftone(char v) {
return 1 << v;
}
void f() {
const unsigned long v = shiftone(46);
}
```
With -fsanitize=undefined, the generated code for f() should call `__ubsan_handle_shift_out_of_bounds`, but it doesn't in clang. I think what's happening is that we try to opportunistically evaluate the variable, but we're doing it in a mode that ignores any undefined behavior. With ubsan enabled, we should abort constant evaluation if the evaluator finds UB.
Godbolt: https://godbolt.org/z/desT7Tfa6
(Based on discussion in https://reviews.llvm.org/D136805 . Not sure if this is exactly the same as the issue discussed there, but it's probably similar.)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxtU8uSmzAQ_Bq4TK2LhwFz4LBe16ZySC7ZrRxdAwygRJYcPfB6vz6D7H3EFUrASIO6e3pEq_tzE5XJdSS7KLnvtLKOXo4GvLJiVNSD1GoEO4nBaUVRtukmNDBHWQ1Rtb3sAr4MOW8UpBDlDzz4i_yajardNQjPWYseBga6gQjUN7Qzo-0-k69L3vUf5H-ruDx_CjfB3WBRCSdeiZG86mkQjB5lD-AmgpEUGXRM1-meYNDmXZmdtJe8jlICA-_3vmWk_YSql7QPkvba8z3sW83AdmFn2NY7EA56TVZFWcUTBZ1ENa4AvjKpUL_hNKHjnIUJj0dSgisVlnPo4ETgzBmcBn08auO8EtaJRcUZaEbpWW2QPqMR2Ep64zxxVBli4gAXeBEOS1kBmF3VhiygOsO7D9DShLPQhsUFu0KRQGpBDi6xnqsT2LKcS5dQuTcxQisQQ1B0XVk8FOwHPG9Xn9vxRfetli7K72Fy7mg5iLJHHuMlsdJm5Nkr3z3Zp-ppwPLzfu7LFi1rZsZe2M5bG8jVDZyhWdDJrqScD1fMXZqXm6QArvK7dmA9-xREs-s86AU7x_4uRVg8EKANsbDW0xsXE_OaoY8ehw4ejW7ZrDNYcRASzYrPTkxNWpZVnpV5Wsd9k_d1XmPshJPUfGPUpUPP2x_sdDdRx-dhsT6cNO77xy84eNUtBsfeyObGM97h21WnDzxZKr2-7ljPL-pY22NQbzkoNlVexFPTpvl6nSZYboZ66GtM8i5NhyrNhizr12URS2xJ2iYqtlGWKTpdDOA4KnaxaLIky9I0SdNNmhb1qhuIsmrTlUXe1vm6jtYJHVDId-Nj0wRJrR8tJyUf5I-uxGjDj06BjvHRu0mbhgYjqD_g3R8vujgIaEIBfwFmiIOB">