[cfe-dev] Strict overflow warning

Richard Smith richard at metafoo.co.uk
Fri Sep 21 14:22:47 PDT 2012


On Fri, Sep 21, 2012 at 3:19 AM, Richtarsky, Martin <
martin.richtarsky at sap.com> wrote:

> Hi Martin,
>
> 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.
>
> Dmitri
>
>
> Hi Dimitri,
>
> 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).
>

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.

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120921/6144d927/attachment.html>


More information about the cfe-dev mailing list