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

    <tr>
        <th>Summary</th>
        <td>
            Sanitize store to constants
        </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>
    Since [D60659](https://reviews.llvm.org/D60659) LLVM is completely removing stores to constants in InstCombine. This can transform a program that might crash with a segfault into a program that runs just fine.

This has been brought up in the [commit email thread](https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20190422/647341.html) with the suggestion to add a new sanitizer check for this case. There doesn't seem a bug report tracking this so I decided to file this one.

I checked all Ubuntu packages and checked where this optimization is actually applied and from what I can see this is happens just 3 times:
* In Chrome's zlib where the respective BB seems unreachable.
* busybox (as pointed out in the commit thread). Note that this bug was only fixed about 6 months ago and it seems to rely on inline assembly (just from looking at the code I am not sure if this is actually fixed and they already tried to fix this with 3 patches so far).
* Some [binary in the jackd audio daemon](https://github.com/jackaudio/jack-example-tools/pull/68) ended up falling to this C pattern:
```
                char *invalid_flag = "'- '";
                invalid_flag[2] = c;
                print_msg(invalid_flag);
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VE1v4zgM_TXJhUjg-CNpDj6kDRYoMLOXzu4eB7JN22plyZDkpOmv3yc5zUyL7iZGYn2QfHx8ZGWaS_kkdc20KO6P22Rb7BfFcZHe9d6PbpEdFukfeCyfJJ_dWqnTsDa2w9b1crqnb9_-_k7SUW2GUbFndSHLgzlJ3ZHzxrIjb3CqnRfaO5KaHvH-YIZKal7Tjz4YC03eCu1aYwcSNFrTWTGQ74WnQXa9p9oK19NZ-h7njrtWTMrDG5x_um8n7eh5cp7aEGGRHBfJYf6NwXrhqGLWVFkzBdf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