This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gcjx] FYI: Minor correction to array access bounds-checking
- From: Ranjit Mathew <rmathew at gmail dot com>
- To: java-patches at gcc dot gnu dot org
- Date: Sun, 16 Oct 2005 11:43:39 +0530
- Subject: [gcjx] FYI: Minor correction to array access bounds-checking
- Openpgp: url=http://ranjitmathew.hostingzero.com/aa_6C114B8F.txt
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I committed the following patch to the gcjx-branch
after an offline discussion with Tom. This makes the
call to Jv_ThrowBadArrayIndex have TREE_SIDE_EFFECTS
and adds in the missing INDEX parameter. It also
explains why converting to unsigned and comparing
INDEX v/s LENGTH takes care of the INDEX < 0 check
as well.
Verified by inspecting the GENERIC and GIMPLE dumps.
Thanks,
Ranjit.
- --
Ranjit Mathew Email: rmathew AT gmail DOT com
Bangalore, INDIA. Web: http://ranjitmathew.hostingzero.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDUe+TYb1hx2wRS48RAhbmAJ9/2Q76n/eFmz7EWwMCAUt5zTiMKwCgoNXv
uzUyuSfmbtEraCQTyN+MBDs=
=zXhV
-----END PGP SIGNATURE-----
Index: ChangeLog
from Ranjit Mathew <rmathew@gcc.gnu.org>
* tree.cc (tree_generator::build_array_reference): Make CALL_EXPR
to call _Jv_ThrowBadArrayIndex have TREE_SIDE_EFFECTS and give
it the missing INDEX parameter. Explain that converting to
unsigned and comparing also takes care of checking for INDEX < 0.
Index: tree.cc
===================================================================
--- tree.cc 2005-10-15 20:11:09.000000000 +0530
+++ tree.cc 2005-10-16 11:34:41.000000000 +0530
@@ -2752,18 +2752,23 @@ tree_generator::build_array_reference (t
tree field = gcc_builtins->find_decl (array_type, "length");
// First: if ((unsigned) index >= (unsigned) length) throw
+ // ArrayIndexOutOfBoundsException. Note that this unsigned
+ // comparison also takes care of checking for INDEX < 0.
tree length = build3 (COMPONENT_REF, type_jint,
// Note we don't use check_reference here,
// as we it would be redundant.
build1 (INDIRECT_REF, array_type, array),
field, NULL_TREE);
+ tree call = build3 (CALL_EXPR, void_type_node,
+ builtin_Jv_ThrowBadArrayIndex,
+ build_tree_list (NULL_TREE, index),
+ NULL_TREE);
+ TREE_SIDE_EFFECTS (call) = 1;
tree check = build3 (COND_EXPR, void_type_node,
build2 (GE_EXPR, type_jboolean,
build1 (NOP_EXPR, type_juint, index),
build1 (NOP_EXPR, type_juint, length)),
- build3 (CALL_EXPR, void_type_node,
- builtin_Jv_ThrowBadArrayIndex,
- NULL_TREE, NULL_TREE),
+ call,
build_empty_stmt ());
result = build2 (COMPOUND_EXPR, result_type, check, result);
TREE_SIDE_EFFECTS (result) = (TREE_SIDE_EFFECTS (array)