http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50565

--- Comment #3 from Mikael Pettersson <mikpe at it dot uu.se> 2011-10-02 
10:43:54 UTC ---
Created attachment 25393
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25393
reduced test case

> cat pr50565.c
/* pr50565.c */
struct netmessage {
    unsigned char pos[2];
};
static struct netmessage nmsgbuf;
const int offset0 = (int)((void*)&nmsgbuf.pos[0] - (void*)&nmsgbuf) + 0*(1U);
const int offset1 = (int)((void*)&nmsgbuf.pos[0] - (void*)&nmsgbuf) + 1*(1U);
> objdir/gcc/xgcc -Bobjdir/gcc/ -O2 -S pr50565.c
pr50565.c:7: error: initializer element is not computable at load time

That's the offset1 initializer it's complaining about.  Note that the offset0
initializer is accepted.  If we comment out the offset1 definition we get:

> perl -pi -e 's,^const int offset1,//const int offset1,g' pr50565.c
> objdir/gcc/xgcc -Bobjdir/gcc/ -O2 -S pr50565.c
> cat pr50565.s
        .file   "pr50565.c"
.globl offset0
        .section        .rodata
        .align 4
        .type   offset0, @object
        .size   offset0, 4
offset0:
        .long   0
        .local  nmsgbuf
        .comm   nmsgbuf,2,1
        .ident  "GCC: (GNU) 4.5.0 20090329 (experimental)"
        .section        .note.GNU-stack,"",@progbits

The common offsetof emulation is clearly computable at compile-time, so one
would expect the same + 1 to also be computable at compile-time, but gcc
doesn't seem to think so.

Reply via email to