From 4267db98773b84dd48f9bcc3b5b03dba6cbb9494 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 3 Jun 2005 04:06:19 +0000 Subject: [PATCH] re PR java/21722 (gcj miscompiles accesses to static final vars with indirect dispatch) 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 | 7 +++++++ gcc/java/class.c | 21 ++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 43dec17af16..117cea996d4 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,10 @@ +2005-06-01 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 + dispatch. + 2005-05-31 Kaveh R. Ghazi * java/verify-glue.c: Don't include errors.h and include toplev.h. diff --git a/gcc/java/class.c b/gcc/java/class.c index 88ca1f49356..68732b74dd5 100644 --- a/gcc/java/class.c +++ b/gcc/java/class.c @@ -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; -- 2.30.2