From 3e02b1c3e85584cb8d944fe4cd3c94eea723c77b Mon Sep 17 00:00:00 2001 From: Andrew Haley Date: Fri, 23 Mar 2001 17:31:42 +0000 Subject: [PATCH] gcj.texi (Configure-time Options): Add -fcheck-references. 2001-02-07 Andrew Haley * gcj.texi (Configure-time Options): Add -fcheck-references. * expr.c (build_java_indirect_ref): New function. (java_check_reference): New function. (build_java_array_length_access): Use build_java_indirect_ref to check for null references. (build_java_arrayaccess): Likewise. (build_get_class): Likewise. (build_field_ref): Likewise. (invoke_build_dtable): Likewise. (build_invokeinterface): Likewise. * lang.c (lang_f_options): Add flag_check_references. * jvspec.c (jvgenmain_spec): Add flag_check_references. * java-tree.h (flag_check_references): New variable. * lang.c (flag_check_references): Likewise. * parse.y (patch_invoke): Use java_check_reference. (patch_assignment): Allow for extra nesting in _Jv_CheckArrayStore. From-SVN: r40782 --- gcc/java/ChangeLog | 4 ++++ gcc/java/parse.y | 42 +++++++++++++++++------------------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 5ad64eed609..18d3b5c71e8 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -2,6 +2,7 @@ * gcj.texi (Configure-time Options): Add -fcheck-references. * expr.c (build_java_indirect_ref): New function. + (java_check_reference): New function. (build_java_array_length_access): Use build_java_indirect_ref to check for null references. (build_java_arrayaccess): Likewise. @@ -13,6 +14,9 @@ * jvspec.c (jvgenmain_spec): Add flag_check_references. * java-tree.h (flag_check_references): New variable. * lang.c (flag_check_references): Likewise. + * parse.y (patch_invoke): Use java_check_reference. + (patch_assignment): Allow for extra nesting in + _Jv_CheckArrayStore. 2001-03-23 Bryce McKinlay diff --git a/gcc/java/parse.y b/gcc/java/parse.y index d1adac6c338..bc7da303bf6 100644 --- a/gcc/java/parse.y +++ b/gcc/java/parse.y @@ -8922,8 +8922,7 @@ resolve_field_access (qual_wfl, field_decl, field_type) && ! flag_emit_class_files && ! flag_emit_xref) { tree length = build_java_array_length_access (where_found); - field_ref = - build_java_arraynull_check (type_found, length, int_type_node); + field_ref = length; /* In case we're dealing with a static array, we need to initialize its class before the array length can be fetched. @@ -10196,7 +10195,7 @@ patch_invoke (patch, method, args) { tree dtable, func; tree original_call, t, ta; - tree cond = NULL_TREE; + tree check = NULL_TREE; /* Last step for args: convert build-in types. If we're dealing with a new TYPE() type call, the first argument to the constructor @@ -10235,12 +10234,11 @@ patch_invoke (patch, method, args) optimization pass to eliminate redundant checks. */ if (TREE_VALUE (args) != current_this) { - /* We use a SAVE_EXPR here to make sure we only evaluate + /* We use a save_expr here to make sure we only evaluate the new `self' expression once. */ tree save_arg = save_expr (TREE_VALUE (args)); TREE_VALUE (args) = save_arg; - cond = build (EQ_EXPR, boolean_type_node, save_arg, - null_pointer_node); + check = java_check_reference (save_arg, 1); } /* Fall through. */ @@ -10300,22 +10298,11 @@ patch_invoke (patch, method, args) patch = build (COMPOUND_EXPR, TREE_TYPE (new), patch, saved_new); } - /* If COND is set, then we are building a check to see if the object + /* If CHECK is set, then we are building a check to see if the object is NULL. */ - if (cond != NULL_TREE) - { - /* We have to make the `then' branch a compound expression to - make the types turn out right. This seems bizarre. */ - patch = build (COND_EXPR, TREE_TYPE (patch), cond, - build (COMPOUND_EXPR, TREE_TYPE (patch), - build (CALL_EXPR, void_type_node, - build_address_of (soft_nullpointer_node), - NULL_TREE, NULL_TREE), - (FLOAT_TYPE_P (TREE_TYPE (patch)) - ? build_real (TREE_TYPE (patch), dconst0) - : build1 (CONVERT_EXPR, TREE_TYPE (patch), - integer_zero_node))), - patch); + if (check != NULL_TREE) + { + patch = build (COMPOUND_EXPR, TREE_TYPE (patch), check, patch); TREE_SIDE_EFFECTS (patch) = 1; } @@ -12525,15 +12512,20 @@ patch_assignment (node, wfl_op1, wfl_op2) tree check; tree base = lvalue; - /* We need to retrieve the right argument for _Jv_CheckArrayStore */ + /* We need to retrieve the right argument for + _Jv_CheckArrayStore. This is somewhat complicated by bounds + and null pointer checks, both of which wrap the operand in + one layer of COMPOUND_EXPR. */ if (TREE_CODE (lvalue) == COMPOUND_EXPR) base = TREE_OPERAND (lvalue, 0); else { + base = TREE_OPERAND (base, 0); if (flag_bounds_check) - base = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (base, 0), 1), 0); - else - base = TREE_OPERAND (TREE_OPERAND (base, 0), 0); + base = TREE_OPERAND (base, 1); + if (flag_check_references) + base = TREE_OPERAND (base, 1); + base = TREE_OPERAND (base, 0); } /* Build the invocation of _Jv_CheckArrayStore */ -- 2.30.2