public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/6064: byte swap function returns bad value
@ 2002-03-26  8:16 dp
  0 siblings, 0 replies; 2+ messages in thread
From: dp @ 2002-03-26  8:16 UTC (permalink / raw)
  To: gcc-gnats


>Number:         6064
>Category:       optimization
>Synopsis:       byte swap function returns bad value
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 26 08:16:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     David Pinedo
>Release:        gcc-2.96-85
>Organization:
>Environment:
Red Hat Linux 7.1 plus some errata
gcc rpm is 2.96-85
Pentium III processor
>Description:
Compile and run the following program:

    unsigned int byteSwap(unsigned int * word)
    {
        char* byte;
        unsigned int *uip;
        char newWord[4];
        byte = (char*) word;
        newWord[3] = *byte++;
        newWord[2] = *byte++;
        newWord[1] = *byte++;
        newWord[0] = *byte++;
        uip = (unsigned int*)newWord;
        return *uip;
    }
 
    main(int argc, char **argv)
    {
        unsigned int ui;
        ui=0x11223344;
        printf("%08x\n", byteSwap(&ui));
    }

If -O2 optimization is used, the output is: 4433f894 (incorrect)

If -O1 optimization is used, the output is: 44332211 (correct)

With -O2 optimization, if the variable newWord is declared static,
the output is correct.
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: optimization/6064: byte swap function returns bad value
@ 2002-04-03  2:41 rth
  0 siblings, 0 replies; 2+ messages in thread
From: rth @ 2002-04-03  2:41 UTC (permalink / raw)
  To: dp, gcc-bugs, gcc-prs, nobody

Synopsis: byte swap function returns bad value

State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Wed Apr  3 02:41:00 2002
State-Changed-Why:
    Fixed for gcc 3.1.  You may wish to report the bug to
    http://bugzilla.redhat.com/ as well.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6064


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-04-03 10:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-26  8:16 optimization/6064: byte swap function returns bad value dp
2002-04-03  2:41 rth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).