This is the mail archive of the 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 Mon, Jul 25, 2011 at 8:43 PM, Ian Lance Taylor <> wrote:
> Jeffrey Walton <> writes:
>> Is it possible to build a library which specifies -fwrapv or
>> '-fno-strict-overflow' but does not penalize the final executable
>> (with respect to optimizations) after final linking?
>> The question arises from a library which detects wrap/carry/overflow
>> and might need to specify -fwrapv or '-fno-strict-overflow' to take
>> advantage of 2s compliment math used on many modern architectures.
> I'm not sure I understand the question. ?The -fwrapv and
> -fno-strict-overflow options only affect the compilation of the code
> with which they are used. ?They do not affect code which is compiled
> without those options. ?They do not affect the linker. ?So the answer to
> your question may be that you should just use the options with the
> specific code that needs them. ?If the answer doesn't make sense, can
> you restate the question?

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))

Will the resulting program enjoy O2 and/or produce incorrect results?


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