[llvm-commits] RFC: initial union syntax support

me22 me22.ca at gmail.com
Thu May 14 08:47:34 PDT 2009


On Thu, May 14, 2009 at 07:58, Andrew Lenharth <andrewl at lenharth.org> wrote:
>
> I agree.  Reordering the elements on creation would make this a pain
> to deal with.  Since it is a struct, GEPs are sane (constant index) so
> it would be a simple matter for a pass to prune redundant fields and
> rewrite GEPs.  But that should happen after the front end is done.
> The alternative is the create a whole bunch of new machinery so you
> can ask for the index of the field holding type T.
>
> The whole point of this exercise is to remove bitcasts.  In fact,
> though I am not suggesting it, you could do away with bitcasts
> completely given unions.
>

What's the semantic difference that using a GEP into a union will give
you over a bitcast?

Would it not be better to simply def a bitcast between a type and a
union with a corresponding type as safe(r)?  That way re-ordering and
uniquing wouldn't change the code.

My understanding is that this is perfectly acceptable in C:

    struct a { int i; };
    struct b { int i; int j; };
    struct a *foo(struct b *p){ return (struct a*)p; }

And in a sense, bitcasting from union to union member is the same kind
of bitcasting-to-a-prefix.

Just musing,
~ Scott




More information about the llvm-commits mailing list