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]

Patch: RFA: fix PR java/21722

This patch fixes PR java/21722.

First, the bug only applies with -findirect-dispatch.  The bug is that
if we see a constant when compiling a class, and the constant comes
from another class we are also compiling in the same invocation, then
we end up generating a "real" field reference, and not a reference via
the atable.  This is wrong as all references must go via the atable.

This fix simply disables this approach when compiling from class files
and using indirect dispatch.

I didn't change the case,
because in that case (when it works) we will still be required to
inline constant fields.  (The language restrictions about inlining
constants don't apply in the .class file case, and one could argue
that inlining here would actually be wrong... as if inlining was
meant, the class file would have simply contained a constant pool

BTW I don't understand why the "constant" case here returns the field
and not its DECL_INITIAL.

I tested this against our test suite on x86 FC2.  I also rebuilt
Eclipse and ran a smoke test without problems.  Ok?


Index: ChangeLog
from  Tom Tromey  <>

	PR java/21722:
	* class.c (build_static_field_ref): Don't fold constant fields if
	current class is from a .class file and we're using indirect

Index: class.c
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.230
diff -u -r1.230 class.c
--- class.c 25 May 2005 22:08:27 -0000 1.230
+++ class.c 2 Jun 2005 14:52:06 -0000
@@ -1068,19 +1068,18 @@
   tree fclass = DECL_CONTEXT (fdecl);
   int is_compiled = is_compiled_class (fclass);
+  int from_class = ! CLASS_FROM_SOURCE_P (current_class);
   /* Allow static final fields to fold to a constant.  When using
-     -fno-assume-compiled, gcj will sometimes try to fold a field from
-     an uncompiled class.  This is required when the field in question
-     meets the appropriate criteria for a compile-time constant.
-     However, currently sometimes gcj is too eager and will end up
-     returning the field itself, leading to an incorrect external
-     reference being generated.  */
-  if ((is_compiled && !flag_indirect_dispatch)
-      || (FIELD_FINAL (fdecl) && DECL_INITIAL (fdecl) != NULL_TREE
-	  && (JSTRING_TYPE_P (TREE_TYPE (fdecl))
-	      || JNUMERIC_TYPE_P (TREE_TYPE (fdecl)))
+     -findirect-dispatch, we simply never do this folding if compiling
+     from .class; in the .class file constants will be referred to via
+     the constant pool.  */
+  if ((!flag_indirect_dispatch || !from_class)
+      && (is_compiled
+	  || (FIELD_FINAL (fdecl) && DECL_INITIAL (fdecl) != NULL_TREE
+	      && (JSTRING_TYPE_P (TREE_TYPE (fdecl))
+		  || JNUMERIC_TYPE_P (TREE_TYPE (fdecl)))
+	      && TREE_CONSTANT (DECL_INITIAL (fdecl)))))
       if (is_compiled == 1)
 	DECL_EXTERNAL (fdecl) = 1;

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