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

    <tr>
        <th>Summary</th>
        <td>
            LLVM should document the assumptions it makes about the underlying libc
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc
      </td>
    </tr>

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

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

<pre>
    LLVM IR makes some assumptions about how certain `libc` functions behave that are not guaranteed by the C standard. The ones that I am aware of are:
- For memcpy, memmove, memset, memcmp, and bcmp, if the n parameter is 0, the function is assumed to not be UB, even if the pointers are NULL or dangling.
- For memcpy, if `src==dst`, the function is assumed to not be UB even if `n > 0`. (Cc https://github.com/llvm/llvm-project/issues/73516)

Note that I am not talking about clang here, I am specifically talking about assumptions LLVM IR and its backends make -- these are assumptions that all LLVM frontends inevitably inherit. So this is orthogonal to [clang documenting its own assumptions](https://reviews.llvm.org/D86993).

It would be good to get this documented. However, what would be the best place for such documentation?

Also, the second assumption is unnecessary for some of LLVM's frontends: while clang needs it, Rust doesn't. It would be good to provide some way to use LLVM IR and its backends without making that assumption. Currently, Rust will not generate any calls to `memcpy` where `src==dst && n>0`, but there is some risk that an LLVM IR transformation introduces such a call and then we'd accidentally inherit this undesired assumption.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVU1v4zYQ_TX0ZRBBpmx9HHTIxms0RbqHtNs7RY4kNhRpkCML_vcFKdtxF1ug6MUmKA7nzXtvhiIEPVjElu2_sP1hI2YanW_fhel_ne2w6Zy6tG9vf_4Gr-8wiQ8MENyEIEKYpxNpZwOIzs0Eo1tAoiehLbAyN7qTrMyhn61cj3U4ijMCjYJAeATrCIZZeGEJUUF3ARoRXiCQsEp4lcEfI4KzGNaYVxATiCWGuj7ewIpnlh9Y_vwER-dhwkmeLoy_xNXkznhdBqTrSk6nuBJ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