[gcjx] Patch: FYI: fix local variable initialization
Tom Tromey
tromey@redhat.com
Sun Oct 9 22:54:00 GMT 2005
I'm checking this in on the gcjx branch.
I didn't realize that DECL_INITIAL does not work for local variables.
This changes the code to emit explicit initializations instead. Also
it fixes a latent bug -- visit_variable_stmt never set 'current'.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* tree.cc (visit_variable_stmt): Build a series of MODIFY_EXPRs
to initialize variables.
Index: tree.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/tree.cc,v
retrieving revision 1.1.2.53
diff -u -r1.1.2.53 tree.cc
--- tree.cc 9 Oct 2005 21:59:48 -0000 1.1.2.53
+++ tree.cc 9 Oct 2005 22:50:15 -0000
@@ -1071,6 +1071,11 @@
tree_generator::visit_variable_stmt (model_variable_stmt *,
const std::list<ref_variable_decl> &decls)
{
+ // The result here is a statement list that initializes all the
+ // variables, as needed. The statement list might be empty.
+ tree result = alloc_stmt_list ();
+ tree_stmt_iterator out = tsi_start (result);
+
for (std::list<ref_variable_decl>::const_iterator i = decls.begin ();
i != decls.end ();
++i)
@@ -1080,9 +1085,18 @@
{
ref_expression init = (*i)->get_initializer ();
init->visit (this);
- DECL_INITIAL (decl) = current;
+
+ // Apparently setting DECL_INITIAL is not enough for locals
+ // -- instead we must emit explicit initializations.
+ // DECL_INITIAL (decl) = current; -- does not work.
+ tree modify = build2 (MODIFY_EXPR, TREE_TYPE (decl),
+ decl, current);
+ TREE_SIDE_EFFECTS (modify) = 1;
+ tsi_link_after (&out, modify, TSI_CONTINUE_LINKING);
}
}
+
+ current = result;
}
void
More information about the Java-patches
mailing list