This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: ignore empty statements when scanning <clinit>
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Cc: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: 15 Mar 2006 10:26:56 -0700
- Subject: Patch: FYI: ignore empty statements when scanning <clinit>
- Reply-to: tromey at redhat dot com
I'm checking this in on the trunk.
When scanning <clinit> to see if it can be removed, we ought to ignore
empty statements. Before this patch we could erroneously see a
<clinit> in the bytecode generated for some interfaces (which did not
need a <clinit>), such as gnu.javax.crypto.mode.IMode.
Note that <clinit> removal is still screwy. For some reason we will
only consider removal if we're generating class files -- not if we're
generating object code. I don't understand why that would be.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* parse.y (analyze_clinit_body): Ignore empty statements.
Index: parse.y
===================================================================
--- parse.y (revision 111942)
+++ parse.y (working copy)
@@ -1,6 +1,6 @@
/* Source code parsing and tree node generation for the GNU compiler
for the Java(TM) language.
- Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+ Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
@@ -8006,7 +8006,8 @@
}
/* Analyzes a method body and look for something that isn't a
- MODIFY_EXPR with a constant value. */
+ MODIFY_EXPR with a constant value. Return true if <clinit> is
+ needed, false otherwise. */
static int
analyze_clinit_body (tree this_class, tree bbody)
@@ -8045,6 +8046,11 @@
|| ! DECL_INITIAL (TREE_OPERAND (bbody, 0))
|| DECL_CONTEXT (TREE_OPERAND (bbody, 0)) != this_class);
+ case NOP_EXPR:
+ /* We might see an empty statement here, which is
+ ignorable. */
+ return ! IS_EMPTY_STMT (bbody);
+
default:
return 1;
}