diff options
author | Andrew Haley <aph@redhat.com> | 2002-09-27 18:27:44 +0000 |
---|---|---|
committer | Andrew Haley <aph@gcc.gnu.org> | 2002-09-27 18:27:44 +0000 |
commit | fc5295fa6af5d1f71b476500988c0739846ce348 (patch) | |
tree | 14791d5379a12f2c854f9406cda926a0e922573b | |
parent | 23b8ba8182bafbb4ad3c4477b6a4063544165a47 (diff) | |
download | gcc-fc5295fa6af5d1f71b476500988c0739846ce348.zip gcc-fc5295fa6af5d1f71b476500988c0739846ce348.tar.gz gcc-fc5295fa6af5d1f71b476500988c0739846ce348.tar.bz2 |
expr.c (build_java_array_length_access): Check for null pointer.
2002-09-26 Andrew Haley <aph@redhat.com>
* expr.c (build_java_array_length_access): Check for null pointer.
* expr.c (expand_java_arrayload): Likewise.
From-SVN: r57591
-rw-r--r-- | gcc/java/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/java/expr.c | 30 |
2 files changed, 29 insertions, 6 deletions
diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 45776e6..620543a 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,8 @@ +2002-09-26 Andrew Haley <aph@redhat.com> + + * expr.c (build_java_array_length_access): Check for null pointer. + * expr.c (expand_java_arrayload): Likewise. + 2002-09-21 Richard Henderson <rth@redhat.com> * jcf-parse.c (get_constant): Decode from IEEE no matter diff --git a/gcc/java/expr.c b/gcc/java/expr.c index c192d46..0c434e9 100644 --- a/gcc/java/expr.c +++ b/gcc/java/expr.c @@ -675,6 +675,15 @@ build_java_array_length_access (node) tree array_type = TREE_TYPE (type); HOST_WIDE_INT length; + /* JVM spec: If the arrayref is null, the arraylength instruction + throws a NullPointerException. The only way we could get a node + of type ptr_type_node at this point is `aconst_null; arraylength' + or something equivalent. */ + if (type == ptr_type_node) + return build (CALL_EXPR, int_type_node, + build_address_of (soft_nullpointer_node), + NULL_TREE, NULL_TREE); + if (!is_array_type_p (type)) abort (); @@ -1028,12 +1037,21 @@ expand_java_arrayload (lhs_type_node ) index_node = save_expr (index_node); array_node = save_expr (array_node); - lhs_type_node = build_java_check_indexed_type (array_node, lhs_type_node); - - load_node = build_java_arrayaccess (array_node, - lhs_type_node, - index_node); - + + if (TREE_TYPE (array_node) == ptr_type_node) + /* The only way we could get a node of type ptr_type_node at this + point is `aconst_null; arraylength' or something equivalent, so + unconditionally throw NullPointerException. */ + load_node = build (CALL_EXPR, lhs_type_node, + build_address_of (soft_nullpointer_node), + NULL_TREE, NULL_TREE); + else + { + lhs_type_node = build_java_check_indexed_type (array_node, lhs_type_node); + load_node = build_java_arrayaccess (array_node, + lhs_type_node, + index_node); + } if (INTEGRAL_TYPE_P (lhs_type_node) && TYPE_PRECISION (lhs_type_node) <= 32) load_node = fold (build1 (NOP_EXPR, int_type_node, load_node)); push_value (load_node); |