re PR java/21722 (gcj miscompiles accesses to static final vars with indirect dispatch)
authorTom Tromey <tromey@redhat.com>
Fri, 3 Jun 2005 04:06:19 +0000 (04:06 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Fri, 3 Jun 2005 04:06:19 +0000 (04:06 +0000)
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
dispatch.

From-SVN: r100533

gcc/java/ChangeLog
gcc/java/class.c

index 43dec17af1693606862042e1c98accff138834ee..117cea996d4d71474e1e47d4d12b2cc437c06179 100644 (file)
@@ -1,3 +1,10 @@
+2005-06-01  Tom Tromey  <tromey@redhat.com>
+
+       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
+       dispatch.
+
 2005-05-31  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * java/verify-glue.c: Don't include errors.h and include toplev.h.
index 88ca1f4935677bba1c15350361063e627e84c782..68732b74dd56a6c9148a10d24dae9a1f1ef3c046 100644 (file)
@@ -1068,19 +1068,18 @@ build_static_field_ref (tree fdecl)
 {
   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)))
-         && TREE_CONSTANT (DECL_INITIAL (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;