[FFmpeg-devel] [RFC] Sechole in gcc 3.3+ and 4.*

Uoti Urpala uoti.urpala
Mon Apr 7 14:38:31 CEST 2008


On Mon, 2008-04-07 at 14:18 +0200, Michael Niedermayer wrote:
> int func(int len){
>     if(len+100 < len)
>         return 1;
>     return 0;
> }
> 
> Just to find out that all versions of gcc i have installed except 2.95
> optimize this away at -O2 or higher.
> 
> If one uses -fwrapv than gcc 4.* seems to leave the check in there but
> 3.4 does still remove it and 3.3 does not support -fwrapv.
> 
> AFAIK addition of signed integers is not an undefined operation in C.

I'm not sure what you'd mean by "addition being an undefined operation".
Overflow in signed integer arithmetic is undefined behavior.

> I also failed to find a mentioning of signed integer addition in the
> list of undefined things in the C standard, it only mentions
> pointer+integer being undefined in some cases.

---
Part 6.5 Expressions:
If an exceptional condition occurs during the evaluation of an
expression (that is, if the result is not mathematically defined or not
in the range of representable values for its type), the behavior is
undefined.
---

If the sum of signed variables overflows the above applies. The unsigned
behavior of always reducing mod size (which means the result is always
representable) is described elsewhere.





More information about the ffmpeg-devel mailing list