On Nov 11, 2008, at 5:11 PM, Peter Shugalev wrote:> Owen Anderson wrote: >> What about something much simpler: memcpy'ing an array of structs >> around. The number of bytes to be memcpy'd is dependent on the >> padding >> of the struct. > > Anyway, I've got your point. sizeof() constant expression is > calculated > during wrong stage of compilation process. Thanks for pointing it out!Yes, not to mention stuff like: #ifdef __i386__ or: case sizeof(foo): This is addressed here: http://llvm.org/docs/tutorial/LangImpl8.html#targetindep Note that this doesn't affect cross compilation: you just need to configure llvm-gcc as a proper cross compiler. This just means that llvm won't magically make your C code portable for you. Real portable languages don't suffer from these problems. -Chris
Hi, Chris Lattner wrote:> Yes, not to mention stuff like: > > #ifdef __i386__ > > or: > case sizeof(foo): > > This is addressed here: > http://llvm.org/docs/tutorial/LangImpl8.html#targetindep > > Note that this doesn't affect cross compilation: you just need to > configure llvm-gcc as a proper cross compiler. This just means that > llvm won't magically make your C code portable for you. Real portable > languages don't suffer from these problems.I'm not looking for magic, I'm just disappointed that sometimes LLVM turns portable C/C++ code into non-portable one. The workaround is not easy. #define SIZE_OF(T) ((char *)((T*)0 + 1) - (char *)0)) works but it is not constant expression anymore. "Lazy" calculation of sizeof expression would be great though I have to admit it would introduce many complexities to the bytecode including storing and calculation of arbitrary complex constant expressions. Bytecode-level uintptr_t/intptr_t data types are needed too. -- Best Regards Peter Shugalev
On Nov 11, 2008, at 6:24 PM, Peter Shugalev wrote:> I'm not looking for magic, I'm just disappointed that sometimes LLVM > turns portable C/C++ code into non-portable one.Sorry, but the GCC front-end folds a ton of stuff ever before the llvm parts start working. -Chris