http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45704
--- Comment #6 from rguenther at suse dot de <rguenther at suse dot de> 2010-09-27 15:54:06 UTC --- On Mon, 27 Sep 2010, anemo at mba dot ocn.ne.jp wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45704 > > --- Comment #5 from Atsushi Nemoto <anemo at mba dot ocn.ne.jp> 2010-09-27 > 15:48:32 UTC --- > Here is a similar test case with "packed" attribute, which still produces bad > result. > Four load-byte instructions are generated instead of one load-word. > > struct st { > int ptr; > } __attribute__ ((packed)); > > int foo(struct st *st) > { > int v = *(volatile int *)&st->ptr; > return v & 0xff; > } > > gcc 4.4.4 works fine (same result with the first test case) > > gcc 4.6.0 20100927 (or 4.5.2 20100927) generates: > lbu $2,0($4) > lbu $3,1($4) > andi $2,$2,0x00ff > lbu $3,2($4) > lbu $3,3($4) > j $31 > nop > > I do not know this should be another PR or not. It should be as this is likely a problem with unaligned access support. I think you can't generally expect unaligned volatile accesses to work (on ia64 for example they certainly wouldn't).