This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[BC] Patch: RFC: indirect dispatch on our own fields

I'm posting this for commentary.

While building Eclipse 3 with the BC compiler I ran into an undefined
reference when loading a .so.  This "shouldn't happen", and I traced
the bug down to a odd scenario.

Suppose you have this:

  class base { public static final Object CONSTANT = ""; }
  class derived extends base {
    public Object method() { return CONSTANT; }

In this situation, the Eclipse java compiler will generate
"getstatic derived.CONSTANT".  This may seem strange, but it is
perfectly valid (and in fact arguably more correct than what gcj
does right now -- though in this situation the difference is merely

When compiling derived.class, gcj tries to emit a direct reference to
the field `CONSTANT'.  This is wrong, as this field is inherited, not
declared in our class.  Instead we must refer to it via our atable.

This patch fixes the problem by adding another condition to the
already ugly conditional in build_static_field_ref().  I'm not
completely sure about it, but I looked at all the uses of
DECL_ARTIFICIAL in gcj and I think this is safe.


Index: ChangeLog
from  Tom Tromey  <>

	* class.c (build_static_field_ref): Don't emit direct references
	to artificial fields.

Index: class.c
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision
diff -u -r1.180.2.14 class.c
--- class.c 12 Oct 2004 12:42:41 -0000
+++ class.c 4 Nov 2004 19:14:26 -0000
@@ -1055,7 +1055,8 @@
      returning the field itself, leading to an incorrect external
      reference being generated.  */
   if ((is_compiled 
-       && (! flag_indirect_dispatch || current_class == fclass))
+       && (! flag_indirect_dispatch
+	   || (current_class == fclass && ! DECL_ARTIFICIAL (fdecl))))
       || (FIELD_FINAL (fdecl) && DECL_INITIAL (fdecl) != NULL_TREE
 	  && (JSTRING_TYPE_P (TREE_TYPE (fdecl))
 	      || JNUMERIC_TYPE_P (TREE_TYPE (fdecl)))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]