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

    <tr>
        <th>Summary</th>
        <td>
            -fsanitize=object-size reports out-of-bounds access as misaligned access
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    If building the following with `-fsanitize=object-size`, the sanitizer correctly flags the code as UB...
```
#include <stddef.h>

void ReadValueOutOfArrayBoundsRight(char *ptr, size_t size) {
  char c = ptr[size + 1];
}

int main() {
  char foo[16];
 ReadValueOutOfArrayBoundsRight(foo, 16);
}
```
https://godbolt.org/z/e4oWfYdPG

However, the error it outputs is:
```
/app/example.cpp:4:12: runtime error: load of misaligned address 0x7ffcd4609ba1 for type 'char', which requires 2 byte alignment
```

This does not make sense because `char` does not require 2 byte alignment, and indeed the alignment is just fine. It's just out of bounds.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVMuu4zYM_RpmQ8SQJT_ihRfJTdPOaopBH-iqkC0q1lSxXD2SyXx9ISfTudPeooAhQSJ5eMhDWYZgzjNRD_UB6uNGpjg53yt5NWqgeTM4de_faRySscrMZ4wToXbWuls-3UycEBq21UHOJprPBOLoho80xm3Ip4YBf1mDvjh4HJ33NEZ7R23lOazW0SlCGfDnQ1EUwI7A9jn28T2OXJh5tEkRgngJUSnSxQTiu6d5Xa_OKPxAUv0ibaL3Kb7Xe-_l_eDSrMIHc54i8N04SY_A90v0mV0m-ntcN-AdQnt4gCGujiOCOGL2rQ_ZB4EfsIT6COLpCO3xNQkzR7xIMwPfvYWnnYP6UDavEf6fc47iL1g2wLs3En_bqynGJYDYAz8BP52dGpyNhfNn4KfPwE9UuV_1b-rH71_T_sHd6Er-i17kvfNoIroUlxQDmhXxbWlOclky7id5WSwV47KA2Fcg9iUHsUef5mguT8x8YZ1U6DReTJA2D6BCqZSnEJB9arUeVdWwbpAlaucx3pfc9Ta3D3ibGd4mM07o6c9kPAXkONwj4Yp1oTm-TXNdf5pMQOUo4OyyTn8QBpoD4UCjTIHyOK-JGvbV7Zno33n4C8pZoZkVkVr79rcNTcCPKUTUZqYC30Xg7fPGpZirH1aFi43qhepEJzfUl22563Ydq-rN1NcjyabrBO1kwxQTrOsqrmtW81I0JOqN6TnjFWt4WTZ1y-uilE27ayvFNFGnywoqRhdpbGHt9ZIHYGNCSNR3jRBiY-VANqxPn_OZbrgagfP8J_B9jtkO6RygYtaEGL6iRBMt9f_16tHT4nwMuc6t09tHnSjHMQsswzeyr5eb5G3_j6k1cUpDMboL8FNO_Ny2i3c5E_DTSjcAPz3Kufb8rwAAAP__MqaAMQ">