GCC 3.2.x and 3.3 generate incorrect code for the simple test case below. The problems occurs, if the C code is compiled with -O2, but does not occur at -O1 or "-O2 -fno-schedule-insns2" (->GCC does invalid instruction reordering ?). The problem disappears, if uint_value is declared as volatile. The correct output for the test program is : uint_value : 00570047 , value 00570047 ... uint_value : 006B005B , value 006B005B Whereas the miscompilation with -O2 gives : uint_value : 00570047 , value BFFFF8E8 ... uint_value : 006B005B , value 00660056 I have the same problem on gcc/x86-64, but the code works OK with the Intel compiler. #include <stdio.h> typedef unsigned int UInt32; typedef unsigned int UInt16; typedef float Float32; float f_array[25]; UInt32 u32_array[25]; int j = 5; inline void func(UInt32 count, UInt32* address, volatile Float32* float_value) { unsigned int i; UInt16 value_low = 0x42; UInt16 value_high = 0x52; /*volatile*/ UInt32 uint_value; for (i = 0; i < count; i++) { value_high = value_high +5; value_low = value_low +5; uint_value = (((UInt32)value_high) << 16); uint_value |= value_low; float_value[i] = *((volatile float*)(&uint_value)); printf(" uint_value : %08X , value %08X \n", uint_value, *((UInt32 *) &(float_value[i]))); } } int main() { func( j, u32_array , f_array); }
*** This bug has been marked as a duplicate of 5328 ***