public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Raphael.Quinet@eed.ericsson.se
To: gcc-gnats@gcc.gnu.org
Subject: target/10702: incorrect code generated on Sparc for expression combining increment and decrement of same variable
Date: Fri, 09 May 2003 12:36:00 -0000	[thread overview]
Message-ID: <20030509123440.19143.qmail@sources.redhat.com> (raw)


>Number:         10702
>Category:       target
>Synopsis:       incorrect code generated on Sparc for expression combining increment and decrement of same variable
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri May 09 12:36:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Raphael Quinet
>Release:        3.2.1
>Organization:
>Environment:
sparc-sun-solaris2.6 and sparc-sun-solaris2.8

Output from gcc -v:
Reading specs from /Local/lib/gcc-lib/sparc-sun-solaris2.6/3.2.1/specs
Configured with: ../gcc-3.2.1/configure --prefix=/Local --with-local-prefix=/Local --with-gnu-ld --with-gnu-as --with-ld=/Local/bin-gnu/ld --with-as=/Local/bin-gnu/as --enable-threads --disable-shared --enable-languages=c,c++,f77,objc --disable-libgcj
Thread model: posix
gcc version 3.2.1

In case this can be useful, "ld" and "as" are from binutils-2.13.1
>Description:
The code included below does not provide the expected
result when compiled on a sparc-sun-solaris platform.  It
does work on Intel platforms.

Expected result: the return value of the program should be 2 (x is incremented once and decremented once).

Observed result with gcc-3.2.1 (and older versions such as
2.95): 1.  Only the first operation is executed (x--).
------------------------
int x = 2;

int
main (int argc,
      char *argv[])
{
  int y;

  y = x-- * x++;
  return x;
}
------------------------

You can also test this by replacing "return x" by some
printf() statements if you want to see the result printed
instead of having to check the return code of the program.

Additional comments:
- Using "char" or "short" instead of "int" produces the
  correct result.  The bug affects (long) integers and
  pointers.
- This can be tested with various expressions including
  more than one operation on the same variable.  For
  example, this problem can be tested with pointers by
  declaring x to be of type "char *" and using the
  expression "y = (x++ == x--);".
- Only the first operation in the expression produces its
  expected side effect on x.  So using "y = x++ * x--" will
  only increment x by 1, while "y = x-- * x++" will only
  decrement x by 1.
- It is necessary to assign the result of the expression to
  some variable or to use it in some way in order to trigger
  this bug.  If you replace "y = x-- * x++" by the simpler
  statement "x-- * x++", then the result will be correct.
- Using the option -Wall or -Wsequence-point produces the
  expected warning "operation on `x' may be undefined", but
  I would have expected the result of the expression to be
  undefined, not the final value of x.  Also, the same
  program returns the correct value on other platforms, such
  as i*86-gnu-linux.
>How-To-Repeat:
gcc -Wall test.c
./a.out
echo $?
>Fix:

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


             reply	other threads:[~2003-05-09 12:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-09 12:36 Raphael.Quinet [this message]
2003-05-09 12:49 ehrhardt

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=20030509123440.19143.qmail@sources.redhat.com \
    --to=raphael.quinet@eed.ericsson.se \
    --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).