From owner-freebsd-current Mon Nov 11 4:41:55 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DCCDC37B404 for ; Mon, 11 Nov 2002 04:41:53 -0800 (PST) Received: from fgwmail6.fujitsu.co.jp (fgwmail6.fujitsu.co.jp [192.51.44.36]) by mx1.FreeBSD.org (Postfix) with ESMTP id 23EB543E42 for ; Mon, 11 Nov 2002 04:41:52 -0800 (PST) (envelope-from yoshint@flab.fujitsu.co.jp) Received: from m4.gw.fujitsu.co.jp by fgwmail6.fujitsu.co.jp (8.9.3/3.7W-MX0205-Fujitsu Gateway) id VAA03859 for ; Mon, 11 Nov 2002 21:41:43 +0900 (JST) (envelope-from yoshint@flab.fujitsu.co.jp) Received: from cerberus.proc.flab.fujitsu.co.jp by m4.gw.fujitsu.co.jp (8.12.1/Fujitsu Domain Master) id gABCfhMe003287 for ; Mon, 11 Nov 2002 21:41:43 +0900 (envelope-from yoshint@flab.fujitsu.co.jp) Received: from cerberus.proc.flab.fujitsu.co.jp (localhost [127.0.0.1]) by cerberus.proc.flab.fujitsu.co.jp (8.12.6/8.12.5) with ESMTP id gABCfg1x017587 for ; Mon, 11 Nov 2002 21:41:42 +0900 (JST) (envelope-from yoshint@flab.fujitsu.co.jp) To: FreeBSD-current@FreeBSD.ORG Subject: gcc 3.2.1 optimization bug ? From: TOMITA Yoshinori MIME-Version: 1.0 (generated by WEMIKO 1.14.1 - =?ISO-2022-JP?B?Ig==?= =?ISO-2022-JP?B?GyRCNl9KXExTQ24bKEIi?=) Content-Type: text/plain; charset=US-ASCII Date: Mon, 11 Nov 2002 21:41:42 +0900 Message-ID: User-Agent: T-gnus/6.15.8 (based on Oort Gnus v0.08) (revision 05) Mule-UCS/0.84 (=?ISO-2022-JP?B?S09VR0VUU1VEQUk6GyRCOH43bkJmGyhC?=) WEMIKO/1.14.1 (=?ISO-2022-JP?B?GyRCNl9KXExTQ24bKEI=?=) SLIM/1.14.7 (=?ISO-2022-JP?B?GyRCPHIwZjpMTD4bKEI=?=) APEL/10.3 MULE XEmacs/21.4 (patch 9) (Informed Management) (i386-unknown-freebsd4.6) Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG For the source code below, compiling gcc -O2/-O3 seem to produce incorrect code. ----------------------------------- #include int main(int argc, char* argv[]) { unsigned int x = 0x12345678; unsigned short tmp; printf("%x\n", x); tmp = ((unsigned short *)&x)[0]; ((unsigned short *)&x)[0] = ((unsigned short *)&x)[1]; ((unsigned short *)&x)[1] = tmp; printf("%x\n", x); return 0; } ----------------------------------- % gcc -O1 a.c % ./a.out 12345678 56781234 % gcc -O2 a.c % ./a.out 12345678 12341234 % gcc -v Using built-in specs. Configured with: FreeBSD/i386 system compiler Thread model: posix gcc version 3.2.1 [FreeBSD] 20021009 (prerelease) Is this a gcc bug or the source code problem ? To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message