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: PR 4509


This fixes PR java/4509.

There were a couple problems here:

* When generating bytecode, if the first part of a COMPOUND_EXPR
  couldn't complete normally, we still generated bytecode for the
  second part.  This seems incorrect to me, and I changed it.

* When generating a LOOP_EXPR, there's no point in generating the
  `goto' back to the beginning if the loop body can't complete
  normally.

* When building a COMPOUND_EXPR, we weren't correctly computing
  whether it can complete normally.  I think we have to take both
  parts into account.  I'm not completely sure the new code is
  correct, since I don't understand why the old code was written the
  way it was.

I rebuilt libgcj and ran the test suite with this patch with no
problems.

Ok to commit?

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	For PR java/4509:
	* parse.y (java_complete_lhs) [COMPOUND_EXPR]: Correctly compute
	CAN_COMPLETE_NORMALLY for the node.
	* jcf-write.c (generate_bytecode_insns) [COMPOUND_EXPR]: Don't
	generate code for second branch if first branch can't complete
	normally.
	(generate_bytecode_insns) [LOOP_EXPR]: Don't generate `goto' to
	the loop head if the loop body can't complete normally.

2001-12-20  Tom Tromey  <tromey@redhat.com>

Index: jcf-write.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-write.c,v
retrieving revision 1.96
diff -u -r1.96 jcf-write.c
--- jcf-write.c 2001/12/16 16:23:49 1.96
+++ jcf-write.c 2001/12/20 18:18:58
@@ -1483,7 +1483,8 @@
       break;
     case COMPOUND_EXPR:	
       generate_bytecode_insns (TREE_OPERAND (exp, 0), IGNORE_TARGET, state);
-      generate_bytecode_insns (TREE_OPERAND (exp, 1), target, state);
+      if (CAN_COMPLETE_NORMALLY (TREE_OPERAND (exp, 0)))
+	generate_bytecode_insns (TREE_OPERAND (exp, 1), target, state);
       break;
     case EXPR_WITH_FILE_LOCATION:
       {
@@ -1880,7 +1881,8 @@
 	  {
 	    struct jcf_block *head_label = get_jcf_label_here (state);
 	    generate_bytecode_insns (body, IGNORE_TARGET, state);
-	    emit_goto (head_label, state);
+	    if (CAN_COMPLETE_NORMALLY (body))
+	      emit_goto (head_label, state);
 	  }
       }
       break;
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.335
diff -u -r1.335 parse.y
--- parse.y 2001/12/20 17:45:41 1.335
+++ parse.y 2001/12/20 18:19:10
@@ -11781,8 +11781,12 @@
 	  TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
 	  if (TREE_OPERAND (node, 1) == error_mark_node)
 	    return error_mark_node;
+	  /* Even though we might allow the case where the first
+	     operand doesn't return normally, we still should compute
+	     CAN_COMPLETE_NORMALLY correctly.  */
 	  CAN_COMPLETE_NORMALLY (node)
-	    = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1));
+	    = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0))
+	       && CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1)));
 	}
       TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 1));
       break;


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