<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64849>64849</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
UBSan misses shift exponent is too large
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jun-wei-zeng
</td>
</tr>
</table>
<pre>
Compiler explorer: [https://godbolt.org/z/5ah6GsW8E](https://godbolt.org/z/5ah6GsW8E)
For the following code, all opt levels of clang's UBSan can not capture the runtime error (i.e. shift exponent is too large), while gcc can.
```c
$ cat test.c
#include <stdio.h>
unsigned short a;
int main()
{
a = 10 >> 6131641877415512002LL && 1;
a = 10 >> 6131641877415512002LL || 0;
a = 10 >> 6131641877415512002LL ? 1 : 0;
printf("%d\n", a);
return 0;
}
$ clang -fsanitize=undefined test.c; ./a.out
0
$ gcc -fsanitize=undefined test.c; ./a.out
test.c:6:11: runtime error: shift exponent 6131641877415512002 is too large for 32-bit type 'int'
test.c:7:11: runtime error: shift exponent 6131641877415512002 is too large for 32-bit type 'int'
test.c:8:11: runtime error: shift exponent 6131641877415512002 is too large for 32-bit type 'int'
1
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VMlu5DYQ_ZrSpdACWdTWBx16sXKZWxDkzJZKEgdsskFS44y_PpDaGduNIMjMwYCghcX3WMvT0zGayTG3UB6hPGd6SbMP7dfF7Z7Z7F7YTdnFD9_bk7_ejOWA_NfN-sAB1AGhPM4p3SKoA1AH1E1-uHibch8moO4FqCv1XP0W_2yeoDwDNf9_O-1BnEEc7vfOB0wz4-it9c_GTdj7gYFOqK1Ff0to-RvbiH7E3mo3AdUR_zj-rh322qHzCXt9S0vgjScsLpkrI4fgAwI1Jucc42zGtFboHbuEJmLyHq0OE6_50AmfZ2MZp75fWXN8nyJU4n71r99UYK8TJo4p_7GmjOvtMjCCOsU0GJ_PoJ7u0cVtwxgwzj4k1KCO94BxCa_aOKDmrS_1axARUSOoM0qBK5d6wkoqWRWyqetClqUkIejLFwSqgCqUP3h_AlqfoD6h-BWo6lDiKpeP6FswLo1bSQRUDlCe3PZ6Qr1W-X5v4LQE944A6vO7Lq8Dx90YtTPJvDCo8-IGHs3ay9f2qyPmQJ3O_ZLuSPFGsM7zZ-H_BA4VqIOUa30fRLUuPOjpX_rzQWM4-oCKdheTMH2_MQLVxiWg-uHI-vOPbD7tSPnwO2VDq4a92uuMW1ntqRKCmjqb22LYV9T3JJiKoZGqp5EqedG1kCxUoTPTkiAlGpKiKoqizgvVFPuyEuNFlD3JHgrBV21sbu236-pCmYlx4bYqmmKfWX1hGzdnJHL8jFtwlWh5zkK7YnaXZYpQCGtiim8sySTL7d19riZGjv9lLdkSbPtgjCbNyyXv_RWoW2lfH7tb8F-5T0DdlkwE6rZk_w4AAP__3I6sog">