On Nov 20, 2007 12:43 PM, Vegard Nossum <vegard.nossum@xxxxxxxxx> wrote: > On Nov 20, 2007 12:16 PM, Vegard Nossum <vegard.nossum@xxxxxxxxx> wrote: > > Here, offsetof(struct socket, type) = 0x24, like the one used in the > > reads/writes. The type here is short, on 386 that's 16 bits. So why is > > gcc later reading 32 bits off the same address, is that really legal? > > Shouldn't that really have been a MOVZWL? Or did I miss something > > obvious? > > I will add that compiling the file in question without optimisations > (it was -Os), it does indeed produce a MOVZWL instruction instead. I > am trying to construct a minimal test-case now. Help is still > appreciated. For the curious, here is the minimal example program: struct a { int dummy; short x; }; struct b { unsigned short x; }; extern void dummy(struct b *b); void sock_init_data(struct a *a, struct b *b) { dummy(b); if (a) { asm("/* THIS FIELD IS ONLY 16 BITS */"); b->x = a->x; } } As you see, with -Os, this produces: /* THIS FIELD IS ONLY 16 BITS */ movl 4(%ebx), %eax movw %ax, (%esi) While the no-optimizations code looks like this: movl 8(%ebp), %eax movzwl 4(%eax), %eax movl %eax, %edx movl 12(%ebp), %eax movw %dx, (%eax) The first one is clearly loading a 32-bit value from an address that may not have more than 16 bits written to it. So, is it legal for the compiler to do that? Vegard -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ