This bug was noticed on sh but potentially impacts other STRICT_ALIGNMENT targets.
The attached test case reduces a misaligned field access from an array of packed structs. In this example compiled with -O2 the field wMaxPacketSize is accessed (on sh4) with a mov.w instruction although it is byte aligned. It seems that the tree-ssa-loop ivopts did not check packed struct offsets indexed by an induction variable. Thus if the struct size is not aligned, the field becomes unaligned after the first iteration even if it was aligned from the base of this structure. The proposed patch solves this problem by expanding may_be_unaligned_p to check that a loop carried offset is a multiple of the desired alignment. -- Summary: Misaligned Accesses on arrays of packed stucts Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: chrbr at gcc dot gnu dot org GCC target triplet: sh4-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35178