From 1b9ee7233caa4e6ff8f964318f0762bf2df6639b Mon Sep 17 00:00:00 2001 From: Per Bothner Date: Thu, 30 Aug 2001 14:08:32 -0700 Subject: [PATCH] jcf-write.c (generate_classfile): Don't write ConstantValue attribute if field is not final... * jcf-write.c (generate_classfile): Don't write ConstantValue attribute if field is not final, for compatibility with jdk. * jcf-write.c (generate_classfile): Convert ConstantValue values to correct type. Work-around for front-end bug. * class.c (set_constant_value): Error if constant has wrong type. From-SVN: r45298 --- gcc/java/ChangeLog | 9 +++++++++ gcc/java/class.c | 6 ++++++ gcc/java/jcf-write.c | 5 ++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index ea4f35b884b..a7e57184ca8 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,12 @@ +2001-08-30 Per Bothner + + * jcf-write.c (generate_classfile): Don't write ConstantValue + attribute if field is not final, for compatibility with jdk. + + * jcf-write.c (generate_classfile): Convert ConstantValue values + to correct type. Work-around for front-end bug. + * class.c (set_constant_value): Error if constant has wrong type. + 2001-08-30 Per Bothner * jcf-dump.c (print_constant): Fix fencepost error so "Float" and diff --git a/gcc/java/class.c b/gcc/java/class.c index e0caeae71d7..eb4be8e96d3 100644 --- a/gcc/java/class.c +++ b/gcc/java/class.c @@ -777,6 +777,12 @@ set_constant_value (field, constant) else { DECL_INITIAL (field) = constant; + if (TREE_TYPE (constant) != TREE_TYPE (field) + && ! (TREE_TYPE (constant) == int_type_node + && INTEGRAL_TYPE_P (TREE_TYPE (field)) + && TYPE_PRECISION (TREE_TYPE (field)) <= 32)) + error ("ConstantValue attribute of field '%s' has wrong type", + IDENTIFIER_POINTER (DECL_NAME (field))); if (FIELD_FINAL (field)) DECL_FIELD_FINAL_IUD (field) = 1; } diff --git a/gcc/java/jcf-write.c b/gcc/java/jcf-write.c index 31493fd0aae..d090b5678ae 100644 --- a/gcc/java/jcf-write.c +++ b/gcc/java/jcf-write.c @@ -2884,7 +2884,8 @@ generate_classfile (clas, state) build_java_signature (TREE_TYPE (part))); PUT2(i); have_value = DECL_INITIAL (part) != NULL_TREE - && FIELD_STATIC (part) && CONSTANT_VALUE_P (DECL_INITIAL (part)); + && FIELD_STATIC (part) && CONSTANT_VALUE_P (DECL_INITIAL (part)) + && FIELD_FINAL (part); if (have_value) attr_count++; @@ -2896,6 +2897,8 @@ generate_classfile (clas, state) { tree init = DECL_INITIAL (part); static tree ConstantValue_node = NULL_TREE; + // This conversion is a work-around for front-end bug. + init = convert (TREE_TYPE (part), init); ptr = append_chunk (NULL, 8, state); if (ConstantValue_node == NULL_TREE) ConstantValue_node = get_identifier ("ConstantValue"); -- 2.30.2