<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61098>61098</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang's static analyzer should be able to warn when memset()/memmove()/memcpy() are optimized away by dead store elimination
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ryao
</td>
</tr>
</table>
<pre>
`memset()` is often used for data sanitization in encryption code. In a project that I regularly scan with Clang's static analyzer, we recently found some memset() operations meant to protect against information leaks in encryption code were optimized away by dead store elimination.
The optional [security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C)](https://clang.llvm.org/docs/analyzer/checkers.html#id87) check will warn about any usage of `memset()`/`memmove()`/`memcpy()`, but this seems extreme since there are no safe alternatives to `memmove()`/`memcpy()` and for initialization, `memset()` is perfectly safe to use. It would be more useful if a check were made that warns whenever dead store optimization should eliminate a memset()/memcpy()/memmove() operation. The commercial static analyzer, PVS Studio, already does this, but it is prohibitively expensive for open source projects.
https://pvs-studio.com/en/docs/warnings/v570/
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMlM-O4ygQxp-GXEptOaTjOAcf-o-i7dOONLt7L0PZZgeDReFk3E-_giSbjqZH6ksCWFBV3_erQmbTO6JGbJ_F9nWFcxx8aMKCftV6vTSiKkcamaKQtZB7UZVgGHwXycHMpKHzATRGBEZnonnHaLwD44CcCsuUd8prKuDNAcIU_L-kIsQBI7xBoH62GOwCrNDBycQBXiy6XsgdA0eMRgE6tMs7BSFf4EQQSJGLdoHOz04D-5HgY47gJwo5DYaR0EWIPsWNKS72aBxHMK7zYTwnawl_8Ccpw4kCgZ-iGc07acATLtAuoAk1cPSBgKwZjcvPFKJ8FeXT-fev4XzRO7Qgts9Mag4mLoVxeUlP396KV5oCKYyk_wx_O8aOnueuo_AHOm2N60HI-iWJvn0Vsh5inFhsnoQ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