Patch: RFA: fix PR java/17500

Tom Tromey tromey@redhat.com
Fri Sep 24 21:50:00 GMT 2004


This patch fixes PR java/17500.

create_artificial_method() was creating a function type, computing its
signature, and then using that to call add_method().  This involved
mapping the signature back to a function type via a cache -- but later
create_artificial_method's caller would modify the function type in
place, messing up the value stored in the cache.

I couldn't see a reason to go through these hoops when we could use
add_method_1 with the function type we just created.  Patch appended.

Tested on x86 FC2, including jacks and mauve.  No regressions.  Test
case included.

Ok?

Tom

Index: gcc/java/ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	PR java/17500:
	* parse.y (create_artificial_method): Use add_method_1.

Index: gcc/java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.510
diff -u -r1.510 parse.y
--- gcc/java/parse.y 24 Sep 2004 15:44:35 -0000 1.510
+++ gcc/java/parse.y 24 Sep 2004 19:54:42 -0000
@@ -7468,7 +7468,11 @@
   mdecl = make_node (FUNCTION_TYPE);
   TREE_TYPE (mdecl) = type;
   TYPE_ARG_TYPES (mdecl) = args;
-  mdecl = add_method (class, flags, name, build_java_signature (mdecl));
+  /* We used to compute the signature of MDECL here and then use
+     add_method(), but that failed because our caller might modify
+     the type of the returned method, which trashes the cache in
+     get_type_from_signature().  */
+  mdecl = add_method_1 (class, flags, name, mdecl);
   java_parser_context_restore_global ();
   DECL_ARTIFICIAL (mdecl) = 1;
   return mdecl;
Index: libjava/ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	PR java/17500:
	* testsuite/libjava.compile/pr17500.java: New file.

Index: libjava/testsuite/libjava.compile/pr17500.java
===================================================================
RCS file: libjava/testsuite/libjava.compile/pr17500.java
diff -N libjava/testsuite/libjava.compile/pr17500.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libjava/testsuite/libjava.compile/pr17500.java 24 Sep 2004 20:02:23 -0000
@@ -0,0 +1,28 @@
+// gcj had a problem compiling code where two anonymous classes had
+// captured constructor arguments of the same type but with different
+// names.
+
+public class pr17500
+{
+  public Object m1 (final Object one)
+  {
+    return new Comparable()
+      {
+	public int compareTo(Object other)
+	{
+	  return one == other ? 0 : 1;
+	}
+      };
+  }
+
+  public Object m2 (final Object two)
+  {
+    return new Comparable()
+      {
+	public int compareTo(Object other)
+	{
+	  return two == other ? 0 : 1;
+	}
+      };
+  }
+}



More information about the Gcc-patches mailing list