Bug 4822 - Evaluation order of =
Summary: Evaluation order of =
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 3.3
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2001-11-07 09:26 UTC by ake
Modified: 2005-11-10 03:15 UTC (History)
5 users (show)

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


Attachments
test.c (178 bytes, application/octet-stream)
2003-05-21 15:17 UTC, ake
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ake 2001-11-07 09:26:00 UTC
This program doesn't work with -O1 and -O2 flags. But when it is
compiled with -O0, then the program runs succesfully.
I have done more testing and this is also a problem with gcc and a C
program.

Release:
unknown

Environment:
linux x86 and alpha 21164 tru64 unix

How-To-Repeat:
Compile with -02 or -01 and it will show "ERROR". Compile with -O0 and it will work.
This is the Java file and the in the attachment, it is the C file.
public class Test {
    public static void main(String [] args) {
        int i,jjnewStateCnt,startsAt,curPos;
        curPos=1;
        i=67;
        startsAt=67;
        jjnewStateCnt=0;
 
        if ((i = jjnewStateCnt) == (startsAt = 67 - (jjnewStateCnt = startsAt))){
            System.err.println("OK "+ "\n");
            return;
 
        }
        System.out.println("\nERROR\n");
        return;
 
 
 
    }
  }
Comment 1 Bryce McKinlay 2001-11-20 17:54:47 UTC
From: Bryce McKinlay <bryce@waitaki.otago.ac.nz>
To: gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, ake@purdue.edu,
   gcc-bugs@gcc.gnu.org
Cc:  
Subject: Re: optimization/4822
Date: Tue, 20 Nov 2001 17:54:47 +1300

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=4822&database=gcc
 
 Hi,
 
 The C test case is, I believe, not a bug because C does not define 
 evaluation order across the "=".
 
 The Java case, however, _is_ a bug because we need to enforce the 
 left-to-right evaluation order in order to comply with Java semantics.
 
 regards
 
 Bryce.
 
 
Comment 2 Nathanael C. Nerode 2003-03-27 21:04:01 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Indeed a bug.  But has it been fixed?
Comment 3 Andrew Haley 2003-04-11 12:57:27 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: OK in 3.3pre