PR 1208

Tom Tromey tromey@redhat.com
Tue Mar 20 16:43:00 GMT 2001


Per> This patch seems to fix the problem. Please try that instead.
Thanks, looks fine to me.
Per> I'm going to try to figure out why the unreachable bytecodes are
Per> being emitted next.
I already have a partial patch for this problem. Alex is working on
finishing it. I believe this is the same problem as PR 2216.
I've appended the incomplete patch. This patch gets pretty close, but
it causes some other failures.
Tom
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/ChangeLog,v
retrieving revision 1.647.2.10
diff -u -r1.647.2.10 ChangeLog
--- ChangeLog	2001年03月07日 22:35:14	1.647.2.10
+++ ChangeLog	2001年03月14日 16:56:55
@@ -1,3 +1,11 @@
+2001年03月13日 Tom Tromey <tromey@redhat.com>
+ Alexandre Petit-Bianco <apbianco@redhat.com>
+
+	* parse.y (try_statement): Always create a TRY_BLOCK.
+	* jcf-write.c (generate_bytecode_insns): Correctly recognize empty
+	`finally' block. Correctly generate `goto' when try block empty.
+	Don't generate `goto' when finally block empty. Fixes PR java/2216.
+
 2001年03月07日 Tom Tromey <tromey@redhat.com>
 
 	* config-lang.in (lang_requires): Define.
Index: jcf-write.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-write.c,v
retrieving revision 1.72
diff -u -r1.72 jcf-write.c
--- jcf-write.c	2001年02月04日 22:44:03	1.72
+++ jcf-write.c	2001年03月14日 16:56:57
@@ -2342,7 +2342,9 @@
 
 	/* If the finally clause happens to be empty, set a flag so we
 remember to just skip it. */
-	if (BLOCK_EXPR_BODY (finally) == empty_stmt_node)
+	if ((TREE_CODE (finally) == BLOCK
+	 && BLOCK_EXPR_BODY (finally) == empty_stmt_node)
+	 || TREE_CODE (finally) == NOP_EXPR)
 	 worthwhile_finally = 0;
 
 	if (worthwhile_finally)
@@ -2363,23 +2365,29 @@
 
 	generate_bytecode_insns (try_block, target, state);
 
-	if (worthwhile_finally)
+	if (!worthwhile_finally)
+	 break;
+
+	if (state->labeled_blocks != finally_label)
+	 abort();
+	state->labeled_blocks = finally_label->next;
+
+	/* This point in the bytecode represents the collection point
+	 for the try clause and the various catch clauses -- each
+	 one which can complete normally will emit a `goto' to this
+	 point. We want to generate a `jsr' to the `finally'
+	 clause, unless none of the preceding clauses can complete
+	 normally, since in that particular case the `jsr' would
+	 simply be dead code. */
+	if (CAN_COMPLETE_NORMALLY (try_block))
 	 {
-	 if (state->labeled_blocks != finally_label)
-	 abort();
-	 state->labeled_blocks = finally_label->next;
 	 emit_jsr (finally_label, state);
+	 if (BLOCK_EXPR_BODY (TREE_OPERAND (try_block, 0))
+		!= empty_stmt_node)
+	 emit_goto (finished_label, state);
 	 }
 
-	if (CAN_COMPLETE_NORMALLY (try_block)
-	 && TREE_CODE (try_block) == BLOCK
-	 && BLOCK_EXPR_BODY (try_block) != empty_stmt_node)
-	 emit_goto (finished_label, state);
-
 	/* Handle exceptions. */
-
-	if (!worthwhile_finally)
-	 break;
 
 	localvar_alloc (return_link, state);
 	handler = alloc_handler (start_label, NULL_PTR, state);
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.251.2.6
diff -u -r1.251.2.6 parse.y
--- parse.y	2001年02月20日 21:15:48	1.251.2.6
+++ parse.y	2001年03月14日 16:57:09
@@ -1847,7 +1847,10 @@
 	TRY_TK block catches
 		{ $$ = build_try_statement (1ドル.location, 2,ドル 3ドル); }
 |	TRY_TK block finally
-		{ $$ = build_try_finally_statement (1ドル.location, 2,ドル 3ドル); }
+ { $$ = build_try_finally_statement 
+		 (1ドル.location, 
+		 build_try_statement (1ドル.location, 2,ドル NULL_TREE), 3ドル);
+		}
 |	TRY_TK block catches finally
 		{ $$ = build_try_finally_statement 
 		 (1ドル.location, build_try_statement (1ドル.location,


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /