<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61982>61982</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
MemorySanitizer cannot detect (unsigned char -1)
</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, MSan cannot detect the use-of-uninitialized-memory. But if you change `a-1` to `a` or `a+1`, it can again.
```shell
% cat a.c
int main() {
unsigned char a;
if (a-1)
__builtin_printf("boom!\n");
return 1;
}
% clang -O0 -fsanitize=memory a.c && ./a.out
boom!
%
```
```shell
% cat a.c
int main() {
unsigned char a;
if (a+1)
__builtin_printf("boom!\n");
return 1;
}
% clang -O0 -fsanitize=memory a.c && ./a.out
==1==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x556ccb2a4fdb (/app/output.s+0xa4fdb)
#1 0x7fde559fe082 (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)
#2 0x556ccb21dc1d (/app/output.s+0x1dc1d)
SUMMARY: MemorySanitizer: use-of-uninitialized-value (/app/output.s+0xa4fdb)
Exiting
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVMGOpDYQ_ZriUgKZAgwcOHRvh2gPs5F2FEU5jQw24Mhtt8De7dmvj4DemdlWRkmkHIKQbaqoV6-eyxbLokerVAPFEYpTJIKf3Nwsk3DxFERsdNQ5-dy0bkY_KRycMe6rtiP2TiqgD_jwKCz2wlrnUSqver_9GBYVuyEOVlvttTD6m5LxWZ3d_JzgMXjUAz67gP0k7KgQOBNxCpyhd9vHunTzvqTj6lmTab-mQjEKbRNgJ2CH28jZ_i6TMuZmowJ74VEk_W7Q1uNZaAtUAdUI5XG3IyIGuwkhV0IzCsje-PSAQNXKj-pX6_o8PXVBG6_t02XW1g8bMnXOnYFSKD5YIFqD3qLNyofZYvpihPL0hrARdsT4F4bxsIhVu28KstOu3FoKAnEgjglQKxIX_B77Ped3oDtZ_jut_oFQ24a9SPX_0QiyE2SndJ9-O3z-9PHTz5Ad8GELfLwhzavpL9v3izBBvZIEyhiya1Hwvu9I5IPscCuuFZcLUOuCvwSfLEBHdt3cP_QPUJYiu5aDVEVRD4pVdAs3ugNqrxV_4nlstA3XeLRhd_TJ4hK-QVLOKto2h6pj0EZ-lCv1tCorxbu8LEpifdkXac1rxWvRkaSSD0JxmUql7snQay2p7FP5fi2b-yV8Hx9_fXg4fP79X8v594rhnuCnq_baju81eCSbTNZZLSLVpLxiZVUwqqOpqVNRD7mo1JD1eV0yJSohGU-5KiUn2Ue6IUYZyxlPKc_yOim7ilMnqWay7muWQc7UWWiTGPPlnLh5jPSyBNXwtK4oMqJTZtnuTyKrvuLmXHu6OEVzs8bEXRgXyJnRi19eUbz2RjV3at1dpUDVjwduu4SiMJtm8v6yQHYAaoHaUfspdEm_nqp2TXGb4svs_lC9B2o3YgtQuxH_MwAA___qALeh">