[LLVMdev] Struct layout assumptions

Andrew Lenharth andrewl at lenharth.org
Mon Mar 3 08:33:29 PST 2008

On 3/2/08, Talin <viridia at gmail.com> wrote:
>  However, the problem here is that I don't know if its legal to bitcast
>  from B.vtable to A.vtable. As far as I know, the optimizer might
>  re-order the member fields, or muck with the padding.
>  What sort of invariants can I rely on in this case?

An optimization could only do that if it could prove it was safe, that
is, if it could find all possible uses and fix them up so they still
referred to the same field.

Basically an optimizer would have to prove that all accesses to those
objects were type safe, and that they didn't escape the analysis
scope, and didn't alias with other objects.

Having written a safe struct reorganizer in llvm before, I can tell
you that even if something like that did exist, it is highly unlikely
it would be able to prove its invarients for your code, and if it
could, then it would be safe and you wouldn't notice :)


More information about the llvm-dev mailing list