Bug 16789

Summary: ICE in force_evaluation_order() on valid code
Product: gcc Reporter: Bryce McKinlay <bryce>
Component: javaAssignee: Tom Tromey <tromey>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, green, java-prs
Priority: P2 Keywords: ice-on-valid-code, patch, wrong-code
Version: 4.0.0   
Target Milestone: 4.0.0   
Host: Target:
Build: Known to work:
Known to fail: 4.0.0 3.3.4 3.4.2 Last reconfirmed: 2004-07-27 20:54:07
Bug Depends on:    
Bug Blocks: 17574    

Description Bryce McKinlay 2004-07-27 20:48:23 UTC
The following test case segfaults in force_evaluation_order() when compiling to
 native.

When compiling the same test to bytecode, the compiler does not crash, but the
generated bytecode is invalid (fails to verify on both gij and Sun's VM)

public class Crash
{
  public static void main(String[] args)
  {
    System.out.println(Thread.currentThread().holdsLock(this));
  }
}
Comment 1 Andrew Pinski 2004-07-27 20:51:27 UTC
Crash.java: In class `Crash':
Crash.java: In method `Crash.main(java.lang.String[])':
Crash.java:5: error: Keyword `this' used outside allowed context.
       System.out.println(Thread.currentThread().holdsLock(this));
                                                           ^
1 error
Comment 2 Andrew Pinski 2004-07-27 20:54:07 UTC
This is the code which ICE:
public class Crash
{
  public void main(String[] args)
  {
    System.out.println(Thread.currentThread().holdsLock(this));
  }
}
Comment 3 Bryce McKinlay 2004-07-27 20:55:26 UTC
Andrew's version of the test case is correct. "static" should be removed.
Comment 4 Bryce McKinlay 2004-07-27 20:56:15 UTC
public class Crash
{
  public void foo()
  {
    System.out.println(Thread.currentThread().holdsLock(this));
  }
}
Comment 5 Andrew Pinski 2004-07-27 20:57:21 UTC
Lets look at the code:
3190            arg = TREE_OPERAND (node, 0);
3191
3192          arg = TREE_OPERAND (arg, 1);
3193
3194          /* Not having a list of argument here is an error. */
3195          if (TREE_CODE (arg) != TREE_LIST)
3196            abort ();

This is wrong when there is no arguments to the function which is true for currentThread.
Comment 6 Bryce McKinlay 2004-07-27 21:04:13 UTC
I'm not so sure. The fact that invalid bytecode is generated (bytecode
compilation doesnt call force_evalution_order) leads me to suspect that
something wen't wrong earlier. 
Comment 7 Tom Tromey 2004-09-21 20:02:09 UTC
I'm testing a patch for this.
Comment 8 Tom Tromey 2004-09-21 22:25:39 UTC
*** Bug 15475 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2004-09-24 03:00:40 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02134.html>. Also this fixes the 
wrong-code with byte-code output.
Comment 10 GCC Commits 2004-09-24 15:39:20 UTC
Subject: Bug 16789

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tromey@gcc.gnu.org	2004-09-24 15:39:17

Modified files:
	gcc/java       : ChangeLog parse.y expr.c 

Log message:
	PR java/16789:
	* parse.y (resolve_qualified_expression_name): Set
	CAN_COMPLETE_NORMALLY on first call when chaining static calls.
	* expr.c (force_evaluation_order): Check for empty argument list
	after stripping COMPOUND_EXPR.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1461&r2=1.1462
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/parse.y.diff?cvsroot=gcc&r1=1.508&r2=1.509
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/expr.c.diff?cvsroot=gcc&r1=1.204&r2=1.205

Comment 11 GCC Commits 2004-09-24 15:41:22 UTC
Subject: Bug 16789

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tromey@gcc.gnu.org	2004-09-24 15:41:17

Modified files:
	libjava        : ChangeLog 
Added files:
	libjava/testsuite/libjava.lang: pr16789.java pr16789.out 

Log message:
	PR java/16789:
	* testsuite/libjava.lang/pr16789.out: New file.
	* testsuite/libjava.lang/pr16789.java: New file.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.3087&r2=1.3088
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/libjava.lang/pr16789.java.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/libjava.lang/pr16789.out.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 12 Tom Tromey 2004-09-24 15:41:57 UTC
Fix checked in.