$ gcc -v Reading specs from /pdv/.tools/pkg/gcc/3.4.3/bin/../lib/gcc/powerpc-ibm- aix5.2.0.0/3.4.3/specs Configured with: ../gcc-3.4.3/configure --prefix=/tools/pkg/gcc/3.4.3 --with- ld=/bin/ld --with-as=/bin/as --disable-threads --enable-languages=c,c++ Thread model: aix gcc version 3.4.3 // foo.c // #include <stdio.h> inline void reverse( char* beg, char* end ) { while( beg < --end ) { char t = *end; *end = *beg; *beg++ = t; } } void doIt( int* val ) { reverse( (char*)val, (char*)val + sizeof( *val ) ); } int main() { int d = 0x12345678; printf( "%x\n", d ); doIt( &d ); printf( "%x\n", d ); return 0; } //// $ gcc -o foo foo.c -O2 $ foo 12345678 78345612 $ gcc -o foo foo.c $ foo 12345678 78563412 Works with GCC 3.3.3
This appears to be related to strength reduction. -O2 -fno-strength-reduce succeeds -O1 -fstrength-reduce fails. The bug is not present in GCC 4.
won't fix for 3.4.6