Bug 6790 - conditional expression as assignment lhs evaluated incorrectly
Summary: conditional expression as assignment lhs evaluated incorrectly
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-05-23 17:26 UTC by horsh
Modified: 2004-08-13 16:03 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description horsh 2002-05-23 17:26:00 UTC
The following four little pieces should give identical 
results:

$gcc test.c; ./a.out
-2, -2, -2 , -2, 0, -2
-2, -2, -2 , -2, 0, -2
-2, -2, -2 , -2, 0, -2
-2, -2, -2 , -2, 0, -2


but they dont:

gcc test.c; ./a.out
-2, -2, -2 , -2, 0, -2
-4, -2, -2 , -2, 0, -2
-2, -2, -2 , -2, 0, -2
-2, -2, -2 , -2, 0, -2

$cat test.c
void
main(void) {
        int  a, b, c, x, y, z, A, B, C, X, Y, Z;

        a=-2; b=-2; c=-2; x=-2; y=-2; z=-2; 

          (y -= b);
          (c ? a : b) += (x ? y : z);

        printf("%d, %d, %d , %d, %d, %d\n", a, b, c, x, y, z);

/*------------------------------------------------------------------*/

        a=-2; b=-2; c=-2; x=-2; y=-2; z=-2;

        (
          (y -= b) ?
          (c ? a : b) :
          (c ? a : b)   ) += (x ? y : z);

        printf("%d, %d, %d , %d, %d, %d\n", a, b, c, x, y, z);

/*------------------------------------------------------------------*/

        a=-2; b=-2; c=-2; x=-2; y=-2; z=-2;

        (
          (y -= b) ?
          ((c ? a : b) += (x ? y : z)) :
          ((c ? a : b) += (x ? y : z))   );

        printf("%d, %d, %d , %d, %d, %d\n", a, b, c, x, y, z);

/*------------------------------------------------------------------*/

        a=-2; b=-2; c=-2; x=-2; y=-2; z=-2;

        (
          (y -= b) ?
          ((c ? (a += (x ? y : z)) : (b += (x ? y : z)))) :
          ((c ? (a += (x ? y : z)) : (b += (x ? y : z))))   );

        printf("%d, %d, %d , %d, %d, %d\n", a, b, c, x, y, z);



}

Release:
2.95.3 20010315 (SuSE), 3.1

Environment:
Reading specs from /usr/lib/gcc-lib/i486-suse-linux/2.95.3/specs
gcc version 2.95.3 20010315 (SuSE)

or

Reading specs from /pkg/gnu/lib/gcc-lib/sparc-sun-solaris2.8/3.1/specs
Configured with: ../configure --prefix=/pkg/gnu --enable-languages=c++,f77
Thread model: posix
gcc version 3.1

How-To-Repeat:
just compile and run:

$gcc test.c; ./a.out
Comment 1 Richard Henderson 2002-05-23 21:10:51 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Not a bug.  There is no sequence point across an assignment operator.
Comment 2 Wolfgang Bangerth 2004-08-13 16:01:28 UTC
Reopening to mark as a duplicate of... 
Comment 3 Wolfgang Bangerth 2004-08-13 16:03:47 UTC
...PR 11751. 

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