Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Nov 2002 21:41:42 +0900
From:      TOMITA Yoshinori <yoshint@flab.fujitsu.co.jp>
To:        FreeBSD-current@FreeBSD.ORG
Subject:   gcc 3.2.1 optimization bug ?
Message-ID:  <ywlvg34jn21.fsf@cerberus.proc.flab.fujitsu.co.jp>

next in thread | raw e-mail | index | archive | help
For the source code below, compiling gcc -O2/-O3 seem to produce
incorrect code.

-----------------------------------
#include <stdio.h>
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ywlvg34jn21.fsf>