From fd0447cd965c0a7519ef243ad208a4213eb28d23 Mon Sep 17 00:00:00 2001 From: tromey Date: Fri, 24 Jan 2003 17:44:03 +0000 Subject: [PATCH] * class.c (build_static_field_ref): Only a String or numeric field can fold to a constant. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@61723 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/java/ChangeLog | 5 +++++ gcc/java/class.c | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 0d084b4..5c2199e 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,8 @@ +2003-01-24 Tom Tromey + + * class.c (build_static_field_ref): Only a String or numeric field + can fold to a constant. + 2003-01-23 Tom Tromey * jcf-parse.c (parse_zip_file_entries): Overwrite trailing \0 of diff --git a/gcc/java/class.c b/gcc/java/class.c index d0953cc..dfaf6f1 100644 --- a/gcc/java/class.c +++ b/gcc/java/class.c @@ -922,8 +922,18 @@ build_static_field_ref (tree fdecl) tree fclass = DECL_CONTEXT (fdecl); int is_compiled = is_compiled_class (fclass); - /* Allow static final fields to fold to a constant. */ - if (is_compiled || FIELD_FINAL (fdecl)) + /* 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 + || (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 (!DECL_RTL_SET_P (fdecl)) { -- 2.7.4