The following test case __attribute__ ((vector_size (16))) unsigned int foo[128/16] __attribute__((aligned (128)));
[ and analagously vector unsigned int foo[128/16] __attribute__((aligned (128))); on ppc (where "vector" is defined to __attribute__((altivec(vector__))) or spu (where "vector" is defined to __attribute__((spu_vector))) ] compiles to .comm foo,128,16 Note that the user-specified alignment is ignored, and the default alignment of 16 for this vector type is used instead. The reason appears to be a problem in decl_attributes (attribs.c). For this declaration, first the "aligned" attribute is processed, and sets DECL_ALIGN to 128 bytes, as well as the DECL_USER_ALIGN flag. However, subsequently the "vector_size" attribute is processed, and this this is marked as "type_required", the following piece of code in decl_attributes: /* Layout the decl in case anything changed. */ if (spec->type_required && DECL_P (*node) && (TREE_CODE (*node) == VAR_DECL || TREE_CODE (*node) == PARM_DECL || TREE_CODE (*node) == RESULT_DECL)) relayout_decl (*node); thinks it needs to recompute the decl properties. In particular, void relayout_decl (tree decl) { DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0; DECL_MODE (decl) = VOIDmode; DECL_ALIGN (decl) = 0; SET_DECL_RTL (decl, 0); layout_decl (decl, 0); } relayout_decl resets DECL_ALIGN without consideration of the DECL_USER_ALIGN flag, and layout_decl then fills back in the default alignment for the vector type. The problem does not occur in 3.4, since decl_attributes there works like this: /* Layout the decl in case anything changed. */ if (spec->type_required && DECL_P (*node) && (TREE_CODE (*node) == VAR_DECL || TREE_CODE (*node) == PARM_DECL || TREE_CODE (*node) == RESULT_DECL)) { /* Force a recalculation of mode and size. */ DECL_MODE (*node) = VOIDmode; DECL_SIZE (*node) = 0; if (!DECL_USER_ALIGN (*node)) DECL_ALIGN (*node) = 0; layout_decl (*node, 0); } and specifically keeps user-requested alignments. Now, I'm not quite sure what the correct fix for 4.0 and mainline is. Should be not call relayout_decl (as in 3.4)? Or should we add the DECL_USER_ALIGN check to relayout_decl (what about other callers of this function)? Richard, it appears you added both the DECL_USER_ALIGN check in 3.4, and the relayout_decl call in 4.0, see PR 18282. Any opinion? -- Summary: attribute ((aligned)) ignored on vector variables Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: uweigand at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28862