Bug 32536

Summary: wrong generated code on complex statement;
Product: gcc Reporter: astier <astier>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Severity: normal CC: alexey, algorithmus, asokumar, astier, av1474, bala, barnarr, behloul.younes, bmead15, buergel, carpman, chuchunxin, devnull, d_picco, eric.mcvicker, fuchsia.groan, gaurav_har, gcc-bugs, gcc, ggs, j.witteveen, jandres, janis, jesser, jompo, krs, lid, lindahlb, lxg8906, mayer, mikaldaz, mike.clarkson, nakkore, nanericwang, nobs, pierre.van.de.laar_at_philips.com, qyang, ramiller, raoulgough, raphael.ribas, rglan, rjvbertin, robc, s9322036, SimonX200, smartmouse714, suan, super.aorta, svetozarmarkov, tczarnecki, vanveghel, vitaly, windows2000d, zshao
Priority: P3    
Version: 4.2.0   
Target Milestone: ---   
Host: i686-pc-linux-gnu Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu Known to work:
Known to fail: Last reconfirmed:

Description astier@lpnp204.in2p3.fr 2007-06-28 15:15:35 UTC

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.

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

	Compile the code above with various degrees of optimization.
Comment 1 Andreas Schwab 2007-06-28 16:54:52 UTC
You are modifying the same object twice between two sequence points.

*** This bug has been marked as a duplicate of 11751 ***