how to make gcc warn about arithmetic signed overflow

Dave Allured - NOAA Affiliate dave.allured@noaa.gov
Mon Sep 23 20:37:00 GMT 2013


On Mon, Sep 23, 2013 at 1:42 PM, Oleg Endo <oleg.endo@t-online.de> wrote:
> On Mon, 2013-09-23 at 13:38 -0600, Dave Allured - NOAA Affiliate wrote:
>>
>> I believe the CPU overflow flag is updated after most integer
>> arithmetic instructions.  Does GCC have any facility for checking this
>> flag after each integer operation?  This would be a runtime check, of
>> course, not a compile time check.
>
> See -ftrapv option.  Although trapping math is not supported on every
> target properly.
> E.g. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35412
> or SH related http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54272

Oleg, thanks for the tip.  "-ftrapv is seriously broken and nobody
wants to fix it", and that was 5.6 years ago.  Too bad, it seems like
a useful thing when you need it.  I use gcc's -ffpe-trap routinely to
guard fortran floating point stuff, and it has done many favors for
me.

--Dave



More information about the Gcc-help mailing list