The following program produces wrong results at -m64 -O3:
// a.cc
#include <iostream>
#define N 5
void
cvt_u4_f4(int n, unsigned int* u4, float* f4)
{
for (int j=0; j<n; j++)
f4[j]=u4[j];
}
int main()
{
unsigned int u4[N];
float f4[N];
for (unsigned int j=0; j<N; j++) u4[j]=4000000000u+j;
cvt_u4_f4(N, u4, f4);
for (int j=0; j<N; j++) std::cout << f4[j] << std::endl;
}
g++-4.4 -m64 -O3 a.cc && ./a.out prints:
-2.94967e+08
-2.94967e+08
-2.94967e+08
-2.94967e+08
4e+09
At -O0/-O1/-O2 the results are correct:
4e+09
4e+09
4e+09
4e+09
4e+09
--
Summary: wrong conversion from unsigned int to float
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: foldy at rmki dot kfki dot hu
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40809