From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3081 invoked by alias); 7 Jun 2009 07:15:47 -0000 Received: (qmail 3019 invoked by uid 48); 7 Jun 2009 07:15:34 -0000 Date: Sun, 07 Jun 2009 07:15:00 -0000 Subject: [Bug c/40366] New: Array + XOR swap fails X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "ashutosh dot sharma dot 0204 at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2009-06/txt/msg00369.txt.bz2 Compiler Version: gcc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu3) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Sample code: #include int main() { int a[2]; a[0]=10; a[1]=20; printf("a[0] = %d a[1] = %d\n", a[0], a[1]); a[0]^=a[1]^=a[0]^=a[1]; printf("a[0] = %d a[1] = %d\n", a[0], a[1]); return 0; } gcc test.c -o test -O2 a[0] = 10 a[1] = 20 a[0] = 20 a[1] = 10 gcc test.c -o test -O0 a[0] = 10 a[1] = 20 a[0] = 0 a[1] = 10 Bug: When compiled with -O0 swap fails. Swap only fails in case of array. Following code works fine with -O0: #include int main() { int a, b; a=10; b=20; printf("a = %d b = %d\n", a, b); a^=b^=a^=b; printf("a = %d b = %d\n", a, b); return 0; } -- Summary: Array + XOR swap fails Product: gcc Version: unknown Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ashutosh dot sharma dot 0204 at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40366