[cfe-dev] portable sizeof
Chris Lattner
clattner at apple.com
Fri Oct 30 11:10:59 PDT 2009
On Oct 30, 2009, at 10:47 AM, Jochen Wilhelmy wrote:
> Hi!
>
> while playing with clang I found that sizeof() is evaluated in the
> frontend,
> e.g. generating llvm-code like
>
> store i32 16, i32* %tmp1
>
> (the size of the struct Foo is 16 byte).
>
> would it be better to generate code like this?
>
> store i32 ptrtoint (struct.Foo* getelementptr inbounds (%struct.Foo*
> null, i32 1) to i32), i32* %tmp1
>
> this way c-code containing a sizeof could be compiled to llvm bytecode
> while the target platfrom is still mostly unknown (at least size_t has
> to be known
> and influences whether i16, i32 or i64 is used)
I don't think we should do that. The reason is that this makes the
bytecode slightly more portable (at the expense of producing worse
code) but it doesn't solve the issue (sizeof is an integer constant
expression so it has to be folded to a constant in various places,
e.g. a 'case' value) and the C -> LLVM IR conversion is not portable
anyway. Once you've gotten to an LLVM IR type, it is already non-
portable.
-Chris
More information about the cfe-dev
mailing list