bad optimization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all -

I'm using gcc 4.6.3 and I am getting (what I think is) a bad
optimization on a very simple program:

#include <iostream>
#include <cmath>

int main(int argc, char **args) {

    int i = -2147483648;
    if(std::abs(i) < 0) {
        std::cerr << "correct" << std::endl;
    }
    else {
        std::cerr << "incorrect" << std::endl;
    }

    return 0;
}

When compiled without optimization, this will print "correct".  When
compiled with optimization, "incorrect".  This works with clang.

I can easily work around this problem since there's only one value for
an int for which this will fail.

Is this an example of undefined behavior, or should I file a bug?

Thanks,
  Brian




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux