This is the mail archive of the gcc-patches@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]

Patch: FYI: fix PR 29013


I'm checking this in.

This fixes PR 29013, a bug which causes us to emit invalid .class
files in one situation.  The problem is that if we see a call to a
method which returns a value, but the value is ignored, then we don't
note the push of that value on the stack.  In some code this can
result in the method having a stack overflow in the bytecode.

Tested on x86 FC5.  New test case included.

I'm currently running all the gcj-generated bytecode through 'gcj
-fsyntax-only' to see if the verifier catches any other bytecode
generation bugs.  There seems to be at least one.

Tom

Index: gcc/java/ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	PR java/29013:
	* jcf-write.c (generate_bytecode_insns) <CALL_EXPR>: Always note
	the push of the called method's return result.

Index: libjava/ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	PR java/29013:
	* testsuite/libjava.lang/PR29013.out: Likewise.
	* testsuite/libjava.lang/PR29013.java: New file.

Index: gcc/java/jcf-write.c
===================================================================
--- gcc/java/jcf-write.c	(revision 116888)
+++ gcc/java/jcf-write.c	(working copy)
@@ -2651,10 +2651,14 @@
 	    if (TREE_CODE (f) != VOID_TYPE)
 	      {
 		int size = TYPE_IS_WIDE (f) ? 2 : 1;
+		/* Always note the push here, so that we correctly
+		   compute the required maximum stack size.  */
+		NOTE_PUSH (size);
 		if (target == IGNORE_TARGET)
-		  emit_pop (size, state);
-		else
-		  NOTE_PUSH (size);
+		  {
+		    emit_pop (size, state);
+		    NOTE_POP (size);
+		  }
 	      }
 	    break;
 	  }
Index: libjava/testsuite/libjava.lang/PR29013.out
===================================================================
Index: libjava/testsuite/libjava.lang/PR29013.java
===================================================================
--- libjava/testsuite/libjava.lang/PR29013.java	(revision 0)
+++ libjava/testsuite/libjava.lang/PR29013.java	(revision 0)
@@ -0,0 +1,9 @@
+public class PR29013 {
+  public static int result() { return 5; }
+
+  public static void computeResult() { result(); }
+
+  public static void main(String[] args) {
+    computeResult();
+  }
+}


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