From 50cbc6057f519f2d0af68c95cf37e45d396009c2 Mon Sep 17 00:00:00 2001 From: Andrew Haley Date: Tue, 14 Jan 2003 13:31:11 +0000 Subject: [PATCH] [multiple changes] 2003-01-14 Andrew Haley * decl.c (java_init_decl_processing): _Jv_NewMultiArray is a varargs function -- correct. * parse.y (patch_assignment): Copy the rhs of an assignment into a temporary if the RHS is a reference. 2003-01-11 Kaveh R. Ghazi * Make-lang.in (keyword.h): Pass "-L ANSI-C" to gperf. * keyword.h: Regenerated. * All Files: Convert to ISO C style function definitions. From-SVN: r61281 --- gcc/java/ChangeLog | 8 ++++++++ gcc/java/decl.c | 5 +++-- gcc/java/parse.y | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 958d317988e..a7d983bd3ad 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,11 @@ +2003-01-14 Andrew Haley + + * decl.c (java_init_decl_processing): _Jv_NewMultiArray is a + varargs function -- correct. + + * parse.y (patch_assignment): Copy the rhs of an assignment into a + temporary if the RHS is a reference. + 2003-01-11 Kaveh R. Ghazi * Make-lang.in (keyword.h): Pass "-L ANSI-C" to gperf. diff --git a/gcc/java/decl.c b/gcc/java/decl.c index d07f83ee098..c388539ae99 100644 --- a/gcc/java/decl.c +++ b/gcc/java/decl.c @@ -810,8 +810,9 @@ java_init_decl_processing (void) 0, NOT_BUILT_IN, NULL, NULL_TREE); DECL_IS_MALLOC (soft_anewarray_node) = 1; - t = tree_cons (NULL_TREE, ptr_type_node, - tree_cons (NULL_TREE, int_type_node, endlink)); + /* There is no endlink here because _Jv_NewMultiArray is a varargs + function. */ + t = tree_cons (NULL_TREE, ptr_type_node, int_type_node); soft_multianewarray_node = builtin_function ("_Jv_NewMultiArray", build_function_type (ptr_type_node, t), diff --git a/gcc/java/parse.y b/gcc/java/parse.y index dcdcc41ed97..b618bb273ad 100644 --- a/gcc/java/parse.y +++ b/gcc/java/parse.y @@ -12627,6 +12627,43 @@ patch_assignment (tree node, tree wfl_op1) DECL_INITIAL (lvalue) = new_rhs; } + /* 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 (""), + 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; TREE_TYPE (node) = lhs_type; -- 2.30.2