This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
target/10702: incorrect code generated on Sparc for expression combining increment and decrement of same variable
- From: Raphael dot Quinet at eed dot ericsson dot se
- To: gcc-gnats at gcc dot gnu dot org
- Date: 9 May 2003 12:34:40 -0000
- Subject: target/10702: incorrect code generated on Sparc for expression combining increment and decrement of same variable
- Reply-to: Raphael dot Quinet at eed dot ericsson dot se
>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: