>Number:         5354
>Category:       c
>Synopsis:       function call with two statement expressions yields incorrect result
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 10 16:26:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Ben Liblit <[EMAIL PROTECTED]>
>Release:        3.1 20020110 (experimental)
>Organization:
Computer Science Division, UC Berkeley
>Environment:
System: Linux brawnix.CS.Berkeley.EDU 2.4.17 #4 Fri Dec 28 23:34:16 PST 2001 i686 
unknown
Architecture: i686

        
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../src/configure --prefix=/var/local/liblit/gcc-cvs/install
>Description:
        
When calling a function where two arguments are computed using ({...})
statement expressions, the generated code computes the incorrect
value for one of the arguments.  Specifically, it appears that
whichever statement expression is computed *last* is taken as the
value for *both* arguments.

>How-To-Repeat:
        
Compile and run the following code:

------------------------------------------------------------------------
        extern int printf(__const char *__restrict __format, ...);


        void f(int x, int y)
        {
          printf("f(%d, %d)\n", x, y);
        }


        int main()
        {
          f(({ int temp1 = 1; temp1; }),
            ({ int temp2 = 2; temp2; }));

          return 0;
        }
------------------------------------------------------------------------

gcc-2.96 produces the correct output:

        f(1, 2)

gcc-3.0.1, which computes the arguments for the call to g from right
to left, produces the following incorrect output:

        f(1, 1)

gcc CVS snapshot as of 10-Jan-2002, which computes the arguments for
the call to g from left to right, produces the following incorrect
output:

        f(2, 2)

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

Reply via email to