+2002-03-11 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
+
+ * parse.y (patch_assignment): Wrap the right-hand-side with a save_expr
+ to prevent it getting evaluated twice in the store checking case.
+ * expr.c (build_java_arraystore_check): Unwrap SAVE_EXPR's when
+ examining OBJECT.
+
2002-03-09 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
* decl.c (java_init_decl_processing): Make sure class_type_node
tree array;
tree object;
{
- tree check, element_type;
+ tree check, element_type, source;
tree array_type_p = TREE_TYPE (array);
tree object_type = TYPE_NAME (TREE_TYPE (TREE_TYPE (object)));
|| CLASS_FINAL (element_type)))
return build1 (NOP_EXPR, array_type_p, array);
+ /* OBJECT might be wrapped by a SAVE_EXPR. */
+ if (TREE_CODE (object) == SAVE_EXPR)
+ source = TREE_OPERAND (object, 0);
+ else
+ source = object;
+
/* Avoid the check if OBJECT was just loaded from the same array. */
- if (TREE_CODE (object) == ARRAY_REF)
+ if (TREE_CODE (source) == ARRAY_REF)
{
tree target;
- tree source = TREE_OPERAND (object, 0); /* COMPONENT_REF. */
+ source = TREE_OPERAND (source, 0); /* COMPONENT_REF. */
source = TREE_OPERAND (source, 0); /* INDIRECT_REF. */
source = TREE_OPERAND (source, 0); /* Source array's DECL or SAVE_EXPR. */
if (TREE_CODE (source) == SAVE_EXPR)
&& JREFERENCE_TYPE_P (TYPE_ARRAY_ELEMENT (lhs_type)))
{
tree array, store_check, base, index_expr;
+
+ /* Save RHS so that it doesn't get re-evaluated by the store check. */
+ new_rhs = save_expr (new_rhs);
/* Get the INDIRECT_REF. */
array = TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0);