From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22294 invoked by alias); 9 May 2003 12:36:00 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 22257 invoked by uid 71); 9 May 2003 12:36:00 -0000 Resent-Date: 9 May 2003 12:36:00 -0000 Resent-Message-ID: <20030509123600.22255.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, Raphael.Quinet@eed.ericsson.se Received: (qmail 19144 invoked by uid 48); 9 May 2003 12:34:40 -0000 Message-Id: <20030509123440.19143.qmail@sources.redhat.com> Date: Fri, 09 May 2003 12:36:00 -0000 From: Raphael.Quinet@eed.ericsson.se Reply-To: Raphael.Quinet@eed.ericsson.se To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: target/10702: incorrect code generated on Sparc for expression combining increment and decrement of same variable X-SW-Source: 2003-05/txt/msg00725.txt.bz2 List-Id: >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: