Patch: RFA: fix PR java/16789

Tom Tromey tromey@redhat.com
Tue Sep 21 23:03:00 GMT 2004


This patch fixes PR 16789.

There are two parts to this bug.

First, we generated incorrect bytecode for something like
staticMethod().staticMethod() (which is valid but weird).  This was
compiled to <compound_expr <call> <call>>, and we weren't setting
CAN_COMPLETE_NORMALLY on the first call -- so jcf-write would omit the
second call.

Second, this construct was causing a crash in force_evaluation_order.
I believe the correct fix is to move the check for a no-argument call
below the code that unwraps the COMPOUND_EXPR.

Michael, I CC'd you since I think this might fix the ICE we were
debugging in irc yesterday.  It is worth a try anyway.

Tested on x86 FC2, including mauve and jacks.  Regression test
included.

Ok?

Tom

Index: gcc/java/ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	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.

Index: gcc/java/expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.204
diff -u -r1.204 expr.c
--- gcc/java/expr.c 25 Aug 2004 09:52:50 -0000 1.204
+++ gcc/java/expr.c 21 Sep 2004 22:24:41 -0000
@@ -3178,9 +3178,6 @@
     {
       tree arg, cmp;
 
-      if (!TREE_OPERAND (node, 1))
-	return node;
-
       arg = node;
       
       /* Position arg properly, account for wrapped around ctors. */
@@ -3189,7 +3186,11 @@
       
       arg = TREE_OPERAND (arg, 1);
       
-      /* Not having a list of argument here is an error. */ 
+      /* An empty argument list is ok, just ignore it.  */
+      if (!arg)
+	return node;
+
+      /* Not having a list of arguments here is an error. */ 
       if (TREE_CODE (arg) != TREE_LIST)
         abort ();
 
Index: gcc/java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.505
diff -u -r1.505 parse.y
--- gcc/java/parse.y 17 Sep 2004 21:55:01 -0000 1.505
+++ gcc/java/parse.y 21 Sep 2004 22:24:47 -0000
@@ -9607,6 +9607,9 @@
 	     forcoming function's argument. */
 	  if (previous_call_static && is_static)
 	    {
+	      /* We must set CAN_COMPLETE_NORMALLY for the first call
+		 since it is done nowhere else.  */
+	      CAN_COMPLETE_NORMALLY (decl) = 1;
 	      decl = build2 (COMPOUND_EXPR, TREE_TYPE (*where_found),
 			     decl, *where_found);
 	      TREE_SIDE_EFFECTS (decl) = 1;
Index: libjava/ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	PR java/16789:
	* testsuite/libjava.lang/pr16789.out: New file.
	* testsuite/libjava.lang/pr16789.java: New file.

Index: libjava/testsuite/libjava.lang/pr16789.java
===================================================================
RCS file: libjava/testsuite/libjava.lang/pr16789.java
diff -N libjava/testsuite/libjava.lang/pr16789.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libjava/testsuite/libjava.lang/pr16789.java 21 Sep 2004 22:24:50 -0000
@@ -0,0 +1,15 @@
+// gcj used to generate incorrect bytecode for
+// staticMethod().staticMethod()
+public class pr16789
+{
+  public void foo()
+  {
+    System.out.println(Thread.currentThread().holdsLock(this));
+  }
+
+  public static void main(String[] args)
+  {
+    new pr16789().foo();
+  }
+}
+
Index: libjava/testsuite/libjava.lang/pr16789.out
===================================================================
RCS file: libjava/testsuite/libjava.lang/pr16789.out
diff -N libjava/testsuite/libjava.lang/pr16789.out
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libjava/testsuite/libjava.lang/pr16789.out 21 Sep 2004 22:24:50 -0000
@@ -0,0 +1 @@
+false



More information about the Gcc-patches mailing list