Re: Is it OK that gcc optimizes away overflow check?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 23/07/11 21:13, Agner Fog wrote:
> I have a program where I check for integer overflow. The program failed, 
> and I found that gcc has optimized away the overflow check. I filed a 
> bug report and got the answer:
>> Integer overflow is undefined. You have to check before the fact, or compile
>>>  with -fwrapv.  
> ( http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49820 )
>
> 5). I have tested many different C++ compilers, and gcc turned out to be 
> the one that optimizes best.

Well yes, and one of the reasons for this is that we take advantage of
integer overflow being undefined.  There is an entire class of
optimizations (loop induction variable optimization) that is difficult
of impossible without taking advantage of this.  We don't do this kind
of thing without good reason.

We can't promise you that in every case gcc will do what you would
like it to do,  However, we have thought long and hard about it.

Andrew.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux