This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]