This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Non-call exceptions versus cse
- From: Andrew Haley <aph at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, java at gcc dot gnu dot org
- Date: Fri, 27 Dec 2002 17:40:06 +0000 (GMT)
- Subject: Re: Non-call exceptions versus cse
- References: <200211191621.gAJGLTs10581@cuddles.cambridge.redhat.com><15834.30922.508706.58112@cuddles.cambridge.redhat.com><15862.8682.417620.249110@cuddles.cambridge.redhat.com><20021212191858.GB23881@redhat.com><20021212194736.GA2379@atrey.karlin.mff.cuni.cz><15864.63985.853284.533114@cuddles.cambridge.redhat.com>
This is the Java front end patch to copy the RHS of an assignment if
it's a reference.
As far as I know this is now correct on all the platforms for which we
support non-call exceptions. Of course, we may have more CSE problems
to contend with.
Andrew.
2002-12-27 Andrew Haley <aph@redhat.com>
* parse.y (patch_assignment): Copy the rhs of an assignment into a
temporary if the RHS is a reference.
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.408
diff -c -2 -p -r1.408 parse.y
*** parse.y 23 Dec 2002 19:42:09 -0000 1.408
--- parse.y 27 Dec 2002 17:36:23 -0000
*************** patch_assignment (node, wfl_op1)
*** 12865,12868 ****
--- 12865,12905 ----
}
+ /* Copy the rhs if it's a reference. */
+ if (! flag_check_references && optimize > 0)
+ {
+ switch (TREE_CODE (new_rhs))
+ {
+ case ARRAY_REF:
+ case INDIRECT_REF:
+ case COMPONENT_REF:
+ /* Transform a = foo.bar
+ into a = { int tmp; tmp = foo.bar; tmp; ).
+ We need to ensure that if a read from memory fails
+ because of a NullPointerException, a destination variable
+ will remain unchanged. An explicit temporary does what
+ we need.
+
+ If flag_check_references is set, this is unnecessary
+ because we'll check each reference before doing any
+ reads. If optimize is not set the result will never be
+ written to a stack slot that contains the LHS. */
+ {
+ tree tmp = build_decl (VAR_DECL, get_identifier ("<tmp>"),
+ TREE_TYPE (new_rhs));
+ tree block = build (BLOCK, TREE_TYPE (new_rhs), NULL);
+ tree assignment
+ = build (MODIFY_EXPR, TREE_TYPE (new_rhs), tmp, fold (new_rhs));
+ BLOCK_VARS (block) = tmp;
+ BLOCK_EXPR_BODY (block)
+ = build (COMPOUND_EXPR, TREE_TYPE (new_rhs), assignment, tmp);
+ TREE_SIDE_EFFECTS (block) = 1;
+ new_rhs = block;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
TREE_OPERAND (node, 0) = lvalue;
TREE_OPERAND (node, 1) = new_rhs;