Linking Program with Lib That Uses -fwrapv or '-fno-strict-overflow'

Jeffrey Walton noloader@gmail.com
Tue Jul 26 05:51:00 GMT 2011


On Tue, Jul 26, 2011 at 1:49 AM, Ian Lance Taylor <iant@google.com> wrote:
> Jeffrey Walton <noloader@gmail.com> writes:
>
>> A simplified example (I know you gave a previous work around) assuming
>> 32 bit ints:
>>
>> // liboverflow, compiled with -fwrapv
>> int my_abs(int x, int* r)
>> {
>>     int y = abs(x);
>>     if (y < 0)
>>         return 0;
>>
>>     *r = y;
>>     return 1;
>> }
>>
>> // myprogram, compiled with -O2 and linked against liboverflow
>> int x = 0x80000000, r = 0;
>> if(my_abs(x, &r))
>>     printf(...)
>>
>> Will the resulting program enjoy O2 and/or produce incorrect results?
>
> If you are asking whether this program has signed overflow problems, the
> answer is no.  Compiling liboverflow with -fwrapv does not affect
> myprogram.  Similarly, compiling myprogram without -fwrapv does not
> affect liboverflow.
As always, thank you very much.

Jeff



More information about the Gcc-help mailing list