Non-call exceptions versus cse

Andrew Haley aph@redhat.com
Fri Dec 27 09:39:00 GMT 2002


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;



More information about the Java mailing list