This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

optimization/6790: conditional expression as assignment lhs evaluated incorrectly



>Number:         6790
>Category:       optimization
>Synopsis:       conditional expression as assignment lhs evaluated incorrectly
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          ice-on-legal-code
>Submitter-Id:   net
>Arrival-Date:   Thu May 23 17:26:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     papahorsh
>Release:        2.95.3 20010315 (SuSE), 3.1
>Organization:
>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
>Description:

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);



}
>How-To-Repeat:
just compile and run:

$gcc test.c; ./a.out
>Fix:

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]