From: Torquil M. S. <to...@gm...> - 2011-08-12 08:16:59
|
Hi! I'm suddenly getting incorrect numerical results when using -O2 with g++ 4.6.1. The culprit seems to be -fstrict-alisasing, since disabling this fixes everything. I posted about my problem on the GCC mailing list: http://gcc.gnu.org/ml/gcc-help/2011-08/msg00168.html Basically, the following program prints the correct result (prints 1.666) when compiling with "-O2 -no-strict-aliasing", but incorrect (prints 0) when using "-O2", with g++ 4.6.1. Using g++ 4.5.3 there is no problem. ------------------------------ #include "iostream" #include "blitz/array.h" int main() { blitz::Array<double,1> X(3); X = 0.0; blitz::Array<double,1> var(1); var = 0.0; for(int i = 0; i != 1; ++i) { for(int c = 0; c != 3; ++c) X(c) = double(c); var(i) = 0.0; for(int c = 0; c != 3; ++c) var(i) += X(c)*X(c); var(i) /= 3.0; } std::cout << var(0) << std::endl; return(0); } --------------------------- The program is a little bit strange, but that only because it is the result of simplifying something else in order to get a minimal example that triggers the error. Initially, my impression was that it is a compiler bug since it worked with g++4.5.3, however I'm posting here as well due to this response from one of the guys at the GCC list: > In every case I've looked at, when code gives the expected answer only > when using -fno-strict-aliasing, it is because the code is using a type > cast in an invalid way. > > In this case I would assume that the invalid type cast occurs in the > blitz library code. Look for invalid type casts there. > > Ian Lance Taylor What do you Blitz+-guys think? I'm using Blitz++ v0.9 on Debian Sid on amd64 architecture. Debian version number is 1:0.9-12 for the libblitz0-dev package. My g++ has Debian version 4.6.1-6. Best regards Torquil Sørensen |