This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Java: fix Array_3 byte compiler failures
- From: Andrew Haley <aph at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: java at gcc dot gnu dot org
- Date: Thu, 26 Sep 2002 18:00:11 +0100 (BST)
- Subject: Java: fix Array_3 byte compiler failures
The test case Array_3.java (compilation from bytecode) has been
failing for a while. It turns out that we can't compile `aconst_null;
arraylength' because build_java_array_length_access() insists that its
arg is of type array, whereas null_pointer_node is of type (void *).
My take on this is that the only way we could ever get an arg of type
(void *) passed to build_java_array_length_access() is in just this
case, and therefore we can unconditionally throw a
NullPointerException if this ever happens.
If anyone can think of a situation where build_java_array_length_access()
might be passed a node of type (void *) that is non-null, please speak up.
Andrew.
2002-09-26 Andrew Haley <aph@redhat.com>
* expr.c (build_java_array_length_access): Check for null pointer.
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.151
diff -p -2 -c -r1.151 expr.c
*** expr.c 21 Sep 2002 02:19:44 -0000 1.151
--- expr.c 26 Sep 2002 16:21:57 -0000
*************** build_java_array_length_access (node)
*** 676,679 ****
--- 676,688 ----
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 (void *) at this point is `aconst_null; arraylength' or
+ somthing equivalent. */
+ if (TREE_CODE (type) == POINTER_TYPE && array_type == void_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 ();