http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42652
Richard Guenther <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |53947 Status|UNCONFIRMED |RESOLVED Known to work| |4.4.7, 4.5.4 Resolution| |FIXED Target Milestone|--- |4.5.4 --- Comment #19 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-13 09:01:19 UTC --- Link to vectorizer missed-optimization meta-bug. --- Comment #20 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-19 11:37:30 UTC --- The testcase is invalid. To quote: typedef struct __attribute__ ((__packed__)) Palette { unsigned short pad; unsigned int ents[0]; } Palette; int main () { unsigned char *buf = new unsigned char[sizeof (Palette) + 256 * sizeof (unsigned int) + 16]; Palette *palette = (Palette *) (buf); unsigned int *now = palette->ents; unsigned int *end = now + 256; for (; now < end; now++) *now = 69; } you are dereferencing a pointer of type unsigned int * which is not properly aligned. Fixed at least since 4.5.4 if you properly do typedef struct __attribute__ ((__packed__)) Palette { unsigned short pad; unsigned int ents[0]; } Palette; typedef unsigned int uuint __attribute__((aligned(1))); int main () { unsigned char *buf = new unsigned char[sizeof (Palette) + 256 * sizeof (unsigned int) + 16]; Palette *palette = (Palette *) (buf); uuint *now = palette->ents; uuint *end = now + 256; for (; now < end; now++) *now = 69; } -Wcast-align does not warn about the original unsigned int *now = palette->ents; stmt though.