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

    <tr>
        <th>Summary</th>
        <td>
            memcpy -> load/store transformation removes overlapping sanitizer checks.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            compiler-rt:asan,
            llvm:optimizations
      </td>
    </tr>

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

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

<pre>
    Note: I'm aware that enabling optimizations with sanitizers might break stuff. This bug is part of an [RFC](https://discourse.llvm.org/t/rfc-safe-optimizations-for-sanitizers/62729) to document and fix these issues.

InstCombine currently transforms memcpy with a 1/2/4/8 size parameter to a load/store pair. This is a valid transformation, but in the case of overlapping memory areas the ASAN-interposed memcpy would abort (and the load/store pair doesn't do this check obviously). Note that this even happens on O1 (which is the recommended opt level for ASan).

https://github.com/llvm/llvm-project/blob/f37101983fc9fabbbde4b10f613ed248a424d71a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp#L152

Also an example of this bug hidden in the wild in httperf:

https://github.com/httperf/httperf/blob/c657cb4a291258ad864d5bec56ab77d3a4c5fcf9/src/gen/wsesspage.c#L394
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVN2O4yYUfhrnBsWy8f-FL9KZjrRStZXaeYEDHGK62FiAk80-fQ9JdibR3rRSHLCB8_2czxZOXcavLmJWHdiXjHczgzN4ZHGCyHABYc1yZG6NZjY_IBq3BHY2cWIBFhPND_SBzeY4RSY8wjcW4qZ1zt4nE5jYjoyGFXxkTjNYWNb89tfbS9a8ZryfYlwDwWb8jX7KBOk2HzC39jTnzh_pYaTLa7kPoHH_xGGvnd9_UqB9Le_4kPGBRceUk9uMSyRIxbT5TmowIHEJG4Y8K16z4nD7_7KE-OJmYRZkcvOeDtkLix6WQAgzacNZrpebZGAlAXG6arp6Fgg7qYMZI_oEDMw6ULQYovNpzfi7F_QDdgJr1Gf1q5SMv5BRkZklsWQSiCiZ5U7oLaxrcp84OH9h1BYI102Hvw9f92Yh0NUFVB8k3WYVA-HIbzI4iU-7f6FE_mAg4C7SjLYQNzmh_MacOBm3BXshH3OWYnHLwXULnnBhE1FCioBb2J9lAjlPRk5JXULyKN1MxiviRO1ils5YRlKJMSyp6KP3zwE4ksObyKkA3aQM3If96t0_KFMUhHWCBl11ZVEOfaXloEEIobAWZaHbskLF6x5qXquuhIc6Jp17_-gq3Tw0_vnuBawNuVzXjFd_lA1_ZHywwaUY43eYV3vtU_wZ9MkoRQbd23g21AmaJ43odVL535T_PPA4u-uWbdNJUQMfSt70oPq2Vo1A2bQguk5VUMtGSz2kXnuZCiN5_nYOGMIKR8xlklQN9U6NlRqqAXbRRIvjPT77rPr9OSzPSaX2zhTL8JTNj3fwFqGQ7zZvx__d2turSZOmabt-N40VL3petaJtOUoUfVUL3dda6aZBAI47CwJtGOmLknFOpVdj0e99JFQIKWw8vVk0XAGrw9PnI602rzsz8oLzouF1SXhlnxdatwM969tCdpWSWV3gDMZ-fJR2frwyp44HWrQmxPC5CCGY44J4ZUX1YYuT8-M74kytdH53lTleNf4LRr_T6Q">