<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55772>55772</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
InstCombine's strcpy(x,x) -> x transformation removes ASan overlapping-memory checks
</td>
</tr>
<tr>
<th>Labels</th>
<td>
compiler-rt:asan,
llvm:instcombine
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Teemperor
</td>
</tr>
</table>
<pre>
Note: This bug is mainly interesting for [this RFC](https://discourse.llvm.org/t/rfc-safe-optimizations-for-sanitizers/62729). See also issue #55595 and the linked bugs from there.
Example: This triggers an ASan assert in O0 but not with O1.
```cpp
#include <string.h>
int main(int argc, char **argv) {
char m[3] = {'a', 'b', '\0'};
return *strcpy(m, m);
}
```
https://godbolt.org/z/h5he4hrdM
The relevant code in InstCombine is:
```cpp
Value *LibCallSimplifier::optimizeStrCpy(CallInst *CI, IRBuilderBase &B) {
Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1);
if (Dst == Src) // strcpy(x,x) -> x
return Src;
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VMFuozAQ_RpysRIRE0I5cEhIK0Xa3Uqbau8GBvDWYGSbbNqv32eSpmmrXQQYbL83M29mXOjqJfuhHQXRhj210rJibBiGTshevTDZOzJknewbVmvDgnjr_K6fD3kQ7wJ-1zo3WIAD_oC7krbUo7G0UOrYLbRpMOnwmLqcW1HTXA9OdvJVOKl7Owclpnvp5CsZi31rnvA04OmCHYiYUFbDGTsSC3gUx3EaM9FXzLXElOyfqfLuWlYb3flJQ4sg3AXh5vy-P4luUO-hOSObBnbAwTYHvIS1ZByCZI8hmBzrtWN_pGvZ4_KNaR2e73IYLjM8kn2pxgpORbkFad8s2iC6vzUN3SYJoZD_FKYpA56zshXQkINjg6kjAmVBsj1DGK5pvYPIEdQF_W5a5onA4_EYivfPIM5DPyS7ILohMeRG03szcK4cXuBD5xF4pdeNHvQxwPPvx3w2uiq0cpdEvuJp45ZWram-30b7hHwYUnQUiLXUUAaS7nvrct0VssfvRHmD-CrrL6GmNG--ySIXSh0kcidrScZDo82lcOjgTD7F5Dd5Gx6T732A-5_bUaqKzFZYT7XefhL4amPnYVA338-RuIbcxjSPAxkUF5hDL9Qk8eZgyv9sXN4qypisAbm7cHsU0JMHk5bsmo0TyE9-gXlSdvqSOo-7JupNqVmVRVUapWLmpFOU3eiLIrD_pkfdi96i1bqp62Ck00ey5xbAl1FiGFDE8w4L5gVFSOWznY1GZZ-qAZ0xFotSo5IefINfhvlg9G8qfZ9PzeobOY6ThM_abBlTmhT4Sfl6FVZ30SqtllWyDHlcp9GqmClRkLIZaj7gHNSDVGTmxsGqwNGAyXMq-GQwQmdZV76FzdEmM5nxkPMwjsIw4Wu-XFQ1r-rlKr5bh-EqKniwCgnNqK6H0sxkk9_-8MCiktbZ90WcCrLpiSafwC9G12qTPRF1yLw2synIbIrwL38akZU">