This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Patch: don't generate dead bytecode
- To: tromey at redhat dot com
- Subject: Re: Patch: don't generate dead bytecode
- From: Per Bothner <per at bothner dot com>
- Date: Tue, 09 Oct 2001 17:08:53 -0700
- CC: Gcc Patch List <gcc-patches at gcc dot gnu dot org>, Java Patch List <java-patches at gcc dot gnu dot org>, Alexandre Petit-Bianco <apbianco at cygnus dot com>
- References: <87elocq19k.fsf@creche.redhat.com>
Tom Tromey wrote:
>Today I ran `make class-check' on libgcj. One of the problems is a
>bug in the front end (previously reported). All the other problems
>turned out to be dead byte code which was generated. It turns out we
>generate code for a statement like this:
>
> if (false) { do something }
>
>This patch removes all that dead bytecode. It does so by simply not
>generating code along a dead branch.
>
The attached patch seems to work. Could you see if it works as well as
your patch?
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.318
diff -u -p -r1.318 parse.y
--- parse.y 2001/10/09 05:40:35 1.318
+++ parse.y 2001/10/10 00:02:47
@@ -15023,11 +15011,22 @@ patch_if_else_statement (node)
return error_mark_node;
}
+ if (TREE_CODE (expression) == INTEGER_CST)
+ {
+ if (integer_zerop (expression))
+ node = TREE_OPERAND (node, 2);
+ else
+ node = TREE_OPERAND (node, 1);
+ if (CAN_COMPLETE_NORMALLY (node) != can_complete_normally)
+ {
+ node = build (COMPOUND_EXPR, void_type_node, node, empty_stmt_node);
+ CAN_COMPLETE_NORMALLY (node) = can_complete_normally;
+ }
+ return node;
+ }
TREE_TYPE (node) = void_type_node;
TREE_SIDE_EFFECTS (node) = 1;
- CAN_COMPLETE_NORMALLY (node)
- = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
- | CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 2));
+ CAN_COMPLETE_NORMALLY (node) = can_complete_normally;
return node;
}