On Fri, Sep 21, 2012 at 3:19 AM, Richtarsky, Martin <span dir="ltr"><<a href="mailto:martin.richtarsky@sap.com" target="_blank">martin.richtarsky@sap.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">Hi Martin,<br>
<br>
I don't think there is such warning in clang, but you could use the -fwrapv option to define signed integer arithmetic to wrap around on overflow -- this is the easy option.  You could also use the -fcatch-undefined-behavior option to catch signed overflow at runtime and turn it into a crash so that you can debug and fix it.<br>

<br>
Dmitri<br>
<br>
<br>
</div>Hi Dimitri,<br>
<br>
yes, -fwrapv or -fno-strict-overflow could be used here. But I would like to see which places are affected, so it would be great if -Wstrict-overflow would work. The option also seems to be recognized by the driver otherwise there would be a warning. It just does not seem to work internally which is bad if you rely on it (e.g. porting a GCC codebase).<br>
</blockquote><div><br></div><div><div>Clang deliberately does not have any warnings which are dependent on optimization level, or any warnings which are produced by the optimizer. GCC's warnings in this category tend to be flaky and very version-dependent, have false positives (due to dead code after inlining, usually), and can't preserve enough information to provide useful diagnostics.</div>
</div><div><br></div><div>We have checking for some specific forms of overflow at compile time, but nothing flow-sensitive like this. It would probably be relatively straightforward to add overflow checking to the static analyzer, if you're interested in doing so. If you want to catch this problem at runtime, you can use -ftrapv or -fcatch-undefined-behavior as Dmitri suggested.</div>
</div>