From: Bryce McKinlay Date: Mon, 11 Mar 2002 11:15:10 +0000 (+0000) Subject: parse.y (patch_assignment): Wrap the right-hand-side with a save_expr to prevent... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=884523df8d676fd03c8d5bacfd98747d7f941a99;p=gcc.git parse.y (patch_assignment): Wrap the right-hand-side with a save_expr to prevent it getting evaluated twice... * 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. From-SVN: r50570 --- diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 6b4512f6b68..e9cef5a435e 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,10 @@ +2002-03-11 Bryce McKinlay + + * 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 * decl.c (java_init_decl_processing): Make sure class_type_node diff --git a/gcc/java/expr.c b/gcc/java/expr.c index 8eb816e2392..fa2935f3107 100644 --- a/gcc/java/expr.c +++ b/gcc/java/expr.c @@ -811,7 +811,7 @@ build_java_arraystore_check (array, object) 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 @@ build_java_arraystore_check (array, 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) diff --git a/gcc/java/parse.y b/gcc/java/parse.y index 2d0c3ddfa6d..925cb74291e 100644 --- a/gcc/java/parse.y +++ b/gcc/java/parse.y @@ -12715,6 +12715,9 @@ patch_assignment (node, wfl_op1) && 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);