[llvm-commits] RFC: initial union syntax support

Duncan Sands baldrick at free.fr
Thu May 14 12:01:25 PDT 2009


Hi Nick,

> Then it would seem I misunderstood the purpose of unions. I thought the 
> problem was that it was impossible to declare a type which would be "as 
> large as the largest of any of these" without having accurate 
> TargetData. The union type was supposed to do that and nothing more.

I sent an example earlier showing that you can do this already without
union types.  As Frits pointed out, the problem is alignment.  It is
easy enough to get the alignment in a target independent way, for example
it seems to me that the following gives you the alignment of the type %T
(assuming that the alignment of i8 is 1):

%trick = type { i8, %T }

...

        %tmp = getelementptr %trick* null, i32 0, i32 1
        %align = ptrtoint %T* %tmp to i32

However, because the alloca command requires a constant integer for
the alignment parameter, this doesn't help much.

Ciao,

Duncan.



More information about the llvm-commits mailing list