This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch: RFA: Fix for PR java/11600
- From: Tom Tromey <tromey at redhat dot com>
- To: GCC libjava patches <java-patches at gcc dot gnu dot org>
- Cc: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: 04 Aug 2003 15:57:01 -0600
- Subject: Patch: RFA: Fix for PR java/11600
- Reply-to: tromey at redhat dot com
This patch fixes PR java/11600
Tested on x86 Red Hat Linux; rebuilt libjava and ran the test suite,
including jacks, with no regressions.
It would be nice if we could just get rid of the various special cases
for arrays. For instance, we could explicitly add Cloneable and
Serializable to the interfaces for each array, and also add `public
Object clone()' (note lack of throws clause) to the array class.
(Sun's javac generates a call to Object.clone for a call to
<array>.clone, but I think that is incorrect. jikes doesn't do this.)
I tried this approach at first, but ran into some ugly morasses. It
turns out array classes aren't treated like ordinary classes; adding a
method to one causes a lot of confusion. So I abandoned this approach
in favor of the below.
Ok?
Tom
Index: gcc/java/ChangeLog
from Tom Tromey <tromey@redhat.com>
Fix for PR java/11600:
* parse.y (java_complete_lhs): See whether we're calling a method
on an array.
(check_thrown_exceptions): Added `is_array_call' argument;
fixed `clone' checking; updated all callers.
Index: gcc/java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.437
diff -u -r1.437 parse.y
--- gcc/java/parse.y 9 Jul 2003 00:31:20 -0000 1.437
+++ gcc/java/parse.y 4 Aug 2003 22:03:13 -0000
@@ -220,7 +220,7 @@
static tree patch_try_statement (tree);
static tree patch_synchronized_statement (tree, tree);
static tree patch_throw_statement (tree, tree);
-static void check_thrown_exceptions (int, tree);
+static void check_thrown_exceptions (int, tree, tree);
static int check_thrown_exceptions_do (tree);
static void purge_unchecked_exceptions (tree);
static bool ctors_unchecked_throws_clause_p (tree);
@@ -9454,7 +9454,13 @@
if (location
&& !OUTER_FIELD_ACCESS_IDENTIFIER_P
(DECL_NAME (current_function_decl)))
- check_thrown_exceptions (location, ret_decl);
+ {
+ tree arguments = NULL_TREE;
+ if (TREE_CODE (qual_wfl) == CALL_EXPR
+ && TREE_OPERAND (qual_wfl, 1) != NULL_TREE)
+ arguments = TREE_VALUE (TREE_OPERAND (qual_wfl, 1));
+ check_thrown_exceptions (location, ret_decl, arguments);
+ }
/* If the previous call was static and this one is too,
build a compound expression to hold the two (because in
@@ -11897,13 +11903,20 @@
int in_this = CALL_THIS_CONSTRUCTOR_P (node);
int from_super = (EXPR_WFL_NODE (TREE_OPERAND (node, 0)) ==
super_identifier_node);
+ tree arguments;
node = patch_method_invocation (node, NULL_TREE, NULL_TREE,
from_super, 0, &decl);
if (node == error_mark_node)
return error_mark_node;
- check_thrown_exceptions (EXPR_WFL_LINECOL (node), decl);
+ if (TREE_CODE (node) == CALL_EXPR
+ && TREE_OPERAND (node, 1) != NULL_TREE)
+ arguments = TREE_VALUE (TREE_OPERAND (node, 1));
+ else
+ arguments = NULL_TREE;
+ check_thrown_exceptions (EXPR_WFL_LINECOL (node), decl,
+ arguments);
/* If we call this(...), register signature and positions */
if (in_this)
DECL_CONSTRUCTOR_CALLS (current_function_decl) =
@@ -15621,22 +15634,28 @@
}
/* Check that exception said to be thrown by method DECL can be
- effectively caught from where DECL is invoked. */
-
+ effectively caught from where DECL is invoked. THIS_EXPR is the
+ expression that computes `this' for the method call. */
static void
-check_thrown_exceptions (int location, tree decl)
+check_thrown_exceptions (int location, tree decl, tree this_expr)
{
tree throws;
- /* For all the unchecked exceptions thrown by DECL */
+ int is_array_call = 0;
+
+ if (this_expr != NULL_TREE
+ && TREE_CODE (TREE_TYPE (this_expr)) == POINTER_TYPE
+ && TYPE_ARRAY_P (TREE_TYPE (TREE_TYPE (this_expr))))
+ is_array_call = 1;
+
+ /* For all the unchecked exceptions thrown by DECL. */
for (throws = DECL_FUNCTION_THROWS (decl); throws;
throws = TREE_CHAIN (throws))
if (!check_thrown_exceptions_do (TREE_VALUE (throws)))
{
-#if 1
- /* Temporary hack to suppresses errors about cloning arrays. FIXME */
- if (DECL_NAME (decl) == get_identifier ("clone"))
+ /* Suppress errors about cloning arrays. */
+ if (is_array_call && DECL_NAME (decl) == get_identifier ("clone"))
continue;
-#endif
+
EXPR_WFL_LINECOL (wfl_operator) = location;
if (DECL_FINIT_P (current_function_decl))
parse_error_context
Index: libjava/testsuite/ChangeLog
from Tom Tromey <tromey@redhat.com>
For PR java/11600:
* libjava.compile/PR11600.xfail: New file.
* libjava.compile/PR11600.java: New file.
Index: libjava/testsuite/libjava.compile/PR11600.java
===================================================================
RCS file: libjava/testsuite/libjava.compile/PR11600.java
diff -N libjava/testsuite/libjava.compile/PR11600.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libjava/testsuite/libjava.compile/PR11600.java 4 Aug 2003 22:03:13 -0000
@@ -0,0 +1,7 @@
+public class PR11600 implements Cloneable
+{
+ public Object clone ()
+ {
+ return super.clone ();
+ }
+}
Index: libjava/testsuite/libjava.compile/PR11600.xfail
===================================================================
RCS file: libjava/testsuite/libjava.compile/PR11600.xfail
diff -N libjava/testsuite/libjava.compile/PR11600.xfail
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libjava/testsuite/libjava.compile/PR11600.xfail 4 Aug 2003 22:03:13 -0000
@@ -0,0 +1 @@
+shouldfail