<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61279>61279</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
UBsan misses a left shift of negative value
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shao-hua-li
</td>
</tr>
</table>
<pre>
For the following code, Clang's UBSAN at all opt levels misses the left shift of negative value. GCC however captures it.
Compiler explorer: https://godbolt.org/z/3ocdasq5M
```shell
% cat a.c
int g;
void a(int c) {
g= (-1 << 0 && c);
}
int main() {
a(127);
return g;
}
%
% clang -fsanitize=undefined a.c && ./a.out
%
% gcc -fsanitize=undefined a.c && ./a.out
/a.c:3:12: runtime error: left shift of negative value -1
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyck8-OnD4Mx5_GXCwQOPybA4cZRvxOv16qfYAMMZAqkGkSZtt9-gpmp7tdVXuohEA49sdfx7b0Xo8LcwPFCYpzJNcwWdf4Sdp4WmVsdHSx6mfTWYdhYhysMfZZLyP2VjFQi62RywhUeXw6fT1-QRlQGoP2GtDwjY3HWXvPfg83PAT0kx4C2gEXHmXQN8abNCsn-F_b4mSf-cYOe3kNq2OPOiSQniE93t-tna_asEP-cTXWsQNxxCmEqwdxBOqAutGqizUhsW4E6l6AOmF7Jf334v_3JCjT--MnNubVRgX2WwVJfzfoJeAI4nT_u1mtUALVm7kHOiBUJ7yfIeLmeUagOs4QRAuixRSBSqBy9wbxcIbq_MafpV6A6g-4LU1G1R9hWw7HYXXLO1G_WUDFuyq2tmA8eLnooF8YxHldFA96YbWV99CVAHUysWv4C2Ps-38hdNvtiaMAccxoa49bl6BnRnbO7v36bAwwzj5KeTQqUo1QB3GQETdZWdWioCwvo6m5iEGVlZQZ9YJVJvM8Heo6l1naZ2VepZFuKCWRivSQ1kWRF4mUIs-KgmpVKVZ0gDzlWWqTGHObt8mJtPcrN2VG1SEy8sLG7ztCtPAz7odAtK2Ma7aY-LKOHvLUaB_8GyXoYLh5Onm5PPZAflp-tDrTfJhnHab1kvR2Buo28usnvjr7jfsA1O16PFC36_0VAAD__5EvIT4">