This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Linking Program with Lib That Uses -fwrapv or '-fno-strict-overflow'
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.
Ian