Bug 17282 - x = y++ + x++ operation wrongly implemented on solaris version
Summary: x = y++ + x++ operation wrongly implemented on solaris version
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 2.95.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2004-09-02 12:06 UTC by Gaurav Goel
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Gaurav Goel 2004-09-02 12:06:57 UTC
x = y++ + x++ operation wrongly implemented on solaris version.

gcc Version:
chinar: /user/ggoel/Release/steel > gcc -v
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/2.8.1/specs
gcc version 2.8.1
chinar: /user/ggoel/Release/steel >

Program code:
        int x=20,y=35;
        x = y++ + x++;
Output of program:

Expected output 56:

Comments: this problem is there with other compilers: cc and g++. Same problen 
is not apearing on Linux.

OS version:
chinar: /user/ggoel/Release/steel > uname -rsv
SunOS 5.6 Generic_105181-35
chinar: /user/ggoel/Release/steel > 

Other details:
chinar: /user/ggoel/Release/steel > gcc -v temp.c
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/2.8.1/specs
gcc version 2.8.1
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/2.8.1/cpp -lang-c -v -undef -
D__GNUC__=2 -D__GNUC_MINOR__=8 -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -
D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -
Asystem(unix) -Asystem(svr4) -D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine
(sparc) temp.c /var/tmp/ccava4ZP.i
GNU CPP version 2.8.1 (sparc)
#include "..." search starts here:
#include <...> search starts here:
End of search list.
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/2.8.1/cc1 /var/tmp/ccava4ZP.i -
quiet -dumpbase temp.c -version -o /var/tmp/ccava4ZP.s
GNU C version 2.8.1 (sparc-sun-solaris2.6) compiled by GNU C version 2.8.1.
 /usr/ccs/bin/as -V -Qy -s -o /var/tmp/ccava4ZP1.o /var/tmp/ccava4ZP.s
/usr/ccs/bin/as: WorkShop Compilers 4.X dev 18 Sep 1996
 /usr/ccs/bin/ld -V -Y P,/usr/ccs/lib:/usr/lib -Qy /usr/local/lib/gcc-lib/sparc-
sun-solaris2.6/2.8.1/crt1.o /usr/local/lib/gcc-lib/sparc-sun-
solaris2.6/2.8.1/crti.o /usr/ccs/lib/values-Xa.o /usr/local/lib/gcc-lib/sparc-
sun-solaris2.6/2.8.1/crtbegin.o -L/usr/local/lib/gcc-lib/sparc-sun-
solaris2.6/2.8.1 -L/usr/local/sparc-sun-solaris2.6/lib -L/usr/ccs/bin -
L/usr/ccs/lib -L/usr/local/lib /var/tmp/ccava4ZP1.o -lgcc -lc -
lgcc /usr/local/lib/gcc-lib/sparc-sun-
solaris2.6/2.8.1/crtend.o /usr/local/lib/gcc-lib/sparc-sun-
ld: Software Generation Utilities - Solaris Link Editors: 5.6-1.274
chinar: /user/ggoel/Release/steel >
Comment 1 Andreas Schwab 2004-09-02 12:36:26 UTC

*** This bug has been marked as a duplicate of 11751 ***
Comment 2 Gaurav Goel 2004-09-03 05:12:35 UTC

It seems to me that this problem is different for what defined in other bug. 
Here we are assigning a value after adding and the variable with other 
constant, but instead of adding then incrementing the variable compiler is just 
incrementing the value. Behavior is different in Linux.

Code is:

x = y++ + x++;

For this expression compiler should first add x and y and then increment  x.
This expression should be broken like this.
x = x + y;

but compiler on Solaris is doing something like this:
temp = x++;
temp1 = y++;
x = x + y;
y = temp1;
x = temp; /* reassigning the variable with incremented value. This is wrong */

expected value of x here is 56, but its giving 21.

Same is working fine with Linux. this problem is there with Solaris and 
compilers cc and g++ also.

Comment 3 Andrew Pinski 2004-09-03 05:23:35 UTC
Nope x = x++; is undefined so is x = 1 + x++; or x = y++ + x++;, you are modifing x twice in 
without a sequence point inbetween.

*** This bug has been marked as a duplicate of 11751 ***