This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization bug gcc 4.1.2
- From: "Fomin Eduard S." <fomin at bionet dot nsc dot ru>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 29 Aug 2008 13:27:41 +0700
- Subject: optimization bug gcc 4.1.2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
inline double abs(double x)
{
// remove sign bit
*reinterpret_cast<long long int*>(&x) &= 0x7FFFFFFFFFFFFFFFLL;
return x;
}
int main(int argc, char *argv[])
{
std::cout << "abs = " << abs(-2.1) << std::endl;
}
This simple code works correct in DEBUG. But it works INCORRECT in
release (-O2)
gcc 4.1.2/4.1.1
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFIt5bdzcPJMsK6QP8RAgvfAJ94tuXYQIGzBfktUi3dkQcXSsigzQCZAbAF
fxSsDpV4w7VoCv6Y06wSscs=
=1PBk
-----END PGP SIGNATURE-----