public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: dp@fc.hp.com
To: gcc-gnats@gcc.gnu.org
Subject: optimization/6064: byte swap function returns bad value
Date: Tue, 26 Mar 2002 08:16:00 -0000	[thread overview]
Message-ID: <20020326161500.592.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2002-03-26 16:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-26  8:16 dp [this message]
2002-04-03  2:41 rth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020326161500.592.qmail@sources.redhat.com \
    --to=dp@fc.hp.com \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).