This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/79174] New: xorswap *x^=*y^(*y=*x) : sometime don't work with optimisation
- From: "leguirec_alain at yahoo dot fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 21 Jan 2017 12:45:56 +0000
- Subject: [Bug c/79174] New: xorswap *x^=*y^(*y=*x) : sometime don't work with optimisation
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79174
Bug ID: 79174
Summary: xorswap *x^=*y^(*y=*x) : sometime don't work with
optimisation
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: leguirec_alain at yahoo dot fr
Target Milestone: ---
this code don't work with optimisation -O1 or -O2
int x=1, y=3;
int *px=&x;
int *py=&y;
*px^=*py^(*py=*px);
printf("x=%d y=%d\n",x,y);
without -O2 -> x=3 y=1
with -O2 -> x=1 y=1
The swap is useless so the optimisation remove it from the code, it's ok, but
the first parameter send to printf is wrong.
400440: ba 01 00 00 00 mov $0x1,%edx
400445: be 01 00 00 00 mov $0x1,%esi
40044a: bf e0 05 40 00 mov $0x4005e0,%edi
40044f: 31 c0 xor %eax,%eax
400451: e9 ba ff ff ff jmpq 400410 <printf@plt>
see on gcc 4.8.5 on centos 7