[LLVMdev] Union types

Tim Northover T.P.Northover at sms.ed.ac.uk
Mon Mar 29 07:15:32 PDT 2010


On Mon, Mar 29, 2010 at 01:15:30PM +0100, Renato Golin wrote:
> Hi All,
> 
> Which implies no one was expecting a UnionType there...
> 
> Also, if I generate the object code directly, llc fails too...
> 
> Is there any plan to implement the union type? The work-around is quite ugly...

Sorry to Renato for getting two copeis of this, I cocked up the reply
first time.

Anyway, here's a patch for this issue (I'd not tried zero initialiser
during my work). It seems to pass all the same tests as llvm did before,
and give reasonable output.

Also, does anyone know off the top of their heads what would be needed
to get unions up to scratch? They do seem to be a neat solution and I'd
be sad to see them removed.

Tim.
-------------- next part --------------
Index: lib/VMCore/Constants.cpp
===================================================================
--- lib/VMCore/Constants.cpp	(revision 99809)
+++ lib/VMCore/Constants.cpp	(working copy)
@@ -59,6 +59,7 @@
   case Type::PointerTyID:
     return ConstantPointerNull::get(cast<PointerType>(Ty));
   case Type::StructTyID:
+  case Type::UnionTyID:
   case Type::ArrayTyID:
   case Type::VectorTyID:
     return ConstantAggregateZero::get(Ty);
@@ -944,7 +945,8 @@
 //                      Factory Function Implementation
 
 ConstantAggregateZero* ConstantAggregateZero::get(const Type* Ty) {
-  assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) &&
+  assert((Ty->isStructTy() || Ty->isUnionTy()
+         || Ty->isArrayTy() || Ty->isVectorTy()) &&
          "Cannot create an aggregate zero of non-aggregate type!");
   
   LLVMContextImpl *pImpl = Ty->getContext().pImpl;


More information about the llvm-dev mailing list