sample code:
#include <stdio.h>
int main()
{
char cp[2];
cp[0] = 'A';
cp[1] = 'B';
printf("%x %x\n",cp[0],cp[1]);
cp[0] ^= (cp[1]^=(cp[0]^=cp[1]));
printf("%x %x\n",cp[0],cp[1]);
return 0;
}
The complex byte swapping instruction is far fetched but seems legal.
It actually swaps bytes if compiled with "gcc -O3". Without optimization,
one of the bytes receives a '\0'.
This instruction seemed to work properly with versions 3.
Environment:
System: Linux lpnp204 2.4.21-47.0.1.EL.cernsmp #1 SMP Thu Oct 19 16:35:52 CEST
2006 i686 i686 i386 GNU/Linux
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure
How-To-Repeat:
Compile the code above with various degrees of optimization.
--
Summary: wrong generated code on complex statement;
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: astier at lpnp204 dot in2p3 dot fr
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32536