[llvm-commits] RFC: initial union syntax support

Andrew Lenharth andrewl at lenharth.org
Thu May 14 14:23:43 PDT 2009


On Thu, May 14, 2009 at 3:44 PM, Chris Lattner <clattner at apple.com> wrote:
>
> On May 14, 2009, at 1:04 PM, Frits van Bommel wrote:
>
>> Nick Lewycky wrote:
>>> Andrew Lenharth wrote:
>>>> 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.
>>
>> I disagree with this. Proper union support will allow more than just
>> doing away
>> with bitcasts in a few places. A union type would have both the
>> maximum size and
>> maximum alignment of any member, so that e.g. explicit padding to
>> get a union in
>> a struct at the right alignment won't be necessary.
>
> I think that unions are a potentially interesting feature, but they
> definately don't eliminate the need for pointer bitcasts.
>
> Some random things:
>
> 1. Union types should be uniqued, but the type as written in the code
> should be used for uniquing.  u{i32, i32} should be distinct from
> u{i32}.

I agree.

> 2. GEP into the union should be allowed.

This is the current patch also.

> 3. We need a ConstantStruct equivalent.

Yes, and more generally I don't know an initialization syntax for
global unions yet.

> 4. Unions should work as first class aggregates, just like structs.

This was the assumption under which you could (but I am not
advocating) using them for bitcasts.

Andrew




More information about the llvm-commits mailing list