Traps for signed arithmetic overflow

Marc Glisse marc.glisse@inria.fr
Fri Nov 23 21:36:00 GMT 2018


On Fri, 23 Nov 2018, Helmut Eller wrote:

> On Fri, Nov 23 2018, Marc Glisse wrote:
>
>> On Fri, 23 Nov 2018, Helmut Eller wrote:
>>
>>> when compiling this example with gcc -O2 -ftrapv:
>>> [...]
>> Try with "-fsanitize=undefined
>> -fsanitize-undefined-trap-on-error". -ftrapv is quite broken and not
>> really maintained. I think fixing it would mean making it an alias for
>> the sanitizer version.
>
> Thanks for the quick reply.  That does indeed produce exactly the code I
> want.
>
> It doesn't seem so detect overflow for short or char types, though:

That's because there is no overflow. Read about integer promotion.

> For __int128 it seems to be detected again, but the code seems very
> long-winded.

Feel free to search for an existing report in gcc's bugzilla and file a 
new one if you can't find it, if there is a missed optimization.

-- 
Marc Glisse



More information about the Gcc-help mailing list