aboutsummaryrefslogtreecommitdiff
path: root/gcc/java/expr.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/java/expr.c')
-rw-r--r--gcc/java/expr.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/gcc/java/expr.c b/gcc/java/expr.c
index 182d247..0d3c61d 100644
--- a/gcc/java/expr.c
+++ b/gcc/java/expr.c
@@ -798,14 +798,21 @@ build_java_arrayaccess (array, type, index)
TREE_SIDE_EFFECTS( throw ) = 1;
}
}
-
+
+ /* The SAVE_EXPR is for correct evaluation order. It would be
+ cleaner to use force_evaluation_order (see comment there), but
+ that is difficult when we also have to deal with bounds
+ checking. The SAVE_EXPR is not necessary to do that when we're
+ not checking for array bounds. */
+ if (TREE_SIDE_EFFECTS (index) && throw)
+ throw = build (COMPOUND_EXPR, int_type_node, save_expr (array), throw);
+
node = build1 (INDIRECT_REF, type,
fold (build (PLUS_EXPR, ptr_type_node,
- java_check_reference (array, flag_check_references),
+ java_check_reference (array,
+ flag_check_references),
(throw ? build (COMPOUND_EXPR, int_type_node,
- throw, arith )
- : arith))));
-
+ throw, arith ) : arith))));
return node;
}