PATCH: IA64 HP-UX Alignment problem in Fortran

Steve Ellcey
Mon Apr 17 18:18:00 GMT 2006

This patch is related to PR libfortran/26890.  The fix for that patch
modified the st_parameter_dt structure in io/io.h and uncovered a latent
bug in the allocation and alignment of the union that is a field of that
structure.  The structure is allocated by the Fortran front-end and in
the front-end the union field is allocated as an array of characters,
this results in a different (lesser) alignment than if it were declared
with its real type.  Since IA64 HP-UX requires 8 byte integers to be
aligned on an 8 byte boundry and the allocation of an array of
characters does not gaurantee that, I get errors about unaligned data on
that platform.

Since the patch to PR libfortran/26890 was checked in on both the main
line and on the 4.1 branch I would like to check this patch in on both
branches as well.

Tested on IA64 HP-UX and Linux and on HPPA HP-UX with no regressions.

Steve Ellcey

2006-04-17  Steve Ellcey  <>

	* trans-io.c(gfc_build_io_library_fndecls): Align pad.

Index: trans-io.c
--- trans-io.c	(revision 112997)
+++ trans-io.c	(working copy)
@@ -227,6 +227,14 @@ gfc_build_io_library_fndecls (void)
   pad_size += 32 * TREE_INT_CST_LOW (TYPE_SIZE_UNIT (integer_type_node));
   pad_idx = build_index_type (build_int_cst (NULL_TREE, pad_size));
   types[IOPARM_type_pad] = build_array_type (char_type_node, pad_idx);
+  /* pad actually contains pointers and integers so it needs to have an
+     alignment that is at least as large as the needed alignment for those
+     types.  See the st_parameter_dt structure in libgfortran/io/io.h for
+     what really goes into this space.  */
+  TYPE_ALIGN (types[IOPARM_type_pad]) = MAX (TYPE_ALIGN (pchar_type_node),
+		     TYPE_ALIGN (gfc_get_int_type (gfc_max_integer_kind)));
   gfc_c_int_type_node = gfc_get_int_type (gfc_c_int_kind);
   for (ptype = IOPARM_ptype_common; ptype < IOPARM_ptype_num; ptype++)

More information about the Gcc-patches mailing list