This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Limit array element alignment to less than size.
- From: Steve Ellcey <sje at cup dot hp dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 29 Sep 2005 10:43:13 -0700 (PDT)
- Subject: PATCH: Limit array element alignment to less than size.
- Reply-to: sje at cup dot hp dot com
This patch causes GCC to generate an error when a user tries to create
an array whose elements have an alignment requirement greater than the
element size. When we have this situation GCC cannot implement the
alignment as requested so we should give an error. Currently, on IA64,
GCC may generate bad code in this situation. This patch is dependent on
the patch "http://gcc.gnu.org/ml/gcc-patches/2005-09/msg01837.html"
which is needed to stop gcc.dg/compat/struct-layout-1_generate.c from
generating tests that have arrays with elements whose alignment is
greater than their size.
With the dependent patch in place, this patch had no regressions on IA64
HP-UX and Linux.
OK to checkin on the mainline (after the testsuite patch is checked in)?
Steve Ellcey
sje@cup.hp.com
2005-09-29 Steve Ellcey <sje@cup.hp.com>
* stor-layout.c (layout_type): Do not allow alignment of array
elements to be greater than their size.
*** gcc.orig/gcc/stor-layout.c Thu Sep 29 10:27:09 2005
--- gcc/gcc/stor-layout.c Thu Sep 29 10:27:52 2005
*************** layout_type (tree type)
*** 1817,1822 ****
--- 1817,1828 ----
TYPE_MODE (type) = BLKmode;
}
}
+ if (TYPE_SIZE_UNIT (element)
+ && host_integerp (TYPE_SIZE_UNIT (element), 1)
+ && tree_low_cst (TYPE_SIZE_UNIT (element), 1) > 0
+ && (HOST_WIDE_INT) TYPE_ALIGN_UNIT (element)
+ > tree_low_cst (TYPE_SIZE_UNIT (element), 1))
+ error ("alignment of array elements is greater than element size");
break;
}