This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Java: Fix double-evaluation of RHS of array store
- From: Bryce McKinlay <bryce at waitaki dot otago dot ac dot nz>
- To: java-patches at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 12 Mar 2002 00:13:57 +1300
- Subject: Java: Fix double-evaluation of RHS of array store
Adam found a bug where we are evaluating an array store RHS twice,
resulting in two calls instead of one. This is because if the RHS is not
a save_expr, it will get re-evaluated when determining its type for
store checking.
In many cases a call_expr RHS is already wrapped by a save_expr, which
is why I didn't notice this before.
Rebuilt libjava and ran testsuite without regressions on PowerPC linux.
I'm checking this in as an obvious fix.
regards
Bryce.
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.
Index: parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
retrieving revision 1.357
diff -u -r1.357 parse.y
--- parse.y 2002/03/09 16:31:51 1.357
+++ parse.y 2002/03/11 10:42:52
@@ -12715,6 +12715,9 @@
&& 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);
Index: expr.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/expr.c,v
retrieving revision 1.136
diff -u -r1.136 expr.c
--- expr.c 2002/03/08 20:59:51 1.136
+++ expr.c 2002/03/11 10:42:54
@@ -811,7 +811,7 @@
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)));
@@ -837,11 +837,17 @@
|| 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)