This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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]

[gcjx] Patch: FYI: cleanups -vs- 'return'


I'm checking this in on the gcjx branch.

We were emitting invalid bytecode in a situation where a 'return'
expression was pushed on the stack and then the cleanups were run.
The reduced test case for this comes from PR 19810 (see the patch to
TODO).

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* bytecode/generate.cc (visit_return): If there are cleanups, save
	result expression in local variable.

Index: TODO
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/Attic/TODO,v
retrieving revision 1.1.2.30
diff -u -r1.1.2.30 TODO
--- TODO 18 May 2005 00:12:01 -0000 1.1.2.30
+++ TODO 18 May 2005 00:12:31 -0000
@@ -13,12 +13,7 @@
 in a static context
 
 the bug in PR 19810 makes for weird bytecode output from gcjx
-it is incorrect due to stack size differences
-- in bytecode_generator::visit_return, make a new temporary local when
-  there is a finally handler
-- store the result there
-- load the result when generating the 'return'
-- the return might be dead code...
+we are failing to eliminate some dead code
 
 gcjx also fails on PR 19629, though differently
 it creates the anonymous constructor incorrectly
Index: bytecode/generate.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/generate.cc,v
retrieving revision 1.1.2.11
diff -u -r1.1.2.11 generate.cc
--- bytecode/generate.cc 20 Apr 2005 16:05:01 -0000 1.1.2.11
+++ bytecode/generate.cc 18 May 2005 00:12:31 -0000
@@ -889,12 +889,30 @@
 {
   note_line (rtn);
 
+  int tmpvar = -1;
   if (expr)
     {
       push_expr_target push (this, ON_STACK);
       expr->visit (this);
+
+      // If there are cleanups to call, make a temporary variable and
+      // assign to it, then reload it before the return.
+      if (! finally_stack.empty ())
+	{
+	  tmpvar = vars.request (NULL);
+	  emit_store (expr->type (), tmpvar);
+	}
     }
+
   call_cleanups (NULL);
+
+  if (tmpvar != -1)
+    {
+      assert (expr);
+      emit_load (expr->type (), tmpvar);
+      vars.remove (tmpvar);
+    }
+
   if (! expr)
     emit (op_return);
   else


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