From 65f69237d7a0a3883ab120593c372fed53613b35 Mon Sep 17 00:00:00 2001 From: Andrew Haley Date: Tue, 29 Aug 2000 22:15:21 +0000 Subject: [PATCH] typeck.c (build_java_array_type): Rewrite code to do array alignment. 2000-08-16 Andrew Haley * typeck.c (build_java_array_type): Rewrite code to do array alignment. Take into account back-end macros when aligning array data. Remove setting of TYPE_USER_ALIGN; Java doesn't allow the user to set alignment. Fixes gcj/252 and 160. (This fixes gcj/252 and 160: http://sources.redhat.com/ml/java-prs/2000-q2/msg00254.html http://gcc.gnu.org/ml/gcc-patches/2000-08/msg00907.html) From-SVN: r36057 --- gcc/java/ChangeLog | 7 +++++++ gcc/java/typeck.c | 25 +++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 4dfa874e472..754112a606b 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -35,6 +35,13 @@ * lang-specs.h: Do not process -o or run the assembler if -fsyntax-only. +2000-08-16 Andrew Haley + + * typeck.c (build_java_array_type): Rewrite code to do array + alignment. Take into account back-end macros when aligning array + data. Remove setting of TYPE_USER_ALIGN; Java doesn't allow the + user to set alignment. Fixes gcj/252 and 160. + 2000-08-09 Tom Tromey * parse.y (check_abstract_method_definitions): Now return `int'. diff --git a/gcc/java/typeck.c b/gcc/java/typeck.c index 1a7256d6482..990ff066db7 100644 --- a/gcc/java/typeck.c +++ b/gcc/java/typeck.c @@ -417,13 +417,34 @@ build_java_array_type (element_type, length) { tree atype = build_prim_array_type (element_type, length); tree arfld = build_decl (FIELD_DECL, get_identifier ("data"), atype); + DECL_CONTEXT (arfld) = t; TREE_CHAIN (fld) = arfld; + + /* We need to force the data field to begin at an alignment at + least equal to the biggest alignment in an object type node + in order to be compatible with the way that JArray is defined + in CNI. However, we can't exceed BIGGEST_FIELD_ALIGNMENT. */ + { + unsigned desired_align = TYPE_ALIGN (object_type_node); + desired_align = MAX (desired_align, TYPE_ALIGN (element_type)); +#ifdef BIGGEST_FIELD_ALIGNMENT + desired_align = MIN (desired_align, + (unsigned) BIGGEST_FIELD_ALIGNMENT); +#endif +#ifdef ADJUST_FIELD_ALIGN + desired_align = ADJUST_FIELD_ALIGN (field, desired_align); +#endif + DECL_ALIGN (arfld) = desired_align; + } } else { - TYPE_ALIGN (t) = TYPE_ALIGN (element_type); - TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (element_type); + unsigned desired_align = TYPE_ALIGN (element_type); +#ifdef BIGGEST_FIELD_ALIGNMENT + desired_align = MIN (desired_align, (unsigned) BIGGEST_FIELD_ALIGNMENT); +#endif + TYPE_ALIGN (t) = desired_align; } pop_obstacks ();