[LLVMdev] Suggestion: Support union types in IR
Chris Lattner
clattner at apple.com
Fri Jan 2 12:05:18 PST 2009
On Jan 1, 2009, at 6:25 AM, Jon Harrop wrote:
>> Exactly. I'm not especially interested in C-style unions, I'm
>> interested
>> in discriminated unions. But the actual discriminator field is easily
>> represented in LLVM IR already, so there's no need to extend the IR
>> to
>> support them. That's why I am only asking for C-style union support -
>> it's a lower-level primitive that you can use to build discriminated
>> unions on top of.
>
> I don't think you would want to build discriminated unions on top of
> C-style
> unions though.
Why?
>> The problem with varying-size structs is that it would be nice to be
>> able to pass them as function parameters and function return values
>> using LLVM's support of structs as first-class data types.
>
> As I understand it, LLVM does not provide first-class structs and
> attempting
> to return arbitrary structs from functions will randomly break. I
> believe you
> need to implement that yourself in whatever way your target language
> requires.
This is a current implementation deficiency, not a design limitation.
We welcome patches to fix this.
-Chris
More information about the llvm-dev
mailing list