> 2011-10-17 Richard Guenther <rguent...@suse.de> > > PR middle-end/50716 > * expr.c (get_object_or_type_alignment): New function. > (expand_assignment): Use it. > (expand_expr_real_1): Likewise.
Maybe move it to builtins.c alongside the other get_*_alignment functions. > Index: gcc/expr.c > =================================================================== > *** gcc/expr.c (revision 180077) > --- gcc/expr.c (working copy) > *************** get_bit_range (unsigned HOST_WIDE_INT *b > *** 4544,4549 **** > --- 4544,4568 ---- > } > } > > + /* Return the alignment of the object EXP, also considering its type > + when we do not know of explicit misalignment. > + ??? Note that generally the type of an expression is not kept > + consistent with misalignment information by the frontend, for > + example when taking the address of a member of a packed structure. > + So taking into account type information for alignment is generally > + wrong, but is done here as a compromise. */ This sounds backwards, as taking into account type information is generally correct, i.e. the packed case is the exception. Maybe use "in the general case" instead: ??? Note that, in the general case, the type of an expression is not kept consistent with the misalignment by the front-end, for example when taking the address of a member of a packed structure. However, in most of the cases, expressions have the alignment of their type, so we fall back to the alignment of the type when we cannot compute a misalignment. + static unsigned int + get_object_or_type_alignment (tree exp) + { + unsigned HOST_WIDE_INT misalign; + unsigned int align = get_object_alignment_1 (exp, &misalign); + align = MAX (TYPE_ALIGN (TREE_TYPE (exp)), align); + if (misalign != 0) + align = (misalign & -misalign); You don't need to go through the MAX if misalign is non-zero. -- Eric Botcazou