From owner-freebsd-bugs@FreeBSD.ORG Thu Mar 31 08:50:13 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 27FB01065673 for ; Thu, 31 Mar 2011 08:50:13 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id E18D08FC0C for ; Thu, 31 Mar 2011 08:50:12 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p2V8oC9U035801 for ; Thu, 31 Mar 2011 08:50:12 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p2V8oCrL035799; Thu, 31 Mar 2011 08:50:12 GMT (envelope-from gnats) Resent-Date: Thu, 31 Mar 2011 08:50:12 GMT Resent-Message-Id: <201103310850.p2V8oCrL035799@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Dmitry Afanasiev Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E02E0106564A for ; Thu, 31 Mar 2011 08:45:45 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id CFD1B8FC18 for ; Thu, 31 Mar 2011 08:45:45 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p2V8jjg8048844 for ; Thu, 31 Mar 2011 08:45:45 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id p2V8jj5u048843; Thu, 31 Mar 2011 08:45:45 GMT (envelope-from nobody) Message-Id: <201103310845.p2V8jj5u048843@red.freebsd.org> Date: Thu, 31 Mar 2011 08:45:45 GMT From: Dmitry Afanasiev To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/156082: gcc makes incorrect code when swapping array elements by xor without optimization X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Mar 2011 08:50:13 -0000 >Number: 156082 >Category: misc >Synopsis: gcc makes incorrect code when swapping array elements by xor without optimization >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Mar 31 08:50:12 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Dmitry Afanasiev >Release: FreeBSD 9.0-CURRENT i386 >Organization: >Environment: FreeBSD orion 9.0-CURRENT FreeBSD 9.0-CURRENT #6: Sun Mar 27 03:24:55 MSD 2011 root@orion:/usr/obj/usr/src/sys/orion amd64 >Description: Base gcc 4.2.1 makes incorrect code when swapping array elements by xor without optimization. Simple .c code attached as xor.txt. Checked on FreeBSD 9.0 on i386/amd64/sparc64 platforms. >How-To-Repeat: # gcc -o xor xor.txt # gcc -o xoro1 -O1 xor.txt # ./xor a0 = 127 b0 = 33 a1 = 127 b1 = 33 a2 = 127 b2[0] = 33 a3 = 127 b3[0] = 0 # ./xoro1 a0 = 127 b0 = 33 a1 = 127 b1 = 33 a2 = 127 b2[0] = 33 a3 = 127 b3[0] = 33 But in theory output must be identical. >Fix: Patch attached with submission follows: #include #include int main(int argc, char *argv[]) { int a0 = 33; int b0 = 127; int a1 = 33; int b1 = 127; int a2 = 33; int b2[] = {127}; int a3 = 33; int b3[] = {127}; a0 ^= b0 ^= a0 ^= b0; b1 ^= a1 ^= b1 ^= a1; a2 ^= b2[0] ^= a2 ^= b2[0]; b3[0] ^= a3 ^= b3[0] ^= a3; printf("a0 = %i b0 = %i\n", a0, b0); printf("a1 = %i b1 = %i\n", a1, b1); printf("a2 = %i b2[0] = %i\n", a2, b2[0]); printf("a3 = %i b3[0] = %i\n", a3, b3[0]); return EX_OK; } >Release-Note: >Audit-Trail: >Unformatted: