[cfe-dev] Strict overflow warning

Dmitri Gribenko gribozavr at gmail.com
Fri Sep 21 01:37:06 PDT 2012

On Friday, September 21, 2012, Richtarsky, Martin wrote:

> Hi all,
> a few days ago I ran across code that relied on signed overflow being
> defined. With gcc this worked fine, clang optimized and the program broke.
> With gcc it is possible to specify -Wstrict-overflow=x to get a warning in
> cases where the compiler relies on undefined behaviour (which will usually
> happen only with -O2 or above).
> I tried this with clang, but got no warning (but clang seems to know the
> option). Am I  doing something wrong?

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.


(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120921/d8e93ebe/attachment.html>

More information about the cfe-dev mailing list