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

    <tr>
        <th>Summary</th>
        <td>
            Clang does not recognize hand-written buffer aliasing checks
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Clang (and GCC) don't seem to recognize the `__fh_overlap` macro in https://godbolt.org/z/EqjKe716r as a buffer aliasing check.

The sample was adapted from https://github.com/jvoisin/fortify-headers/blob/master/include/string.h, which is reportedly used in Musl-based Linux distributions like Alpine.

In this case, since `r` was just allocated, the compiler should be able to reason that `r` cannot overlap with `a` and delete the `__fh_overlap` check. It's also important to be able to optimize this because `memcpy` is the usual pattern to load memory without tripping strict aliasing issues.

CC @andres-erbsen
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8U02P4zYM_TXyhUjgyM6HDz5M07pYtL31PqAkJtasLLkilWn21xfKBJ2iaPdkGJLeI98HMvtrJBrV_ge1_7HBInPKo8Obd4ZiY5K7j-eA8QpKnzA6-Pl8VnoAl6LSRwEmWkASZLLpGv03ApkJ1KF9fb3Mr-lGOeCqDi0saHMCH2EWWVl1L0pPSk_X5EwKsk35qvT0Tenppz_efqHj7pABGRBMuVwoAwaP7OMV7Ez261a1L6p9-X0mYFzWQPBeLztchRxcclr-TeNlLmZr06L09HZLnn1UerqkLP5y38yEjjIrPZmQjNLTgiyUlZ58tKE4UnpiyT5et7PSZ3ifvZ3BM2RaUxZy4Q6FydX9fiscNgbr368-lj_B-frUFPEpMgT_leAlrD7Sc4svEWT2DBaZKjj7aB8S5qpbXeytsACGkCwKuXqnimzTsvpAGXhOJTgwBGgCfbiBnCosyt9AFmNMAk9L4N3LXM-wnlVjHQWS_7XvQ3b4IkofGTBwAr_U3TFKZfwHeVrFLx9J8AyGLBZ-YC602PVe0Tw_eAoXDLCiCOVYn4aEDhZaUr4_BkxFQLJf1-p8VdHKZxI8cyF-ing-g-pbjC4Tbygbpti4sXNDN2BD4-6433XtaXccmnnsDju374_u2Fl7aKkje2qH3nTmZLAd-r7xo271vj107e6kh27YDqbru6N2nSU8mN6ovqUFfdiGcFtqdpvHMOOuP_TtrgloKPCjU1rb2h6lda1XHuuDjSlXVn0bPAt_QoiXQM-yuUQM1a7PXs0Y3eY9exGK_90KbkoO43eCX6men82a0xtZqRF_6Kj09Jz-Nuq_AgAA___YRF_D">